mirror of
https://github.com/docker/build-push-action.git
synced 2025-04-19 18:06:46 +00:00
Handle build bake through bake, bake-files and bake-targets
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
b07bd1f9df
commit
8be103ff82
9 changed files with 475 additions and 241 deletions
57
src/main.ts
57
src/main.ts
|
@ -1,6 +1,6 @@
|
|||
import * as os from 'os';
|
||||
import * as buildx from './buildx';
|
||||
import {Inputs, loadInputs} from './context-helper';
|
||||
import {Inputs, getInputs, getArgs} from './context';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
|
@ -11,74 +11,23 @@ async function run(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
const inputs: Inputs = await loadInputs();
|
||||
|
||||
if (!(await buildx.isAvailable())) {
|
||||
core.setFailed(`Buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);
|
||||
return;
|
||||
}
|
||||
|
||||
let buildArgs: Array<string> = ['buildx', 'build'];
|
||||
const inputs: Inputs = await getInputs();
|
||||
|
||||
if (inputs.builder) {
|
||||
core.info(`📌 Using builder instance ${inputs.builder}`);
|
||||
await buildx.use(inputs.builder);
|
||||
}
|
||||
if (inputs.file) {
|
||||
buildArgs.push('--file', inputs.file);
|
||||
}
|
||||
await asyncForEach(inputs.buildArgs, async buildArg => {
|
||||
buildArgs.push('--build-arg', buildArg);
|
||||
});
|
||||
await asyncForEach(inputs.labels, async label => {
|
||||
buildArgs.push('--label', label);
|
||||
});
|
||||
await asyncForEach(inputs.tags, async tag => {
|
||||
buildArgs.push('--tag', tag);
|
||||
});
|
||||
if (inputs.pull) {
|
||||
buildArgs.push('--pull');
|
||||
}
|
||||
if (inputs.target) {
|
||||
buildArgs.push('--target', inputs.target);
|
||||
}
|
||||
if (inputs.allow) {
|
||||
buildArgs.push('--allow', inputs.allow);
|
||||
}
|
||||
if (inputs.noCache) {
|
||||
buildArgs.push('--no-cache');
|
||||
}
|
||||
if (inputs.platforms) {
|
||||
buildArgs.push('--platform', inputs.platforms);
|
||||
}
|
||||
if (inputs.load) {
|
||||
buildArgs.push('--load');
|
||||
}
|
||||
if (inputs.push) {
|
||||
buildArgs.push('--push');
|
||||
}
|
||||
await asyncForEach(inputs.outputs, async output => {
|
||||
buildArgs.push('--output', output);
|
||||
});
|
||||
await asyncForEach(inputs.cacheFrom, async cacheFrom => {
|
||||
buildArgs.push('--cache-from', cacheFrom);
|
||||
});
|
||||
await asyncForEach(inputs.cacheTo, async cacheTo => {
|
||||
buildArgs.push('--cache-from', cacheTo);
|
||||
});
|
||||
buildArgs.push(inputs.context);
|
||||
|
||||
core.info(`🏃 Starting build...`);
|
||||
await exec.exec('docker', buildArgs);
|
||||
await exec.exec('docker', await getArgs(inputs));
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
const asyncForEach = async (array, callback) => {
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
await callback(array[index], index, array);
|
||||
}
|
||||
};
|
||||
|
||||
run();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue