Skip to content

Commit

Permalink
Merge pull request #2997 from jsternberg/bake-set-annotations
Browse files Browse the repository at this point in the history
bake: allow annotations to be set on the command line
  • Loading branch information
crazy-max authored Feb 20, 2025
2 parents 18f4275 + d6fdf83 commit accfbf6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bake/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,9 @@ func (c Config) newOverrides(v []string) (map[string]map[string]Override, error)
o := t[kk[1]]

// IMPORTANT: if you add more fields here, do not forget to update
// docs/bake-reference.md and https://docs.docker.com/build/bake/overrides/
// docs/reference/buildx_bake.md (--set) and https://docs.docker.com/build/bake/overrides/
switch keys[1] {
case "output", "cache-to", "cache-from", "tags", "platform", "secrets", "ssh", "attest", "entitlements", "network":
case "output", "cache-to", "cache-from", "tags", "platform", "secrets", "ssh", "attest", "entitlements", "network", "annotations":
if len(parts) == 2 {
o.ArrValue = append(o.ArrValue, parts[1])
}
Expand Down
12 changes: 12 additions & 0 deletions bake/bake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ target "webapp" {
args = {
VAR_BOTH = "webapp"
}
annotations = [
"index,manifest:org.opencontainers.image.authors=dvdksn"
]
inherits = ["webDEP"]
}`),
}
Expand Down Expand Up @@ -115,6 +118,15 @@ target "webapp" {
})
})

t.Run("AnnotationsOverrides", func(t *testing.T) {
t.Parallel()
m, g, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.annotations=index,manifest:org.opencontainers.image.vendor=docker"}, nil, &EntitlementConf{})
require.NoError(t, err)
require.Equal(t, []string{"index,manifest:org.opencontainers.image.authors=dvdksn", "index,manifest:org.opencontainers.image.vendor=docker"}, m["webapp"].Annotations)
require.Equal(t, 1, len(g))
require.Equal(t, []string{"webapp"}, g["default"].Targets)
})

t.Run("ContextOverride", func(t *testing.T) {
t.Parallel()
_, _, err := ReadTargets(ctx, []File{fp}, []string{"webapp"}, []string{"webapp.context"}, nil, &EntitlementConf{})
Expand Down
1 change: 1 addition & 0 deletions docs/reference/buildx_bake.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ $ docker buildx bake --set foo*.no-cache # bypass caching only for

You can override the following fields:

* `annotations`
* `args`
* `cache-from`
* `cache-to`
Expand Down

0 comments on commit accfbf6

Please sign in to comment.