build-push-action icon indicating copy to clipboard operation
build-push-action copied to clipboard

Cache is discarded in partial successful builds

Open peredwardsson opened this issue 2 years ago • 2 comments

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

  1. Make a big Dockerfile.
  2. Set it up as in https://github.com/docker/build-push-action/issues/252#issuecomment-744400434
  3. 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

peredwardsson avatar Jan 11 '23 12:01 peredwardsson

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

MichaelVoelkel avatar Jan 29 '23 17:01 MichaelVoelkel

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

DiegoRBaquero avatar Jan 16 '24 17:01 DiegoRBaquero

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

crazy-max avatar Mar 08 '24 14:03 crazy-max