Skip to content

Commit 3848523

Browse files
bake: accept "platforms" as alias for "platform" in --set overrides
Normalizes the plural form to match the HCL attribute name, so --set 'target.platforms=...' works alongside the existing singular form. Signed-off-by: Shaun Thompson <30006198+thompson-shaun@users.noreply.github.com>
1 parent ce05817 commit 3848523

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

bake/bake.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,11 @@ func (c Config) newOverrides(v []string) (map[string]map[string]Override, error)
588588
return nil, err
589589
}
590590

591+
// Normalize plural alias so both "platform" and "platforms" are accepted.
592+
if keys[1] == "platforms" {
593+
keys[1] = "platform"
594+
}
595+
591596
okey := strings.Join(keys[1:], ".")
592597
for _, name := range names {
593598
t, ok := m[name]

bake/bake_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,25 @@ target "webapp" {
201201
require.Equal(t, []string{"linux/arm64", "linux/riscv64"}, m["webapp"].Platforms)
202202
})
203203

204+
t.Run("PlatformsOverride", func(t *testing.T) {
205+
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.platforms=linux/arm64"}, nil, nil, &EntitlementConf{})
206+
require.NoError(t, err)
207+
require.Equal(t, []string{"linux/arm64"}, m["webapp"].Platforms)
208+
})
209+
210+
t.Run("PlatformsAppend", func(t *testing.T) {
211+
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.platforms+=linux/arm64"}, nil, nil, &EntitlementConf{})
212+
require.NoError(t, err)
213+
require.Equal(t, []string{"linux/amd64", "linux/arm64"}, m["webapp"].Platforms)
214+
})
215+
216+
t.Run("PlatformsMixedForms", func(t *testing.T) {
217+
// Both singular and plural forms should map to the same field and accumulate identically.
218+
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.platform=linux/arm64", "webapp.platforms=linux/riscv64"}, nil, nil, &EntitlementConf{})
219+
require.NoError(t, err)
220+
require.Equal(t, []string{"linux/arm64", "linux/riscv64"}, m["webapp"].Platforms)
221+
})
222+
204223
t.Run("SecretsOverride", func(t *testing.T) {
205224
t.Setenv("FOO", "foo")
206225
t.Setenv("BAR", "bar")

docs/reference/buildx_bake.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ You can override the following fields:
455455
* `no-cache`
456456
* `no-cache-filter`
457457
* `output`
458-
* `platform`
458+
* `platform` (also accepted as `platforms`)
459459
* `pull`
460460
* `push`
461461
* `secrets`
@@ -472,7 +472,7 @@ You can append using `+=` operator for the following fields:
472472
* `entitlements`¹
473473
* `no-cache-filter`
474474
* `output`
475-
* `platform`
475+
* `platform` (also accepted as `platforms`)
476476
* `secrets`
477477
* `ssh`
478478
* `tags`

0 commit comments

Comments
 (0)