docker / docker/buildx

Export build cache even if build fails

Open
#1,141 4 comments 58 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/cache
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.