Compare commits

...

29 Commits

Author SHA1 Message Date
2e941f2def Merge pull request #95 from crazy-max/dev-deps
Update dev deps
2021-06-23 17:12:30 +02:00
eef74457f7 Update dev deps
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-06-23 17:03:04 +02:00
e168301d39 Merge pull request #94 from crazy-max/exec-output
Use built-in `getExecOutput`
2021-06-23 16:42:15 +02:00
29f1eeb9e5 Use built-in getExecOutput
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-06-23 16:11:57 +02:00
faca7837b0 Merge pull request #93 from crazy-max/bool-input
Use `core.getBooleanInput`
2021-06-23 15:49:45 +02:00
dffa64995b Use core.getBooleanInput
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-06-23 15:43:25 +02:00
c0e291b502 Merge pull request #86 from docker/dependabot/npm_and_yarn/actions/tool-cache-1.7.1
Bump @actions/tool-cache from 1.7.0 to 1.7.1
2021-06-23 15:01:18 +02:00
2323559062 Update generated content
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-06-23 14:59:36 +02:00
e80b8cc6d8 Bump @actions/tool-cache from 1.7.0 to 1.7.1
Bumps [@actions/tool-cache](https://github.com/actions/toolkit/tree/HEAD/packages/tool-cache) from 1.7.0 to 1.7.1.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/tool-cache/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/tool-cache)

---
updated-dependencies:
- dependency-name: "@actions/tool-cache"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-23 12:30:27 +00:00
31e7cc5f84 Merge pull request #85 from docker/dependabot/npm_and_yarn/actions/exec-1.1.0
Bump @actions/exec from 1.0.4 to 1.1.0
2021-06-23 14:28:46 +02:00
9db0a23fb3 Update generated content
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-06-23 14:26:04 +02:00
90e26af07a Bump @actions/exec from 1.0.4 to 1.1.0
Bumps [@actions/exec](https://github.com/actions/toolkit/tree/HEAD/packages/exec) from 1.0.4 to 1.1.0.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/exec/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/@actions/core@1.1.0/packages/exec)

---
updated-dependencies:
- dependency-name: "@actions/exec"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-23 12:17:11 +00:00
01ed3f7910 Merge pull request #87 from docker/dependabot/npm_and_yarn/actions/core-1.4.0
Bump @actions/core from 1.3.0 to 1.4.0
2021-06-23 14:11:09 +02:00
11ae4c31f6 Update generated content
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-06-23 13:56:24 +02:00
983bf3e000 Merge pull request #91 from docker/dependabot/npm_and_yarn/y18n-4.0.3
Bump y18n from 4.0.0 to 4.0.3
2021-06-23 12:10:31 +02:00
9a462131b5 Merge pull request #89 from docker/dependabot/npm_and_yarn/hosted-git-info-2.8.9
Bump hosted-git-info from 2.8.8 to 2.8.9
2021-06-23 12:09:47 +02:00
1806a02fac Merge pull request #90 from docker/dependabot/npm_and_yarn/ws-7.5.0
Bump ws from 7.3.1 to 7.5.0
2021-06-23 12:09:30 +02:00
c1f17c078a Merge pull request #92 from docker/dependabot/npm_and_yarn/lodash-4.17.21
Bump lodash from 4.17.19 to 4.17.21
2021-06-23 12:01:51 +02:00
76bfd425d8 Bump lodash from 4.17.19 to 4.17.21
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.19 to 4.17.21.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.19...4.17.21)

---
updated-dependencies:
- dependency-name: lodash
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-23 09:58:26 +00:00
5a93241d03 Bump y18n from 4.0.0 to 4.0.3
Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.3.
- [Release notes](https://github.com/yargs/y18n/releases)
- [Changelog](https://github.com/yargs/y18n/blob/y18n-v4.0.3/CHANGELOG.md)
- [Commits](https://github.com/yargs/y18n/compare/v4.0.0...y18n-v4.0.3)

---
updated-dependencies:
- dependency-name: y18n
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-23 09:58:22 +00:00
2f13c4010e Bump hosted-git-info from 2.8.8 to 2.8.9
Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.8 to 2.8.9.
- [Release notes](https://github.com/npm/hosted-git-info/releases)
- [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
- [Commits](https://github.com/npm/hosted-git-info/compare/v2.8.8...v2.8.9)

---
updated-dependencies:
- dependency-name: hosted-git-info
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-23 09:58:22 +00:00
1dd5af0c3a Bump ws from 7.3.1 to 7.5.0
Bumps [ws](https://github.com/websockets/ws) from 7.3.1 to 7.5.0.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/7.3.1...7.5.0)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-23 09:58:22 +00:00
55dd79473c Bump @actions/core from 1.3.0 to 1.4.0
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.3.0 to 1.4.0.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

---
updated-dependencies:
- dependency-name: "@actions/core"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-08 04:04:34 +00:00
b1f1f719c7 Merge pull request #82 from docker/dependabot/npm_and_yarn/actions/tool-cache-1.7.0
Bump @actions/tool-cache from 1.6.1 to 1.7.0
2021-05-30 16:43:16 +02:00
68810d1ede Update generated content
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-05-30 16:41:24 +02:00
cd8b844a0a Bump @actions/tool-cache from 1.6.1 to 1.7.0
Bumps [@actions/tool-cache](https://github.com/actions/toolkit/tree/HEAD/packages/tool-cache) from 1.6.1 to 1.7.0.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/tool-cache/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/tool-cache)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-28 04:03:56 +00:00
894f000c27 Merge pull request #80 from docker/dependabot/npm_and_yarn/actions/core-1.3.0
Bump @actions/core from 1.2.7 to 1.3.0
2021-05-25 02:57:25 +02:00
f080c7125b Update generated content
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-05-25 02:52:57 +02:00
49b8353604 Bump @actions/core from 1.2.7 to 1.3.0
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.7 to 1.3.0.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-24 04:10:09 +00:00
9 changed files with 7359 additions and 7256 deletions

View File

@ -1,18 +1,40 @@
import fs = require('fs'); import fs = require('fs');
import * as docker from '../src/docker';
import * as buildx from '../src/buildx'; import * as buildx from '../src/buildx';
import * as path from 'path'; import * as path from 'path';
import * as os from 'os'; import * as os from 'os';
import * as semver from 'semver'; import * as semver from 'semver';
import * as exec from '@actions/exec'; 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', () => { describe('getVersion', () => {
it('valid', async () => { async function isDaemonRunning() {
await exec.exec('docker', ['buildx', 'version']); return await exec
const version = await buildx.getVersion(); .getExecOutput(`docker`, ['version', '--format', '{{.Server.Os}}'], {
console.log(`version: ${version}`); ignoreReturnCode: true,
expect(semver.valid(version)).not.toBeNull(); silent: true
}, 100000); })
.then(res => {
return !res.stdout.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
);
}); });
describe('parseVersion', () => { describe('parseVersion', () => {
@ -27,7 +49,14 @@ describe('parseVersion', () => {
describe('inspect', () => { describe('inspect', () => {
async function isDaemonRunning() { 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.includes(' ') && res.exitCode == 0;
});
} }
(isDaemonRunning() ? it : it.skip)( (isDaemonRunning() ? it : it.skip)(
'valid', 'valid',

12155
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

View File

@ -27,24 +27,24 @@
], ],
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.7", "@actions/core": "^1.4.0",
"@actions/exec": "^1.0.4", "@actions/exec": "^1.1.0",
"@actions/http-client": "^1.0.11", "@actions/http-client": "^1.0.11",
"@actions/tool-cache": "^1.6.1", "@actions/tool-cache": "^1.7.1",
"semver": "^7.3.5", "semver": "^7.3.5",
"uuid": "^8.3.2" "uuid": "^8.3.2"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.3", "@types/jest": "^26.0.23",
"@types/node": "^14.0.14", "@types/node": "^14.17.4",
"@vercel/ncc": "^0.23.0", "@vercel/ncc": "^0.28.6",
"dotenv": "^8.2.0", "dotenv": "^8.6.0",
"jest": "^26.1.0", "jest": "^26.6.3",
"jest-circus": "^26.1.0", "jest-circus": "^26.6.3",
"jest-runtime": "^26.1.0", "jest-runtime": "^26.6.3",
"prettier": "^2.0.5", "prettier": "^2.3.1",
"ts-jest": "^26.1.1", "ts-jest": "^26.5.6",
"typescript": "^3.9.5", "typescript": "^4.3.4",
"typescript-formatter": "^7.2.2" "typescript-formatter": "^7.2.2"
} }
} }

View File

@ -3,9 +3,9 @@ import * as path from 'path';
import * as semver from 'semver'; import * as semver from 'semver';
import * as util from 'util'; import * as util from 'util';
import * as context from './context'; import * as context from './context';
import * as exec from './exec';
import * as github from './github'; import * as github from './github';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as tc from '@actions/tool-cache'; import * as tc from '@actions/tool-cache';
export type Builder = { export type Builder = {
@ -18,77 +18,92 @@ export type Builder = {
node_platforms?: string; node_platforms?: string;
}; };
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 res.exitCode == 0;
});
}
export async function getVersion(): Promise<string> { export async function getVersion(): Promise<string> {
return await exec.exec(`docker`, ['buildx', 'version'], true).then(res => { return await exec
if (res.stderr.length > 0 && !res.success) { .getExecOutput('docker', ['buildx', 'version'], {
throw new Error(res.stderr); ignoreReturnCode: true,
} silent: true
return parseVersion(res.stdout); })
}); .then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.trim());
}
return parseVersion(res.stdout);
});
} }
export async function parseVersion(stdout: string): Promise<string> { export async function parseVersion(stdout: string): Promise<string> {
const matches = /\sv?([0-9.]+)/.exec(stdout); const matches = /\sv?([0-9.]+)/.exec(stdout);
if (!matches) { if (!matches) {
throw new Error(`Cannot parse Buildx version`); throw new Error(`Cannot parse buildx version`);
} }
return semver.clean(matches[1]); 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> { export async function inspect(name: string): Promise<Builder> {
return await exec.exec(`docker`, ['buildx', 'inspect', name], true).then(res => { return await exec
if (res.stderr.length > 0 && !res.success) { .getExecOutput(`docker`, ['buildx', 'inspect', name], {
throw new Error(res.stderr); ignoreReturnCode: true,
} silent: true
const builder: Builder = {}; })
itlines: for (const line of res.stdout.trim().split(`\n`)) { .then(res => {
const [key, ...rest] = line.split(':'); if (res.stderr.length > 0 && res.exitCode != 0) {
const value = rest.map(v => v.trim()).join(':'); throw new Error(res.stderr.trim());
if (key.length == 0 || value.length == 0) {
continue;
} }
switch (key) { const builder: Builder = {};
case 'Name': { itlines: for (const line of res.stdout.trim().split(`\n`)) {
if (builder.name == undefined) { const [key, ...rest] = line.split(':');
builder.name = value; const value = rest.map(v => v.trim()).join(':');
} else { if (key.length == 0 || value.length == 0) {
builder.node_name = value; continue;
}
switch (key) {
case 'Name': {
if (builder.name == undefined) {
builder.name = value;
} else {
builder.node_name = value;
}
break;
}
case 'Driver': {
builder.driver = value;
break;
}
case 'Endpoint': {
builder.node_endpoint = value;
break;
}
case 'Status': {
builder.node_status = value;
break;
}
case 'Flags': {
builder.node_flags = value;
break;
}
case 'Platforms': {
builder.node_platforms = value.replace(/\s/g, '');
break itlines;
} }
break;
}
case 'Driver': {
builder.driver = value;
break;
}
case 'Endpoint': {
builder.node_endpoint = value;
break;
}
case 'Status': {
builder.node_status = value;
break;
}
case 'Flags': {
builder.node_flags = value;
break;
}
case 'Platforms': {
builder.node_platforms = value.replace(/\s/g, '');
break itlines;
} }
} }
} return builder;
return builder; });
});
} }
export async function install(inputVersion: string, dockerConfigHome: string): Promise<string> { export async function install(inputVersion: string, dockerConfigHome: string): Promise<string> {
@ -173,19 +188,29 @@ async function filename(version: string): Promise<string> {
} }
export async function getBuildKitVersion(containerID: string): Promise<string> { export async function getBuildKitVersion(containerID: string): Promise<string> {
return exec.exec(`docker`, ['inspect', '--format', '{{.Config.Image}}', containerID], true).then(bkitimage => { return exec
if (bkitimage.success && bkitimage.stdout.length > 0) { .getExecOutput(`docker`, ['inspect', '--format', '{{.Config.Image}}', containerID], {
return exec.exec(`docker`, ['run', '--rm', bkitimage.stdout, '--version'], true).then(bkitversion => { ignoreReturnCode: true,
if (bkitversion.success && bkitversion.stdout.length > 0) { silent: true
return `${bkitimage.stdout} => ${bkitversion.stdout}`; })
} else if (bkitversion.stderr.length > 0) { .then(bkitimage => {
core.warning(bkitversion.stderr); if (bkitimage.exitCode == 0 && bkitimage.stdout.length > 0) {
} return exec
return bkitversion.stdout; .getExecOutput(`docker`, ['run', '--rm', bkitimage.stdout, '--version'], {
}); ignoreReturnCode: true,
} else if (bkitimage.stderr.length > 0) { silent: true
core.warning(bkitimage.stderr); })
} .then(bkitversion => {
return bkitimage.stdout; if (bkitversion.exitCode == 0 && bkitversion.stdout.length > 0) {
}); return `${bkitimage.stdout} => ${bkitversion.stdout}`;
} else if (bkitversion.stderr.length > 0) {
core.warning(bkitversion.stderr.trim());
}
return bkitversion.stdout;
});
} else if (bkitimage.stderr.length > 0) {
core.warning(bkitimage.stderr.trim());
}
return bkitimage.stdout;
});
} }

View File

@ -24,8 +24,8 @@ export async function getInputs(): Promise<Inputs> {
buildkitdFlags: buildkitdFlags:
core.getInput('buildkitd-flags') || core.getInput('buildkitd-flags') ||
'--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host', '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
install: /true/i.test(core.getInput('install')), install: core.getBooleanInput('install'),
use: /true/i.test(core.getInput('use')), use: core.getBooleanInput('use'),
endpoint: core.getInput('endpoint'), endpoint: core.getInput('endpoint'),
config: core.getInput('config') config: core.getInput('config')
}; };

View File

@ -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;
});
}

View File

@ -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()
};
};

View File

@ -1,12 +1,11 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as os from 'os'; import * as os from 'os';
import * as path from 'path'; import * as path from 'path';
import * as semver from 'semver'; import * as semver from 'semver';
import * as buildx from './buildx'; import * as buildx from './buildx';
import * as context from './context'; import * as context from './context';
import * as mexec from './exec';
import * as stateHelper from './state-helper'; import * as stateHelper from './state-helper';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
async function run(): Promise<void> { async function run(): Promise<void> {
try { try {
@ -25,8 +24,6 @@ async function run(): Promise<void> {
} }
const buildxVersion = await buildx.getVersion(); const buildxVersion = await buildx.getVersion();
core.info(`Using buildx ${buildxVersion}`);
const builderName: string = inputs.driver == 'docker' ? 'default' : `builder-${require('uuid').v4()}`; const builderName: string = inputs.driver == 'docker' ? 'default' : `builder-${require('uuid').v4()}`;
context.setOutput('name', builderName); context.setOutput('name', builderName);
stateHelper.setBuilderName(builderName); stateHelper.setBuilderName(builderName);
@ -96,21 +93,29 @@ async function run(): Promise<void> {
async function cleanup(): Promise<void> { async function cleanup(): Promise<void> {
if (stateHelper.IsDebug && stateHelper.containerName.length > 0) { if (stateHelper.IsDebug && stateHelper.containerName.length > 0) {
core.startGroup(`BuildKit container logs`); core.startGroup(`BuildKit container logs`);
await mexec.exec('docker', ['logs', `${stateHelper.containerName}`], false).then(res => { await exec
if (res.stderr.length > 0 && !res.success) { .getExecOutput('docker', ['logs', `${stateHelper.containerName}`], {
core.warning(res.stderr); ignoreReturnCode: true
} })
}); .then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
core.warning(res.stderr.trim());
}
});
core.endGroup(); core.endGroup();
} }
if (stateHelper.builderName.length > 0) { if (stateHelper.builderName.length > 0) {
core.startGroup(`Removing builder`); core.startGroup(`Removing builder`);
await mexec.exec('docker', ['buildx', 'rm', `${stateHelper.builderName}`], false).then(res => { await exec
if (res.stderr.length > 0 && !res.success) { .getExecOutput('docker', ['buildx', 'rm', `${stateHelper.builderName}`], {
core.warning(res.stderr); ignoreReturnCode: true
} })
}); .then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
core.warning(res.stderr.trim());
}
});
core.endGroup(); core.endGroup();
} }
} }

2140
yarn.lock

File diff suppressed because it is too large Load Diff