Compare commits
	
		
			31 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | a1c666d855 | ||
|   | d5b70f51d8 | ||
|   | 2e941f2def | ||
|   | eef74457f7 | ||
|   | e168301d39 | ||
|   | 29f1eeb9e5 | ||
|   | faca7837b0 | ||
|   | dffa64995b | ||
|   | c0e291b502 | ||
|   | 2323559062 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | e80b8cc6d8 | ||
|   | 31e7cc5f84 | ||
|   | 9db0a23fb3 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 90e26af07a | ||
|   | 01ed3f7910 | ||
|   | 11ae4c31f6 | ||
|   | 983bf3e000 | ||
|   | 9a462131b5 | ||
|   | 1806a02fac | ||
|   | c1f17c078a | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 76bfd425d8 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 5a93241d03 | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 2f13c4010e | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 1dd5af0c3a | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 55dd79473c | ||
|   | b1f1f719c7 | ||
|   | 68810d1ede | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | cd8b844a0a | ||
|   | 894f000c27 | ||
|   | f080c7125b | ||
| ![dependabot[bot]](/assets/img/avatar_default.png)  | 49b8353604 | 
| @@ -1,18 +1,40 @@ | ||||
| import fs = require('fs'); | ||||
| import * as docker from '../src/docker'; | ||||
| import * as buildx from '../src/buildx'; | ||||
| import * as path from 'path'; | ||||
| import * as os from 'os'; | ||||
| import * as semver from 'semver'; | ||||
| import * as exec from '@actions/exec'; | ||||
|  | ||||
| describe('isAvailable', () => { | ||||
|   const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput'); | ||||
|   buildx.isAvailable(); | ||||
|  | ||||
|   expect(execSpy).toHaveBeenCalledWith(`docker`, ['buildx'], { | ||||
|     silent: true, | ||||
|     ignoreReturnCode: true | ||||
|   }); | ||||
| }); | ||||
|  | ||||
| describe('getVersion', () => { | ||||
|   it('valid', async () => { | ||||
|     await exec.exec('docker', ['buildx', 'version']); | ||||
|   async function isDaemonRunning() { | ||||
|     return await exec | ||||
|       .getExecOutput(`docker`, ['version', '--format', '{{.Server.Os}}'], { | ||||
|         ignoreReturnCode: true, | ||||
|         silent: true | ||||
|       }) | ||||
|       .then(res => { | ||||
|         return !res.stdout.trim().includes(' ') && res.exitCode == 0; | ||||
|       }); | ||||
|   } | ||||
|   (isDaemonRunning() ? it : it.skip)( | ||||
|     'valid', | ||||
|     async () => { | ||||
|       const version = await buildx.getVersion(); | ||||
|       console.log(`version: ${version}`); | ||||
|       expect(semver.valid(version)).not.toBeNull(); | ||||
|   }, 100000); | ||||
|     }, | ||||
|     100000 | ||||
|   ); | ||||
| }); | ||||
|  | ||||
| describe('parseVersion', () => { | ||||
| @@ -27,7 +49,14 @@ describe('parseVersion', () => { | ||||
|  | ||||
| describe('inspect', () => { | ||||
|   async function isDaemonRunning() { | ||||
|     return await docker.isDaemonRunning(); | ||||
|     return await exec | ||||
|       .getExecOutput(`docker`, ['version', '--format', '{{.Server.Os}}'], { | ||||
|         ignoreReturnCode: true, | ||||
|         silent: true | ||||
|       }) | ||||
|       .then(res => { | ||||
|         return !res.stdout.trim().includes(' ') && res.exitCode == 0; | ||||
|       }); | ||||
|   } | ||||
|   (isDaemonRunning() ? it : it.skip)( | ||||
|     'valid', | ||||
|   | ||||
							
								
								
									
										11971
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										11971
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										26
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								package.json
									
									
									
									
									
								
							| @@ -27,24 +27,24 @@ | ||||
|   ], | ||||
|   "license": "Apache-2.0", | ||||
|   "dependencies": { | ||||
|     "@actions/core": "^1.2.7", | ||||
|     "@actions/exec": "^1.0.4", | ||||
|     "@actions/core": "^1.4.0", | ||||
|     "@actions/exec": "^1.1.0", | ||||
|     "@actions/http-client": "^1.0.11", | ||||
|     "@actions/tool-cache": "^1.6.1", | ||||
|     "@actions/tool-cache": "^1.7.1", | ||||
|     "semver": "^7.3.5", | ||||
|     "uuid": "^8.3.2" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@types/jest": "^26.0.3", | ||||
|     "@types/node": "^14.0.14", | ||||
|     "@vercel/ncc": "^0.23.0", | ||||
|     "dotenv": "^8.2.0", | ||||
|     "jest": "^26.1.0", | ||||
|     "jest-circus": "^26.1.0", | ||||
|     "jest-runtime": "^26.1.0", | ||||
|     "prettier": "^2.0.5", | ||||
|     "ts-jest": "^26.1.1", | ||||
|     "typescript": "^3.9.5", | ||||
|     "@types/jest": "^26.0.23", | ||||
|     "@types/node": "^14.17.4", | ||||
|     "@vercel/ncc": "^0.28.6", | ||||
|     "dotenv": "^8.6.0", | ||||
|     "jest": "^26.6.3", | ||||
|     "jest-circus": "^26.6.3", | ||||
|     "jest-runtime": "^26.6.3", | ||||
|     "prettier": "^2.3.1", | ||||
|     "ts-jest": "^26.5.6", | ||||
|     "typescript": "^4.3.4", | ||||
|     "typescript-formatter": "^7.2.2" | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -3,9 +3,9 @@ import * as path from 'path'; | ||||
| import * as semver from 'semver'; | ||||
| import * as util from 'util'; | ||||
| import * as context from './context'; | ||||
| import * as exec from './exec'; | ||||
| import * as github from './github'; | ||||
| import * as core from '@actions/core'; | ||||
| import * as exec from '@actions/exec'; | ||||
| import * as tc from '@actions/tool-cache'; | ||||
|  | ||||
| export type Builder = { | ||||
| @@ -18,36 +18,51 @@ export type Builder = { | ||||
|   node_platforms?: string; | ||||
| }; | ||||
|  | ||||
| export async function getVersion(): Promise<string> { | ||||
|   return await exec.exec(`docker`, ['buildx', 'version'], true).then(res => { | ||||
|     if (res.stderr.length > 0 && !res.success) { | ||||
|       throw new Error(res.stderr); | ||||
| export async function isAvailable(): Promise<Boolean> { | ||||
|   return await exec | ||||
|     .getExecOutput('docker', ['buildx'], { | ||||
|       ignoreReturnCode: true, | ||||
|       silent: true | ||||
|     }) | ||||
|     .then(res => { | ||||
|       if (res.stderr.length > 0 && res.exitCode != 0) { | ||||
|         return false; | ||||
|       } | ||||
|     return parseVersion(res.stdout); | ||||
|       return res.exitCode == 0; | ||||
|     }); | ||||
| } | ||||
|  | ||||
| export async function getVersion(): Promise<string> { | ||||
|   return await exec | ||||
|     .getExecOutput('docker', ['buildx', 'version'], { | ||||
|       ignoreReturnCode: true, | ||||
|       silent: true | ||||
|     }) | ||||
|     .then(res => { | ||||
|       if (res.stderr.length > 0 && res.exitCode != 0) { | ||||
|         throw new Error(res.stderr.trim()); | ||||
|       } | ||||
|       return parseVersion(res.stdout.trim()); | ||||
|     }); | ||||
| } | ||||
|  | ||||
| export async function parseVersion(stdout: string): Promise<string> { | ||||
|   const matches = /\sv?([0-9.]+)/.exec(stdout); | ||||
|   if (!matches) { | ||||
|     throw new Error(`Cannot parse Buildx version`); | ||||
|     throw new Error(`Cannot parse buildx version`); | ||||
|   } | ||||
|   return semver.clean(matches[1]); | ||||
| } | ||||
|  | ||||
| export async function isAvailable(): Promise<Boolean> { | ||||
|   return await exec.exec(`docker`, ['buildx'], true).then(res => { | ||||
|     if (res.stderr.length > 0 && !res.success) { | ||||
|       return false; | ||||
|     } | ||||
|     return res.success; | ||||
|   }); | ||||
| } | ||||
|  | ||||
| export async function inspect(name: string): Promise<Builder> { | ||||
|   return await exec.exec(`docker`, ['buildx', 'inspect', name], true).then(res => { | ||||
|     if (res.stderr.length > 0 && !res.success) { | ||||
|       throw new Error(res.stderr); | ||||
|   return await exec | ||||
|     .getExecOutput(`docker`, ['buildx', 'inspect', name], { | ||||
|       ignoreReturnCode: true, | ||||
|       silent: true | ||||
|     }) | ||||
|     .then(res => { | ||||
|       if (res.stderr.length > 0 && res.exitCode != 0) { | ||||
|         throw new Error(res.stderr.trim()); | ||||
|       } | ||||
|       const builder: Builder = {}; | ||||
|       itlines: for (const line of res.stdout.trim().split(`\n`)) { | ||||
| @@ -173,19 +188,29 @@ async function filename(version: string): Promise<string> { | ||||
| } | ||||
|  | ||||
| export async function getBuildKitVersion(containerID: string): Promise<string> { | ||||
|   return exec.exec(`docker`, ['inspect', '--format', '{{.Config.Image}}', containerID], true).then(bkitimage => { | ||||
|     if (bkitimage.success && bkitimage.stdout.length > 0) { | ||||
|       return exec.exec(`docker`, ['run', '--rm', bkitimage.stdout, '--version'], true).then(bkitversion => { | ||||
|         if (bkitversion.success && bkitversion.stdout.length > 0) { | ||||
|           return `${bkitimage.stdout} => ${bkitversion.stdout}`; | ||||
|   return exec | ||||
|     .getExecOutput(`docker`, ['inspect', '--format', '{{.Config.Image}}', containerID], { | ||||
|       ignoreReturnCode: true, | ||||
|       silent: true | ||||
|     }) | ||||
|     .then(bkitimage => { | ||||
|       if (bkitimage.exitCode == 0 && bkitimage.stdout.length > 0) { | ||||
|         return exec | ||||
|           .getExecOutput(`docker`, ['run', '--rm', bkitimage.stdout.trim(), '--version'], { | ||||
|             ignoreReturnCode: true, | ||||
|             silent: true | ||||
|           }) | ||||
|           .then(bkitversion => { | ||||
|             if (bkitversion.exitCode == 0 && bkitversion.stdout.length > 0) { | ||||
|               return `${bkitimage.stdout.trim()} => ${bkitversion.stdout.trim()}`; | ||||
|             } else if (bkitversion.stderr.length > 0) { | ||||
|           core.warning(bkitversion.stderr); | ||||
|               core.warning(bkitversion.stderr.trim()); | ||||
|             } | ||||
|         return bkitversion.stdout; | ||||
|             return bkitversion.stdout.trim(); | ||||
|           }); | ||||
|       } else if (bkitimage.stderr.length > 0) { | ||||
|       core.warning(bkitimage.stderr); | ||||
|         core.warning(bkitimage.stderr.trim()); | ||||
|       } | ||||
|     return bkitimage.stdout; | ||||
|       return bkitimage.stdout.trim(); | ||||
|     }); | ||||
| } | ||||
|   | ||||
| @@ -24,8 +24,8 @@ export async function getInputs(): Promise<Inputs> { | ||||
|     buildkitdFlags: | ||||
|       core.getInput('buildkitd-flags') || | ||||
|       '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host', | ||||
|     install: /true/i.test(core.getInput('install')), | ||||
|     use: /true/i.test(core.getInput('use')), | ||||
|     install: core.getBooleanInput('install'), | ||||
|     use: core.getBooleanInput('use'), | ||||
|     endpoint: core.getInput('endpoint'), | ||||
|     config: core.getInput('config') | ||||
|   }; | ||||
|   | ||||
| @@ -1,7 +0,0 @@ | ||||
| import * as exec from './exec'; | ||||
|  | ||||
| export async function isDaemonRunning(): Promise<boolean> { | ||||
|   return await exec.exec(`docker`, ['version', '--format', '{{.Server.Os}}'], true).then(res => { | ||||
|     return !res.stdout.includes(' ') && res.success; | ||||
|   }); | ||||
| } | ||||
							
								
								
									
										34
									
								
								src/exec.ts
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								src/exec.ts
									
									
									
									
									
								
							| @@ -1,34 +0,0 @@ | ||||
| import * as aexec from '@actions/exec'; | ||||
| import {ExecOptions} from '@actions/exec'; | ||||
|  | ||||
| export interface ExecResult { | ||||
|   success: boolean; | ||||
|   stdout: string; | ||||
|   stderr: string; | ||||
| } | ||||
|  | ||||
| export const exec = async (command: string, args: string[] = [], silent: boolean): Promise<ExecResult> => { | ||||
|   let stdout: string = ''; | ||||
|   let stderr: string = ''; | ||||
|  | ||||
|   const options: ExecOptions = { | ||||
|     silent: silent, | ||||
|     ignoreReturnCode: true | ||||
|   }; | ||||
|   options.listeners = { | ||||
|     stdout: (data: Buffer) => { | ||||
|       stdout += data.toString(); | ||||
|     }, | ||||
|     stderr: (data: Buffer) => { | ||||
|       stderr += data.toString(); | ||||
|     } | ||||
|   }; | ||||
|  | ||||
|   const returnCode: number = await aexec.exec(command, args, options); | ||||
|  | ||||
|   return { | ||||
|     success: returnCode === 0, | ||||
|     stdout: stdout.trim(), | ||||
|     stderr: stderr.trim() | ||||
|   }; | ||||
| }; | ||||
							
								
								
									
										27
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/main.ts
									
									
									
									
									
								
							| @@ -1,12 +1,11 @@ | ||||
| import * as core from '@actions/core'; | ||||
| import * as exec from '@actions/exec'; | ||||
| import * as os from 'os'; | ||||
| import * as path from 'path'; | ||||
| import * as semver from 'semver'; | ||||
| import * as buildx from './buildx'; | ||||
| import * as context from './context'; | ||||
| import * as mexec from './exec'; | ||||
| import * as stateHelper from './state-helper'; | ||||
| import * as core from '@actions/core'; | ||||
| import * as exec from '@actions/exec'; | ||||
|  | ||||
| async function run(): Promise<void> { | ||||
|   try { | ||||
| @@ -25,8 +24,6 @@ async function run(): Promise<void> { | ||||
|     } | ||||
|  | ||||
|     const buildxVersion = await buildx.getVersion(); | ||||
|     core.info(`Using buildx ${buildxVersion}`); | ||||
|  | ||||
|     const builderName: string = inputs.driver == 'docker' ? 'default' : `builder-${require('uuid').v4()}`; | ||||
|     context.setOutput('name', builderName); | ||||
|     stateHelper.setBuilderName(builderName); | ||||
| @@ -96,9 +93,13 @@ async function run(): Promise<void> { | ||||
| async function cleanup(): Promise<void> { | ||||
|   if (stateHelper.IsDebug && stateHelper.containerName.length > 0) { | ||||
|     core.startGroup(`BuildKit container logs`); | ||||
|     await mexec.exec('docker', ['logs', `${stateHelper.containerName}`], false).then(res => { | ||||
|       if (res.stderr.length > 0 && !res.success) { | ||||
|         core.warning(res.stderr); | ||||
|     await exec | ||||
|       .getExecOutput('docker', ['logs', `${stateHelper.containerName}`], { | ||||
|         ignoreReturnCode: true | ||||
|       }) | ||||
|       .then(res => { | ||||
|         if (res.stderr.length > 0 && res.exitCode != 0) { | ||||
|           core.warning(res.stderr.trim()); | ||||
|         } | ||||
|       }); | ||||
|     core.endGroup(); | ||||
| @@ -106,9 +107,13 @@ async function cleanup(): Promise<void> { | ||||
|  | ||||
|   if (stateHelper.builderName.length > 0) { | ||||
|     core.startGroup(`Removing builder`); | ||||
|     await mexec.exec('docker', ['buildx', 'rm', `${stateHelper.builderName}`], false).then(res => { | ||||
|       if (res.stderr.length > 0 && !res.success) { | ||||
|         core.warning(res.stderr); | ||||
|     await exec | ||||
|       .getExecOutput('docker', ['buildx', 'rm', `${stateHelper.builderName}`], { | ||||
|         ignoreReturnCode: true | ||||
|       }) | ||||
|       .then(res => { | ||||
|         if (res.stderr.length > 0 && res.exitCode != 0) { | ||||
|           core.warning(res.stderr.trim()); | ||||
|         } | ||||
|       }); | ||||
|     core.endGroup(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user