Skip to content

Commit

Permalink
bake: missing overrides when parsing definition
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Apr 18, 2023
1 parent 0f6ebcb commit dba2a69
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
12 changes: 10 additions & 2 deletions __tests__/buildx/bake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <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);
});
});

Expand Down
29 changes: 29 additions & 0 deletions __tests__/fixtures/bake-01-overrides.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
15 changes: 13 additions & 2 deletions src/buildx/bake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Bake {
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'];

let remoteDef;
Expand All @@ -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,
Expand Down

0 comments on commit dba2a69

Please sign in to comment.