Handle build bake through bake, bake-files and bake-targets
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>pull/92/head
parent
b07bd1f9df
commit
8be103ff82
@ -1,49 +0,0 @@
|
|||||||
import * as core from '@actions/core';
|
|
||||||
|
|
||||||
export interface Inputs {
|
|
||||||
context: string;
|
|
||||||
file: string;
|
|
||||||
buildArgs: string[];
|
|
||||||
labels: string[];
|
|
||||||
tags: string[];
|
|
||||||
pull: boolean;
|
|
||||||
target: string;
|
|
||||||
allow: string;
|
|
||||||
noCache: boolean;
|
|
||||||
builder: string;
|
|
||||||
platforms: string;
|
|
||||||
load: boolean;
|
|
||||||
push: boolean;
|
|
||||||
outputs: string[];
|
|
||||||
cacheFrom: string[];
|
|
||||||
cacheTo: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function loadInputs(): Promise<Inputs> {
|
|
||||||
return {
|
|
||||||
context: core.getInput('context') || '.',
|
|
||||||
file: core.getInput('file') || './Dockerfile',
|
|
||||||
buildArgs: await getInputList('build-args'),
|
|
||||||
labels: await getInputList('labels'),
|
|
||||||
tags: await getInputList('tags'),
|
|
||||||
pull: /true/i.test(core.getInput('pull')),
|
|
||||||
target: core.getInput('target'),
|
|
||||||
allow: core.getInput('allow'),
|
|
||||||
noCache: /true/i.test(core.getInput('no-cache')),
|
|
||||||
builder: core.getInput('builder'),
|
|
||||||
platforms: core.getInput('platforms'),
|
|
||||||
load: /true/i.test(core.getInput('load')),
|
|
||||||
push: /true/i.test(core.getInput('push')),
|
|
||||||
outputs: await getInputList('outputs'),
|
|
||||||
cacheFrom: await getInputList('cache-from'),
|
|
||||||
cacheTo: await getInputList('cache-to')
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getInputList(name: string): Promise<string[]> {
|
|
||||||
const items = core.getInput(name);
|
|
||||||
if (items == '') {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return items.split(/\r?\n/).reduce<string[]>((acc, line) => acc.concat(line.split(',')).map(pat => pat.trim()), []);
|
|
||||||
}
|
|
||||||
@ -0,0 +1,139 @@
|
|||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
|
export interface Inputs {
|
||||||
|
context: string;
|
||||||
|
file: string;
|
||||||
|
buildArgs: string[];
|
||||||
|
labels: string[];
|
||||||
|
tags: string[];
|
||||||
|
pull: boolean;
|
||||||
|
target: string;
|
||||||
|
allow: string;
|
||||||
|
noCache: boolean;
|
||||||
|
builder: string;
|
||||||
|
platforms: string;
|
||||||
|
load: boolean;
|
||||||
|
push: boolean;
|
||||||
|
outputs: string[];
|
||||||
|
cacheFrom: string[];
|
||||||
|
cacheTo: string[];
|
||||||
|
bake: boolean;
|
||||||
|
bakeFiles: string[];
|
||||||
|
bakeTargets: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getInputs(): Promise<Inputs> {
|
||||||
|
return {
|
||||||
|
context: core.getInput('context') || '.',
|
||||||
|
file: core.getInput('file') || './Dockerfile',
|
||||||
|
buildArgs: await getInputList('build-args'),
|
||||||
|
labels: await getInputList('labels'),
|
||||||
|
tags: await getInputList('tags'),
|
||||||
|
pull: /true/i.test(core.getInput('pull')),
|
||||||
|
target: core.getInput('target'),
|
||||||
|
allow: core.getInput('allow'),
|
||||||
|
noCache: /true/i.test(core.getInput('no-cache')),
|
||||||
|
builder: core.getInput('builder'),
|
||||||
|
platforms: core.getInput('platforms'),
|
||||||
|
load: /true/i.test(core.getInput('load')),
|
||||||
|
push: /true/i.test(core.getInput('push')),
|
||||||
|
outputs: await getInputList('outputs'),
|
||||||
|
cacheFrom: await getInputList('cache-from'),
|
||||||
|
cacheTo: await getInputList('cache-to'),
|
||||||
|
bake: /true/i.test(core.getInput('bake')),
|
||||||
|
bakeFiles: await getInputList('bake-files'),
|
||||||
|
bakeTargets: await getInputList('bake-targets')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getArgs(inputs: Inputs): Promise<string[]> {
|
||||||
|
let args: Array<string> = ['buildx'];
|
||||||
|
if (inputs.bake) {
|
||||||
|
args.concat(await getBakeArgs(inputs));
|
||||||
|
} else {
|
||||||
|
args.concat(await getBuildArgs(inputs));
|
||||||
|
}
|
||||||
|
args.concat(await getCommonArgs(inputs));
|
||||||
|
|
||||||
|
if (!inputs.bake) {
|
||||||
|
args.push(inputs.context);
|
||||||
|
} else {
|
||||||
|
args.concat(inputs.bakeTargets);
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getCommonArgs(inputs: Inputs): Promise<string[]> {
|
||||||
|
let args: Array<string> = [];
|
||||||
|
if (inputs.noCache) {
|
||||||
|
args.push('--no-cache');
|
||||||
|
}
|
||||||
|
if (inputs.pull) {
|
||||||
|
args.push('--pull');
|
||||||
|
}
|
||||||
|
if (inputs.load) {
|
||||||
|
args.push('--load');
|
||||||
|
}
|
||||||
|
if (inputs.push) {
|
||||||
|
args.push('--push');
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getBakeArgs(inputs: Inputs): Promise<string[]> {
|
||||||
|
let args: Array<string> = ['bake'];
|
||||||
|
await asyncForEach(inputs.bakeFiles, async bakeFile => {
|
||||||
|
args.push('--file', bakeFile);
|
||||||
|
});
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getBuildArgs(inputs: Inputs): Promise<string[]> {
|
||||||
|
let args: Array<string> = ['build'];
|
||||||
|
await asyncForEach(inputs.buildArgs, async buildArg => {
|
||||||
|
args.push('--build-arg', buildArg);
|
||||||
|
});
|
||||||
|
await asyncForEach(inputs.labels, async label => {
|
||||||
|
args.push('--label', label);
|
||||||
|
});
|
||||||
|
await asyncForEach(inputs.tags, async tag => {
|
||||||
|
args.push('--tag', tag);
|
||||||
|
});
|
||||||
|
if (inputs.target) {
|
||||||
|
args.push('--target', inputs.target);
|
||||||
|
}
|
||||||
|
if (inputs.allow) {
|
||||||
|
args.push('--allow', inputs.allow);
|
||||||
|
}
|
||||||
|
if (inputs.platforms) {
|
||||||
|
args.push('--platform', inputs.platforms);
|
||||||
|
}
|
||||||
|
await asyncForEach(inputs.outputs, async output => {
|
||||||
|
args.push('--output', output);
|
||||||
|
});
|
||||||
|
await asyncForEach(inputs.cacheFrom, async cacheFrom => {
|
||||||
|
args.push('--cache-from', cacheFrom);
|
||||||
|
});
|
||||||
|
await asyncForEach(inputs.cacheTo, async cacheTo => {
|
||||||
|
args.push('--cache-from', cacheTo);
|
||||||
|
});
|
||||||
|
if (inputs.file) {
|
||||||
|
args.push('--file', inputs.file);
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getInputList(name: string): Promise<string[]> {
|
||||||
|
const items = core.getInput(name);
|
||||||
|
if (items == '') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return items.split(/\r?\n/).reduce<string[]>((acc, line) => acc.concat(line.split(',')).map(pat => pat.trim()), []);
|
||||||
|
}
|
||||||
|
|
||||||
|
const asyncForEach = async (array, callback) => {
|
||||||
|
for (let index = 0; index < array.length; index++) {
|
||||||
|
await callback(array[index], index, array);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
FROM alpine
|
||||||
|
|
||||||
|
ARG name=world
|
||||||
|
RUN echo "Hello ${name}!"
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
group "default" {
|
||||||
|
targets = ["db", "app"]
|
||||||
|
}
|
||||||
|
|
||||||
|
group "release" {
|
||||||
|
targets = ["db", "app-plus"]
|
||||||
|
}
|
||||||
|
|
||||||
|
target "db" {
|
||||||
|
context = "./test"
|
||||||
|
tags = ["docker.io/tonistiigi/db"]
|
||||||
|
}
|
||||||
|
|
||||||
|
target "app" {
|
||||||
|
context = "./test"
|
||||||
|
dockerfile = "Dockerfile-bake"
|
||||||
|
args = {
|
||||||
|
name = "foo"
|
||||||
|
}
|
||||||
|
tags = [
|
||||||
|
"localhost:5000/name/app:latest",
|
||||||
|
"localhost:5000/name/app:1.0.0"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
target "cross" {
|
||||||
|
platforms = [
|
||||||
|
"linux/amd64",
|
||||||
|
"linux/arm64",
|
||||||
|
"linux/386"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
target "app-plus" {
|
||||||
|
inherits = ["app", "cross"]
|
||||||
|
args = {
|
||||||
|
IAMPLUS = "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue