moby / moby/buildkit

gha: export cache to github even on build failure

Open
#4,262 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

kind/enhancement
Dominant language
Go
Stars
10.3k
Forks
1.5k
Avg merge
1d 23h
Merged PRs (30d)
48

Description

The experimental gha cache backend --cache-from: type=gha --cache-to: type=gha,mode=max works very well for me!
One use-case that I'd like it to have, is to trigger the cache upload even on failed builds.

I.e. I use the official docker/build-push-action@v5 github action.
I'm not sure what triggers the cache upload to gha but it only happens on successful builds. I'd love if there was an extra flag/setting to also trigger the upload on failure.

My current workaround is to manually manage the cache with type=local:


      - name: Restore Cached Docker Layers
        uses: actions/cache/restore@v3
        with:
          path: /tmp/.buildx-cache
          key: ${{env.base_tag}}-buildx-

      - name: Build and Push as Staging
        uses: docker/build-push-action@v5
        with:
          context: ./${{matrix.image}}
          push: true
          tags: ${{env.base_tag}}:staging
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

      - name: Move Docker Layers Cache
        if: always()
        run: |
          rm -rf /tmp/.buildx-cache
          mv /tmp/.buildx-cache-new /tmp/.buildx-cache

      - name: Save Docker Layers Cache
        uses: actions/cache/save@v3
        if: always()
        with:
          path: /tmp/.buildx-cache
          key: ${{env.base_tag}}-buildx-${{github.sha}}

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 tracing the experimental gha cache backend used by --cache-from: type=gha and --cache-to: type=gha,mode=max, then reproduce a failed build through docker/build-push-action@v5. Determine where cache upload is gated on build success. Done means an explicit setting causes the gha cache to upload usable layers after a failed build, without changing successful builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, github-actions, go
Domain
build-system, ci-cd, devops
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.