mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-23 19:56:09 +08:00
Merge pull request #95 from crazy-max/fix-bake-def-parse
bake: missing overrides when parsing definition
This commit is contained in:
commit
3ebf172e37
@ -33,17 +33,25 @@ describe('parseDefinitions', () => {
|
|||||||
[
|
[
|
||||||
[path.join(fixturesDir, 'bake-01.hcl')],
|
[path.join(fixturesDir, 'bake-01.hcl')],
|
||||||
['validate'],
|
['validate'],
|
||||||
|
[],
|
||||||
path.join(fixturesDir, 'bake-01-validate.json')
|
path.join(fixturesDir, 'bake-01-validate.json')
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[path.join(fixturesDir, 'bake-02.hcl')],
|
[path.join(fixturesDir, 'bake-02.hcl')],
|
||||||
['build'],
|
['build'],
|
||||||
|
[],
|
||||||
path.join(fixturesDir, 'bake-02-build.json')
|
path.join(fixturesDir, 'bake-02-build.json')
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[path.join(fixturesDir, 'bake-01.hcl')],
|
||||||
|
['image'],
|
||||||
|
['*.output=type=docker', '*.platform=linux/amd64'],
|
||||||
|
path.join(fixturesDir, 'bake-01-overrides.json')
|
||||||
]
|
]
|
||||||
])('given %p', async (sources: string[], targets: string[], out: string) => {
|
])('given %p', async (sources: string[], targets: string[], overrides: string[], out: string) => {
|
||||||
const bake = new Bake();
|
const bake = new Bake();
|
||||||
const expectedDef = <BakeDefinition>JSON.parse(fs.readFileSync(out, {encoding: 'utf-8'}).trim())
|
const expectedDef = <BakeDefinition>JSON.parse(fs.readFileSync(out, {encoding: 'utf-8'}).trim())
|
||||||
expect(await bake.parseDefinitions(sources, targets)).toEqual(expectedDef);
|
expect(await bake.parseDefinitions(sources, targets, overrides)).toEqual(expectedDef);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
29
__tests__/fixtures/bake-01-overrides.json
Normal file
29
__tests__/fixtures/bake-01-overrides.json
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"group": {
|
||||||
|
"default": {
|
||||||
|
"targets": [
|
||||||
|
"image"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"target": {
|
||||||
|
"image": {
|
||||||
|
"context": ".",
|
||||||
|
"dockerfile": "Dockerfile",
|
||||||
|
"args": {
|
||||||
|
"BUILDKIT_CONTEXT_KEEP_GIT_DIR": "1",
|
||||||
|
"GO_VERSION": "1.20"
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"docker/buildx-bin:local"
|
||||||
|
],
|
||||||
|
"target": "binaries",
|
||||||
|
"platforms": [
|
||||||
|
"linux/amd64"
|
||||||
|
],
|
||||||
|
"output": [
|
||||||
|
"type=docker"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -32,7 +32,7 @@ export class Bake {
|
|||||||
this.buildx = opts?.buildx || new Buildx();
|
this.buildx = opts?.buildx || new Buildx();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async parseDefinitions(sources: Array<string>, targets: Array<string>, workdir?: string): Promise<BakeDefinition> {
|
public async parseDefinitions(sources: Array<string>, targets?: Array<string>, overrides?: Array<string>, load?: boolean, push?: boolean, workdir?: string): Promise<BakeDefinition> {
|
||||||
const args = ['bake'];
|
const args = ['bake'];
|
||||||
|
|
||||||
let remoteDef;
|
let remoteDef;
|
||||||
@ -58,8 +58,19 @@ export class Bake {
|
|||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
args.push('--file', file);
|
args.push('--file', file);
|
||||||
}
|
}
|
||||||
|
if (overrides) {
|
||||||
|
for (const override of overrides) {
|
||||||
|
args.push('--set', override);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (load) {
|
||||||
|
args.push('--load');
|
||||||
|
}
|
||||||
|
if (push) {
|
||||||
|
args.push('--push');
|
||||||
|
}
|
||||||
|
|
||||||
const printCmd = await this.buildx.getCommand([...args, '--print', ...targets]);
|
const printCmd = await this.buildx.getCommand([...args, '--print', ...(targets || [])]);
|
||||||
return await Exec.getExecOutput(printCmd.command, printCmd.args, {
|
return await Exec.getExecOutput(printCmd.command, printCmd.args, {
|
||||||
cwd: workdir,
|
cwd: workdir,
|
||||||
ignoreReturnCode: true,
|
ignoreReturnCode: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user