Skip to content

bake: allow annotations to be set on the command line#2997

Merged
crazy-max merged 1 commit intodocker:masterfrom
jsternberg:bake-set-annotations
Feb 20, 2025
Merged

bake: allow annotations to be set on the command line#2997
crazy-max merged 1 commit intodocker:masterfrom
jsternberg:bake-set-annotations

Conversation

@jsternberg
Copy link
Copy Markdown
Collaborator

Annotations were not merged correctly. The overrides in ArrValue would be merged, but the section of code setting them from the command line did not include annotations in the list of available attributes so the command line option was completely discarded.

Fixes #2989.

Comment thread bake/bake.go
// docs/bake-reference.md 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":
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do the same for labels?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, I don't think labels has the same issue. It uses Value from the overrides:

buildx/bake/bake.go

Lines 891 to 898 in 52f503e

case "labels":
if len(keys) != 2 {
return errors.Errorf("invalid format for labels, expecting labels.<name>=<value>")
}
if t.Labels == nil {
t.Labels = map[string]*string{}
}
t.Labels[keys[1]] = &value

Compare to annotations:

buildx/bake/bake.go

Lines 973 to 974 in 52f503e

case "annotations":
t.Annotations = append(t.Annotations, o.ArrValue...)

So this might already work for labels? It looks like it's documented in there to work.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, this switch is a list of "use ArrValue to fill in the overrides" and the default is to use Value if you're not in the list.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes indeed, thanks

Comment thread bake/bake.go Outdated
Annotations were not merged correctly. The overrides in `ArrValue` would
be merged, but the section of code setting them from the command line
did not include `annotations` in the list of available attributes so the
command line option was completely discarded.

Signed-off-by: Jonathan A. Sternberg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bake: overriding annotations

3 participants