mirror of
https://github.com/docker/build-push-action.git
synced 2024-11-15 18:13:52 +08:00
Check Buildx version
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
f11192a27b
commit
3e57a3300a
19
.github/workflows/ci.yml
vendored
19
.github/workflows/ci.yml
vendored
@ -13,6 +13,12 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
single:
|
single:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
buildx-version:
|
||||||
|
- ""
|
||||||
|
- latest
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Run local registry
|
name: Run local registry
|
||||||
@ -31,6 +37,7 @@ jobs:
|
|||||||
id: buildx
|
id: buildx
|
||||||
uses: ./setup-buildx/ # change to docker/setup-buildx-action@master
|
uses: ./setup-buildx/ # change to docker/setup-buildx-action@master
|
||||||
with:
|
with:
|
||||||
|
version: ${{ matrix.buildx-version }}
|
||||||
driver-opt: network=host
|
driver-opt: network=host
|
||||||
buildkitd-flags: --allow-insecure-entitlement security.insecure
|
buildkitd-flags: --allow-insecure-entitlement security.insecure
|
||||||
-
|
-
|
||||||
@ -63,6 +70,9 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
|
buildx-version:
|
||||||
|
- ""
|
||||||
|
- latest
|
||||||
dockerfile:
|
dockerfile:
|
||||||
- multi
|
- multi
|
||||||
- multi-sudo
|
- multi-sudo
|
||||||
@ -84,6 +94,7 @@ jobs:
|
|||||||
id: buildx
|
id: buildx
|
||||||
uses: ./setup-buildx/ # change to docker/setup-buildx-action@master
|
uses: ./setup-buildx/ # change to docker/setup-buildx-action@master
|
||||||
with:
|
with:
|
||||||
|
version: ${{ matrix.buildx-version }}
|
||||||
driver-opt: network=host
|
driver-opt: network=host
|
||||||
buildkitd-flags: --allow-insecure-entitlement security.insecure
|
buildkitd-flags: --allow-insecure-entitlement security.insecure
|
||||||
-
|
-
|
||||||
@ -110,6 +121,12 @@ jobs:
|
|||||||
|
|
||||||
git-context:
|
git-context:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
buildx-version:
|
||||||
|
#- "" # GIT_AUTH_TOKEN not available in the current version on the GitHub Runner
|
||||||
|
- latest
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Run local registry
|
name: Run local registry
|
||||||
@ -128,7 +145,7 @@ jobs:
|
|||||||
id: buildx
|
id: buildx
|
||||||
uses: ./setup-buildx/ # change to docker/setup-buildx-action@master
|
uses: ./setup-buildx/ # change to docker/setup-buildx-action@master
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: ${{ matrix.buildx-version }}
|
||||||
driver-opt: network=host
|
driver-opt: network=host
|
||||||
buildkitd-flags: --allow-insecure-entitlement security.insecure
|
buildkitd-flags: --allow-insecure-entitlement security.insecure
|
||||||
-
|
-
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import * as semver from 'semver';
|
||||||
import * as buildx from '../src/buildx';
|
import * as buildx from '../src/buildx';
|
||||||
|
|
||||||
const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
|
const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
|
||||||
@ -13,3 +14,20 @@ describe('getImageID', () => {
|
|||||||
expect(imageID).toEqual(digest);
|
expect(imageID).toEqual(digest);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getVersion', () => {
|
||||||
|
it('valid', async () => {
|
||||||
|
const version = await buildx.getVersion();
|
||||||
|
console.log(`version: ${version}`);
|
||||||
|
expect(semver.valid(version)).not.toBeNull();
|
||||||
|
}, 100000);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parseVersion', () => {
|
||||||
|
test.each([
|
||||||
|
['github.com/docker/buildx v0.4.1 bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'],
|
||||||
|
['github.com/docker/buildx v0.4.2 fb7b670b764764dc4716df3eba07ffdae4cc47b2', '0.4.2']
|
||||||
|
])('given %p', async (stdout, expected) => {
|
||||||
|
expect(await buildx.parseVersion(stdout)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
2181
dist/index.js
generated
vendored
2181
dist/index.js
generated
vendored
File diff suppressed because it is too large
Load Diff
@ -30,7 +30,8 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.4",
|
"@actions/core": "^1.2.4",
|
||||||
"@actions/exec": "^1.0.4"
|
"@actions/exec": "^1.0.4",
|
||||||
|
"semver": "^7.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.3",
|
"@types/jest": "^26.0.3",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import * as semver from 'semver';
|
||||||
import * as context from './context';
|
import * as context from './context';
|
||||||
import * as exec from './exec';
|
import * as exec from './exec';
|
||||||
|
|
||||||
@ -24,6 +25,23 @@ export async function isAvailable(): Promise<Boolean> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getVersion(): Promise<string> {
|
||||||
|
return await exec.exec(`docker`, ['buildx', 'version'], true).then(res => {
|
||||||
|
if (res.stderr != '' && !res.success) {
|
||||||
|
throw new Error(res.stderr);
|
||||||
|
}
|
||||||
|
return parseVersion(res.stdout);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function parseVersion(stdout: string): Promise<string> {
|
||||||
|
const matches = /\sv([0-9.]+)\s/.exec(stdout);
|
||||||
|
if (!matches) {
|
||||||
|
throw new Error(`Cannot parse Buildx version`);
|
||||||
|
}
|
||||||
|
return semver.clean(matches[1]);
|
||||||
|
}
|
||||||
|
|
||||||
export async function use(builder: string): Promise<void> {
|
export async function use(builder: string): Promise<void> {
|
||||||
return await exec.exec(`docker`, ['buildx', 'use', '--builder', builder], false).then(res => {
|
return await exec.exec(`docker`, ['buildx', 'use', '--builder', builder], false).then(res => {
|
||||||
if (res.stderr != '' && !res.success) {
|
if (res.stderr != '' && !res.success) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
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 buildx from './buildx';
|
import * as buildx from './buildx';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
@ -46,15 +47,15 @@ export async function getInputs(): Promise<Inputs> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getArgs(inputs: Inputs): Promise<Array<string>> {
|
export async function getArgs(inputs: Inputs, buildxVersion: string): Promise<Array<string>> {
|
||||||
let args: Array<string> = ['buildx'];
|
let args: Array<string> = ['buildx'];
|
||||||
args.push.apply(args, await getBuildArgs(inputs));
|
args.push.apply(args, await getBuildArgs(inputs, buildxVersion));
|
||||||
args.push.apply(args, await getCommonArgs(inputs));
|
args.push.apply(args, await getCommonArgs(inputs));
|
||||||
args.push(inputs.context);
|
args.push(inputs.context);
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getBuildArgs(inputs: Inputs): Promise<Array<string>> {
|
async function getBuildArgs(inputs: Inputs, buildxVersion: string): Promise<Array<string>> {
|
||||||
let args: Array<string> = ['build'];
|
let args: Array<string> = ['build'];
|
||||||
await asyncForEach(inputs.buildArgs, async buildArg => {
|
await asyncForEach(inputs.buildArgs, async buildArg => {
|
||||||
args.push('--build-arg', buildArg);
|
args.push('--build-arg', buildArg);
|
||||||
@ -73,7 +74,8 @@ async function getBuildArgs(inputs: Inputs): Promise<Array<string>> {
|
|||||||
}
|
}
|
||||||
if (inputs.platforms.length > 0) {
|
if (inputs.platforms.length > 0) {
|
||||||
args.push('--platform', inputs.platforms.join(','));
|
args.push('--platform', inputs.platforms.join(','));
|
||||||
} else {
|
}
|
||||||
|
if (inputs.platforms.length == 0 || semver.satisfies(buildxVersion, '>=0.4.2')) {
|
||||||
args.push('--iidfile', await buildx.getImageIDFile());
|
args.push('--iidfile', await buildx.getImageIDFile());
|
||||||
}
|
}
|
||||||
await asyncForEach(inputs.outputs, async output => {
|
await asyncForEach(inputs.outputs, async output => {
|
||||||
|
@ -16,6 +16,9 @@ async function run(): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const buildxVersion = await buildx.getVersion();
|
||||||
|
core.info(`📣 Buildx version: ${buildxVersion}`);
|
||||||
|
|
||||||
let inputs: Inputs = await getInputs();
|
let inputs: Inputs = await getInputs();
|
||||||
if (inputs.builder) {
|
if (inputs.builder) {
|
||||||
core.info(`📌 Using builder instance ${inputs.builder}`);
|
core.info(`📌 Using builder instance ${inputs.builder}`);
|
||||||
@ -23,7 +26,7 @@ async function run(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.info(`🏃 Starting build...`);
|
core.info(`🏃 Starting build...`);
|
||||||
const args: string[] = await getArgs(inputs);
|
const args: string[] = await getArgs(inputs, buildxVersion);
|
||||||
await exec.exec('docker', args);
|
await exec.exec('docker', args);
|
||||||
|
|
||||||
const imageID = await buildx.getImageID();
|
const imageID = await buildx.getImageID();
|
||||||
|
Loading…
Reference in New Issue
Block a user