docker / build-push-action

GitHub Action to build and push Docker images with Buildx
https://github.com/marketplace/actions/build-and-push-docker-images
Apache License 2.0
4.24k stars 541 forks source link

Cache not read #917

Closed ro0NL closed 1 year ago

ro0NL commented 1 year ago

Hi,

Im using the following job step for building a multistage dockerfile:

-
    uses: docker/build-push-action@v4
    with:
        context: .
        load: true
        target: app
        # https://docs.docker.com/build/ci/github-actions/cache/#github-cache
        cache-from: type=gha,scope=app
        cache-to: type=gha,mode=max,scope=app

After the first run 53 caches are written

After the second run 105 caches are written, and no existing cache is used.

Locally the build cache works fine.

Am i missing something?

crazy-max commented 1 year ago

Maybe GitHub Actions cache is full so old objects are GCed? Would need to see your full workflow, Dockerfile and logs to make sure. Link to your repo would be easier though.

ro0NL commented 1 year ago

@crazy-max i think i'm able to reproduce:

1st run without cache: https://github.com/ro0NL/test-docker-build/actions/runs/5724005099/job/15509630853 2nd run with 45 existing cache entries: https://github.com/ro0NL/test-docker-build/actions/runs/5724018658/job/15509671146

after the 2nd run there are 94 caches

initially i did saw CACHED docker steps

after using

'on':
    push:
        tags:
            - '*.*.*'

it seems to defacto ignore existing build cache, but keeps writing it

ro0NL commented 1 year ago

the same happens with local cache as per https://docs.docker.com/build/ci/github-actions/cache/#local-cache

i think it's because restore-keys doesnt load the cache by matching prefix from a previous tag

oh well, this took too much time already

crazy-max commented 1 year ago

after using

'on':
    push:
        tags:
            - '*.*.*'

it seems to defacto ignore existing build cache, but keeps writing it

Cache is scoped in GHA, you can find out looking at "GitHub Actions runtime token ACs":

1st run without cache: https://github.com/ro0NL/test-docker-build/actions/runs/5724005099/job/15509630853

image

2nd run with 45 existing cache entries: https://github.com/ro0NL/test-docker-build/actions/runs/5724018658/job/15509671146

image

As you can see you can read cache from main branch but not between tags.

ro0NL commented 1 year ago

IIUC it can only work if the main branch is build on each commit?