Skip to content

bake: normalize named context keys - #4090

Open
crazy-max wants to merge 1 commit into
docker:masterfrom
crazy-max:fix-bake-context-normalization
Open

crazy-max wants to merge 1 commit into
docker:masterfrom
crazy-max:fix-bake-context-normalization

Conversation

@crazy-max

Copy link
Copy Markdown
Member

fixes #2328

Bake now normalizes named context keys in the same way as docker buildx build --build-context and the Dockerfile frontend. Contexts such as library/golang and docker.io/library/golang therefore resolve correctly when referenced by FROM or COPY --from. Ambiguous keys that normalize to the same name produce a deterministic error instead of selecting an arbitrary value.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
@crazy-max
crazy-max force-pushed the fix-bake-context-normalization branch from e94c402 to adc30fa Compare September 17, 2026 15:22
@crazy-max crazy-max added this to the v0.38.0 milestone Sep 17, 2026
@crazy-max
crazy-max marked this pull request as ready for review September 17, 2026 15:26

@jsternberg jsternberg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Curious about this. Should we instead make it a warning or an error to use the non-normalized version? A big difference between this and the command line is that command lines are usually more ephemeral. It seems to me like we'd want the underlying HCL file to be consistent since it gets checked into the repository.

We could also error when the named contexts are in conflict and only warn when they differ from the canonical name.

@crazy-max

Copy link
Copy Markdown
Member Author

Curious about this. Should we instead make it a warning or an error to use the non-normalized version? A big difference between this and the command line is that command lines are usually more ephemeral. It seems to me like we'd want the underlying HCL file to be consistent since it gets checked into the repository.

We could also error when the named contexts are in conflict and only warn when they differ from the canonical name.

I considered making non-normalized names an error, but that would reject the exact configuration from #2328 and make Bake behave differently from --build-context. It would also require the Bake file to use golang while the Dockerfile says FROM library/golang, which doesn't seem more consistent from the user perspective.

BuildKit normalizes the Dockerfile reference before looking up the named context, so Bake needs to apply the same normalization when creating the frontend attributes. I kept non-conflicting aliases valid, but added an error when multiple keys normalize to the same name because that case is genuinely ambiguous.

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.

Unable to use library/* as build context and override it from bake files

2 participants