Export build cache even if build fails
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 4.5k
- Forks
- 682
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 29
Description
Hello,
I would like to propose as a feature that even if a build fails, Buildx should still export caches specified with --cache-to.
Rationale
We have a few lengthy build steps in our project (which are run in CI) that can usually be reused from cache, but if you have to change something that re-triggers some of those steps and you get it wrong such that any but the first step fail, you're back to waiting for those previously successful steps because they are not cached.
It is my understanding, through observed behavior, that Buildx will only export caches at the end of a successful build. Having an option to make it export the cache for successful layers even if the overall build failed would allow us to reuse lengthy build steps that succeeded in a failed build.
There is a workaround by dividing lengthy build steps into individual stages and then running these stages in order, each of them caching to and from the same location. But this becomes increasingly difficult to manage as the build complexity increases, with each lengthy build step not only requiring its own Docker layer but also its own job/invocation.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported behavior with a Buildx build that has lengthy steps, fails after some successful steps, and uses --cache-to. Compare the exported cache after a successful build and a failed build, then define done as preserving reusable successful layers when the overall build fails without changing the existing successful-build behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100