From dba2a69f6143d7b1c3d0b8c7133acbb53b74d0d5 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Tue, 18 Apr 2023 14:16:46 +0200 Subject: [PATCH] bake: missing overrides when parsing definition Signed-off-by: CrazyMax --- __tests__/buildx/bake.test.ts | 12 ++++++++-- __tests__/fixtures/bake-01-overrides.json | 29 +++++++++++++++++++++++ src/buildx/bake.ts | 15 ++++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 __tests__/fixtures/bake-01-overrides.json diff --git a/__tests__/buildx/bake.test.ts b/__tests__/buildx/bake.test.ts index b46126a..5fd6ceb 100644 --- a/__tests__/buildx/bake.test.ts +++ b/__tests__/buildx/bake.test.ts @@ -33,17 +33,25 @@ describe('parseDefinitions', () => { [ [path.join(fixturesDir, 'bake-01.hcl')], ['validate'], + [], path.join(fixturesDir, 'bake-01-validate.json') ], [ [path.join(fixturesDir, 'bake-02.hcl')], ['build'], + [], 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 expectedDef = 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); }); }); diff --git a/__tests__/fixtures/bake-01-overrides.json b/__tests__/fixtures/bake-01-overrides.json new file mode 100644 index 0000000..0de1200 --- /dev/null +++ b/__tests__/fixtures/bake-01-overrides.json @@ -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" + ] + } + } +} diff --git a/src/buildx/bake.ts b/src/buildx/bake.ts index b276411..7b96693 100644 --- a/src/buildx/bake.ts +++ b/src/buildx/bake.ts @@ -32,7 +32,7 @@ export class Bake { this.buildx = opts?.buildx || new Buildx(); } - public async parseDefinitions(sources: Array, targets: Array, workdir?: string): Promise { + public async parseDefinitions(sources: Array, targets?: Array, overrides?: Array, load?: boolean, push?: boolean, workdir?: string): Promise { const args = ['bake']; let remoteDef; @@ -58,8 +58,19 @@ export class Bake { for (const file of files) { 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, { cwd: workdir, ignoreReturnCode: true,