Guideline for leveraging GitHub Actions cache
Hi,
I believe it would be super helpful to provide some guidelines on how to implement gha caching while using this action.
Docker's documentation also doesn't mention anything about when using bake:
https://docs.docker.com/build/cache/backends/gha/
A pretty straightforward job like this
services:
name: Services
environment: non-prod
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Login to ACR
uses: docker/login-action@v3
with:
registry: ${{ vars.REGISTRY }}
username: ${{ vars.ARM_CLIENT_ID }}
password: ${{ secrets.ARM_CLIENT_SECRET }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: docker/bake-action@v5
env:
REGISTRY: ${{ vars.REGISTRY }}
with:
push: true
set: |
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
has not been successful in caching. It keeps creating Actions Caches and quickly fills up the Actions Cache size.
Edit
Was able to get more reproducible behavior. Not 100% cache hit - though I think that may be a fault of either my Dockerfile targets, how they're reference in the bake file, or the base images being used themselves.
Nonetheless, I bake a couple targets simultaneously and so changing the scope solved 97% of my problems:
services:
name: Services
environment: non-prod
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Login to ACR
uses: docker/login-action@v3
with:
registry: ${{ vars.REGISTRY }}
username: ${{ vars.ARM_CLIENT_ID }}
password: ${{ secrets.ARM_CLIENT_SECRET }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: docker/bake-action@v5
env:
REGISTRY: ${{ vars.REGISTRY }}
with:
push: true
set: |
auth.cache-from=type=gha,scope=auth
auth.cache-to=type=gha,mode=max,scope=auth
api.cache-from=type=gha,scope=api
api.cache-to=type=gha,mode=max,scope=api
There's not much documentation on the scope in this Action and I hadn't even known about it until I did a deep dive in the docker build documentation. Given that, not even 100% sure this would be the intended way to handle my use case.
Is there some clue on how to fix the example in:
https://docs.docker.com/build/ci/github-actions/multi-platform/#with-bake
To have the annotation like ghcr.io expects?