From a7448298e01a90c2bcc9e35928b1a431bd940f4b Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 26 Mar 2023 19:26:59 +0200 Subject: [PATCH] bake: fix undefined output property Signed-off-by: CrazyMax --- __tests__/buildx/bake.test.ts | 19 +++++++++-- ...ke-validate.json => bake-01-validate.json} | 0 __tests__/fixtures/{bake.hcl => bake-01.hcl} | 0 __tests__/fixtures/bake-02-build.json | 20 +++++++++++ __tests__/fixtures/bake-02.hcl | 33 +++++++++++++++++++ src/buildx/bake.ts | 4 ++- src/types/bake.ts | 32 +++++++++--------- 7 files changed, 89 insertions(+), 19 deletions(-) rename __tests__/fixtures/{bake-validate.json => bake-01-validate.json} (100%) rename __tests__/fixtures/{bake.hcl => bake-01.hcl} (100%) create mode 100644 __tests__/fixtures/bake-02-build.json create mode 100644 __tests__/fixtures/bake-02.hcl diff --git a/__tests__/buildx/bake.test.ts b/__tests__/buildx/bake.test.ts index c929f238..1cf94fb7 100644 --- a/__tests__/buildx/bake.test.ts +++ b/__tests__/buildx/bake.test.ts @@ -31,9 +31,14 @@ describe('parseDefinitions', () => { // prettier-ignore test.each([ [ - [path.join(fixturesDir, 'bake.hcl')], + [path.join(fixturesDir, 'bake-01.hcl')], ['validate'], - path.join(fixturesDir, 'bake-validate.json') + path.join(fixturesDir, 'bake-01-validate.json') + ], + [ + [path.join(fixturesDir, 'bake-02.hcl')], + ['build'], + path.join(fixturesDir, 'bake-02-build.json') ] ])('given %p', async (sources: string[], targets: string[], out: string) => { const bake = new Bake(); @@ -57,6 +62,16 @@ describe('hasLocalExporter', () => { }, false ], + [ + { + "target": { + "build": { + "target": "build" + }, + } + }, + false + ], [ { "target": { diff --git a/__tests__/fixtures/bake-validate.json b/__tests__/fixtures/bake-01-validate.json similarity index 100% rename from __tests__/fixtures/bake-validate.json rename to __tests__/fixtures/bake-01-validate.json diff --git a/__tests__/fixtures/bake.hcl b/__tests__/fixtures/bake-01.hcl similarity index 100% rename from __tests__/fixtures/bake.hcl rename to __tests__/fixtures/bake-01.hcl diff --git a/__tests__/fixtures/bake-02-build.json b/__tests__/fixtures/bake-02-build.json new file mode 100644 index 00000000..147f4ce5 --- /dev/null +++ b/__tests__/fixtures/bake-02-build.json @@ -0,0 +1,20 @@ +{ + "group": { + "default": { + "targets": [ + "build" + ] + } + }, + "target": { + "build": { + "context": ".", + "dockerfile": "Dockerfile", + "args": { + "BUILDKIT_CONTEXT_KEEP_GIT_DIR": "1", + "GO_VERSION": "1.20" + }, + "target": "build" + } + } +} diff --git a/__tests__/fixtures/bake-02.hcl b/__tests__/fixtures/bake-02.hcl new file mode 100644 index 00000000..d2bafa49 --- /dev/null +++ b/__tests__/fixtures/bake-02.hcl @@ -0,0 +1,33 @@ +// Copyright 2023 actions-toolkit authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +variable "GO_VERSION" { + default = "1.20" +} + +target "_common" { + args = { + GO_VERSION = GO_VERSION + BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1 + } +} + +group "default" { + targets = ["build"] +} + +target "build" { + inherits = ["_common"] + target = "build" +} diff --git a/src/buildx/bake.ts b/src/buildx/bake.ts index b639bb74..7576a9ea 100644 --- a/src/buildx/bake.ts +++ b/src/buildx/bake.ts @@ -84,7 +84,9 @@ export class Bake { const exporters = new Array(); for (const key in def.target) { const target = def.target[key]; - exporters.push(...target.output); + if (target.output) { + exporters.push(...target.output); + } } return exporters; } diff --git a/src/types/bake.ts b/src/types/bake.ts index 57c09f9b..089efdef 100644 --- a/src/types/bake.ts +++ b/src/types/bake.ts @@ -24,22 +24,22 @@ export interface Group { } export interface Target { - args: Record; - attest: Array; - 'cache-from': Array; - 'cache-to': Array; + args?: Record; + attest?: Array; + 'cache-from'?: Array; + 'cache-to'?: Array; context: string; - contexts: Record; + contexts?: Record; dockerfile: string; - 'dockerfile-inline': string; - labels: Record; - 'no-cache': boolean; - 'no-cache-filter': Array; - output: Array; - platforms: Array; - pull: boolean; - secret: Array; - ssh: Array; - tags: Array; - target: string; + 'dockerfile-inline'?: string; + labels?: Record; + 'no-cache'?: boolean; + 'no-cache-filter'?: Array; + output?: Array; + platforms?: Array; + pull?: boolean; + secret?: Array; + ssh?: Array; + tags?: Array; + target?: string; }