docker / docker/buildx

Bake should not allow multiple cache outputs of the same name

Open
#3,819 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area/bake kind/enhancement
Dominant language
Go
Stars
4.5k
Forks
682
Avg merge
2d 14h
Merged PRs (30d)
29

Description

Description

Currently, bake allows for multiple targets to output to the same cache target. When you do so, the result is non-deterministic and mostly results in your build never caching properly, and it being a total mystery why. I've done this two different ways:

  1. By accident, having a somewhat complex bake file/Dockerfile, and not noticing I did a bad copy paste on a cache name
  2. In a Multiplatform build (see https://github.com/docker/buildx/discussions/1382) This one might already be fixed, or may only be an issue with GHA output, I'm still debugging some cache busting issues. If it's supposed to be fixed, adding validation that we never output cache targets of the same name would be neat.

I'd also say that probably one shouldn't be allowed to name two regular output targets of the same name in the same build, but I haven't actually tried to see if bake lets you.

Is there an actual use case for this? Otherwise it seems like a footgun, and should error. If there's a desire not to break existing "working" bakefiles, could go with a warning for some number of releases, first.

I've been working a lot with various docker internals for my work on clipper.dev, happy to put up a PR to fix this if it would be accepted.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the duplicate cache-output case with a bake file and inspect the bake validation path; the issue does not name a file or test. Determine how duplicate cache and regular output names are handled, then add validation and coverage showing the intended error or warning behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
build-system, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.