From abfb2c064ded02f7ee600d3715b183150e795a92 Mon Sep 17 00:00:00 2001 From: Anthony Poschen Date: Mon, 26 Oct 2020 15:56:18 +1100 Subject: [PATCH 1/3] Add support for empty strings in target elements and compact func. Signed-off-by: Anthony Poschen --- bake/bake.go | 3 +++ bake/hcl.go | 1 + 2 files changed, 4 insertions(+) diff --git a/bake/bake.go b/bake/bake.go index e5ee0ca9..a8c7c37f 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -526,6 +526,9 @@ func removeDupes(s []string) []string { if _, ok := seen[v]; ok { continue } + if v == "" { + continue + } seen[v] = struct{}{} s[i] = v i++ diff --git a/bake/hcl.go b/bake/hcl.go index 6f19390e..510d2e60 100644 --- a/bake/hcl.go +++ b/bake/hcl.go @@ -31,6 +31,7 @@ var ( "csvdecode": stdlib.CSVDecodeFunc, "coalesce": stdlib.CoalesceFunc, "coalescelist": stdlib.CoalesceListFunc, + "compact": stdlib.CompactFunc, "concat": stdlib.ConcatFunc, "contains": stdlib.ContainsFunc, "distinct": stdlib.DistinctFunc, From bfd1ea387722a0de6178085047596302c5535039 Mon Sep 17 00:00:00 2001 From: Anthony Poschen Date: Mon, 26 Oct 2020 16:37:28 +1100 Subject: [PATCH 2/3] Added doco for conditonal tags in bake file. Signed-off-by: Anthony Poschen --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index 5550fcfe..0f4de262 100644 --- a/README.md +++ b/README.md @@ -741,6 +741,43 @@ $ docker buildx bake --print webapp } ``` +Example of only adding tags if a variable is not empty using an `notequal` function: + +``` +$ cat <<'EOF' > docker-bake.hcl +variable "TAG" {default="" } + +group "default" { + targets = [ + "webapp", + ] +} + +target "webapp" { + context="." + dockerfile="Dockerfile" + tags = [ + "my-image:latest", + notequal("",TAG) ? "my-image:${TAG}": "", + ] +} +EOF + +$ docker buildx bake --print webapp +{ + "target": { + "webapp": { + "context": ".", + "dockerfile": "Dockerfile", + "tags": [ + "my-image:latest" + ] + } + } +} +``` + + ### `buildx imagetools create [OPTIONS] [SOURCE] [SOURCE...]` Imagetools contains commands for working with manifest lists in the registry. These commands are useful for inspecting multi-platform build results. From 5843e67a905c5c9c6a22f19f646fbe0b0db22997 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Mon, 7 Dec 2020 21:02:48 -0800 Subject: [PATCH 3/3] fix indentations in example Signed-off-by: Tonis Tiigi --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0f4de262..768c9d3e 100644 --- a/README.md +++ b/README.md @@ -749,17 +749,17 @@ variable "TAG" {default="" } group "default" { targets = [ - "webapp", - ] + "webapp", + ] } target "webapp" { - context="." - dockerfile="Dockerfile" - tags = [ - "my-image:latest", - notequal("",TAG) ? "my-image:${TAG}": "", - ] + context="." + dockerfile="Dockerfile" + tags = [ + "my-image:latest", + notequal("",TAG) ? "my-image:${TAG}": "", + ] } EOF