Cache is discarded in partial successful builds
Troubleshooting
Before submitting a bug report please read the Troubleshooting doc.
Behaviour
If a docker image is not successfully built as part of this step, and cache is being handled as in https://github.com/docker/build-push-action/issues/252#issuecomment-744400434, then the cache is discarded. This means that all partial success is thrown away, leading to tons of extra work for me. 😇
Steps to reproduce this issue
- Make a big Dockerfile.
- Set it up as in https://github.com/docker/build-push-action/issues/252#issuecomment-744400434
- Have it fail midway through.
Expected behaviour
The layers which worked should be saved for the future in the cache.
Actual behaviour
All layers associated with the Dockerfile is thrown away, even the good ones.
Configuration
See https://github.com/docker/build-push-action/issues/252#issuecomment-744400434
YES! Please fix this.
Some kind of workaround could be to let manually use restore/save of the cache action. But not sure how to combine this with cha cache-from / cache-to gha
Would this be possible? This was generated by ChatGPT:
- name: Build and Cache Step 1
run: docker build -t myimage:step1 --target=step1 --cache-from=type=gha .
- name: Push Docker Image Step 1
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: myimage:step1
cache-to: type=gha,mode=max,scope=l1
- name: Build and Cache Step 2
run: docker build -t myimage:step2 --target=step2 --cache-from=type=gha .
- name: Push Docker Image Step 2
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: myimage:step2
cache-to: type=gha,mode=max
Looks like a duplicate of https://github.com/docker/build-push-action/issues/252, let's continue the discussion there. Also you should consider switching to gha cache exporter: https://docs.docker.com/build/ci/github-actions/cache/#github-cache