-
Notifications
You must be signed in to change notification settings - Fork 545
bake: support += operator to append with overrides #3031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -37,6 +37,15 @@ target "webapp" { | |||
annotations = [ | ||||
"index,manifest:org.opencontainers.image.authors=dvdksn" | ||||
] | ||||
attest = [ | ||||
"type=provenance,mode=max" | ||||
] | ||||
platforms = [ | ||||
"linux/amd64" | ||||
] | ||||
secret = [ | ||||
"id=FOO,env=FOO" | ||||
] | ||||
inherits = ["webDEP"] | ||||
}`), | ||||
} | ||||
|
@@ -127,6 +136,22 @@ target "webapp" { | |||
require.Equal(t, []string{"webapp"}, g["default"].Targets) | ||||
}) | ||||
|
||||
t.Run("AttestOverride", func(t *testing.T) { | ||||
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.attest=type=sbom"}, nil, &EntitlementConf{}) | ||||
require.NoError(t, err) | ||||
require.Len(t, m["webapp"].Attest, 2) | ||||
require.Equal(t, "provenance", m["webapp"].Attest[0].Type) | ||||
require.Equal(t, "sbom", m["webapp"].Attest[1].Type) | ||||
}) | ||||
|
||||
t.Run("AttestAppend", func(t *testing.T) { | ||||
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.attest+=type=sbom"}, nil, &EntitlementConf{}) | ||||
require.NoError(t, err) | ||||
require.Len(t, m["webapp"].Attest, 2) | ||||
require.Equal(t, "provenance", m["webapp"].Attest[0].Type) | ||||
require.Equal(t, "sbom", m["webapp"].Attest[1].Type) | ||||
}) | ||||
|
||||
t.Run("ContextOverride", func(t *testing.T) { | ||||
t.Parallel() | ||||
_, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.context"}, nil, &EntitlementConf{}) | ||||
|
@@ -148,6 +173,49 @@ target "webapp" { | |||
require.Equal(t, []string{"webapp"}, g["default"].Targets) | ||||
}) | ||||
|
||||
t.Run("PlatformOverride", func(t *testing.T) { | ||||
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.platform=linux/arm64"}, nil, &EntitlementConf{}) | ||||
require.NoError(t, err) | ||||
require.Equal(t, []string{"linux/arm64"}, m["webapp"].Platforms) | ||||
}) | ||||
|
||||
t.Run("PlatformAppend", func(t *testing.T) { | ||||
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.platform+=linux/arm64"}, nil, &EntitlementConf{}) | ||||
require.NoError(t, err) | ||||
require.Equal(t, []string{"linux/amd64", "linux/arm64"}, m["webapp"].Platforms) | ||||
}) | ||||
|
||||
t.Run("PlatformAppendMulti", func(t *testing.T) { | ||||
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.platform+=linux/arm64", "webapp.platform+=linux/riscv64"}, nil, &EntitlementConf{}) | ||||
require.NoError(t, err) | ||||
require.Equal(t, []string{"linux/amd64", "linux/arm64", "linux/riscv64"}, m["webapp"].Platforms) | ||||
}) | ||||
|
||||
t.Run("PlatformAppendMultiLastOverride", func(t *testing.T) { | ||||
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.platform+=linux/arm64", "webapp.platform=linux/riscv64"}, nil, &EntitlementConf{}) | ||||
require.NoError(t, err) | ||||
require.Equal(t, []string{"linux/arm64", "linux/riscv64"}, m["webapp"].Platforms) | ||||
}) | ||||
|
||||
t.Run("SecretsOverride", func(t *testing.T) { | ||||
t.Setenv("FOO", "foo") | ||||
t.Setenv("BAR", "bar") | ||||
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.secrets=id=BAR,env=BAR"}, nil, &EntitlementConf{}) | ||||
require.NoError(t, err) | ||||
require.Len(t, m["webapp"].Secrets, 1) | ||||
require.Equal(t, "BAR", m["webapp"].Secrets[0].ID) | ||||
}) | ||||
|
||||
t.Run("SecretsAppend", func(t *testing.T) { | ||||
t.Setenv("FOO", "foo") | ||||
t.Setenv("BAR", "bar") | ||||
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.secrets+=id=BAR,env=BAR"}, nil, &EntitlementConf{}) | ||||
require.NoError(t, err) | ||||
require.Len(t, m["webapp"].Secrets, 2) | ||||
require.Equal(t, "FOO", m["webapp"].Secrets[0].ID) | ||||
require.Equal(t, "BAR", m["webapp"].Secrets[1].ID) | ||||
}) | ||||
Comment on lines
+209
to
+217
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for this PR but if we append a secret with the same ID it doesn't seem to override the existing one from the bake definition but append instead: target "default" {
secret = [
"id=FOO,env=FOO"
]
}
Building with this Dockerfile: FROM busybox
RUN --mount=type=secret,id=FOO cat /run/secrets/FOO We have:
Which is ok as it takes the last one defined but we should dedup early. @jsternberg Maybe having a custom dedup logic for secrets in buildx/util/buildflags/secrets.go Line 30 in 4ed1e07
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened #3032 |
||||
|
||||
t.Run("ShmSizeOverride", func(t *testing.T) { | ||||
m, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.shm-size=256m"}, nil, &EntitlementConf{}) | ||||
require.NoError(t, err) | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case is edgy and don't think current implementation is right. If last override does not append then it should only take this value and not append with previous one:
Should be instead:
Maybe that's fine for this PR to start with but I think we should refactor the override logic for such case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there ever a case where
=
and+=
for same override key make sense? It would not be append anyway. Even if you follow the order of arguments, then one way it is a replace, and the other way some overrides get ignored.