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.41k stars 561 forks source link

Backup cache-from if cache-from fails? #1243

Closed lightninglu10 closed 1 week ago

lightninglu10 commented 1 month ago

Description

Hey guys, we have a cache branching strategy where we tag images by the github branch. We set our cache-from like this:

ref=${{ env.REGISTRY }}:branch.${{ github.ref_name }}

For the first push of any branch, the image won't exist, but the main branch image will exist (which we typically branch from). So there will always be a cache miss even though the cache technically exists, just under a different branch name.

Is there anyway to have some kind of backup cache-from if it fails to exist, by setting a different value so it'll pull from main instead?

We used to have this behavior manually coded out in Travis, but swapped to Github Actions because it's better than Travis, but we're just missing this feature.

crazy-max commented 1 month ago

You can use multiple cache-from in this case:

cache-from: |
  type=registry,ref=${{ env.REGISTRY }}:branch.${{ github.ref_name }}
  type=registry,ref=${{ env.REGISTRY }}:main
lightninglu10 commented 1 month ago

Oh nice, didn't know that was possible. Thank you @crazy-max

crazy-max commented 1 week ago

More info: https://docs.docker.com/build/cache/backends/#multiple-caches