From 9a9dd4e87e456903770618f18cd3e8e9940329db Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Sun, 15 Dec 2024 23:15:16 -0800 Subject: [PATCH 1/2] [v0.19] bake: remove empty values set by --set These parser functions are called for `--set` to resolve entitlement paths that would be automatically added and will fail for empty value. The empty values would already be ignored but in v0.19 is done after merging the `--set` values and then calling parse again. Signed-off-by: Tonis Tiigi --- util/buildflags/cache.go | 3 +++ util/buildflags/export.go | 3 +++ util/buildflags/secrets.go | 3 +++ util/buildflags/ssh.go | 3 +++ 4 files changed, 12 insertions(+) diff --git a/util/buildflags/cache.go b/util/buildflags/cache.go index 7e0971b2..604324be 100644 --- a/util/buildflags/cache.go +++ b/util/buildflags/cache.go @@ -14,6 +14,9 @@ import ( func ParseCacheEntry(in []string) ([]*controllerapi.CacheOptionsEntry, error) { outs := make([]*controllerapi.CacheOptionsEntry, 0, len(in)) for _, in := range in { + if in == "" { + continue + } fields, err := csvvalue.Fields(in, nil) if err != nil { return nil, err diff --git a/util/buildflags/export.go b/util/buildflags/export.go index 60c561f4..c9d5cdcd 100644 --- a/util/buildflags/export.go +++ b/util/buildflags/export.go @@ -19,6 +19,9 @@ func ParseExports(inp []string) ([]*controllerapi.ExportEntry, error) { return nil, nil } for _, s := range inp { + if s == "" { + continue + } fields, err := csvvalue.Fields(s, nil) if err != nil { return nil, err diff --git a/util/buildflags/secrets.go b/util/buildflags/secrets.go index 2e442297..cc735dba 100644 --- a/util/buildflags/secrets.go +++ b/util/buildflags/secrets.go @@ -11,6 +11,9 @@ import ( func ParseSecretSpecs(sl []string) ([]*controllerapi.Secret, error) { fs := make([]*controllerapi.Secret, 0, len(sl)) for _, v := range sl { + if v == "" { + continue + } s, err := parseSecret(v) if err != nil { return nil, err diff --git a/util/buildflags/ssh.go b/util/buildflags/ssh.go index 10686f05..747222ed 100644 --- a/util/buildflags/ssh.go +++ b/util/buildflags/ssh.go @@ -14,6 +14,9 @@ func ParseSSHSpecs(sl []string) ([]*controllerapi.SSH, error) { } for _, s := range sl { + if s == "" { + continue + } parts := strings.SplitN(s, "=", 2) out := controllerapi.SSH{ ID: parts[0], From afc9cebb4861d02086e8f4d043256cfcebf1d3a9 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:35:14 +0100 Subject: [PATCH 2/2] bake: test empty override Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- bake/bake_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bake/bake_test.go b/bake/bake_test.go index d589b447..d2448203 100644 --- a/bake/bake_test.go +++ b/bake/bake_test.go @@ -2028,3 +2028,20 @@ target "app" { _, _, err := ReadTargets(ctx, []File{fp}, []string{"app"}, nil, nil, &EntitlementConf{}) require.NoError(t, err) } + +// https://github.com/docker/buildx/issues/2858 +func TestOverrideEmpty(t *testing.T) { + fp := File{ + Name: "docker-bake.hcl", + Data: []byte(` +target "app" { + output = ["./bin"] +} +`), + } + + ctx := context.TODO() + + _, _, err := ReadTargets(ctx, []File{fp}, []string{"app"}, []string{"app.output="}, nil, &EntitlementConf{}) + require.NoError(t, err) +}