Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Guideline for leveraging GitHub Actions cache #196

Open
felipecrs opened this issue Mar 19, 2024 · 1 comment
Open

Guideline for leveraging GitHub Actions cache #196

felipecrs opened this issue Mar 19, 2024 · 1 comment

Comments

@felipecrs
Copy link
Contributor

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/

@nathanblair
Copy link

nathanblair commented Jul 30, 2024

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/#-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/#-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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants