Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cache not working #245

Open
3 tasks done
FezVrasta opened this issue Sep 1, 2024 · 7 comments
Open
3 tasks done

Cache not working #245

FezVrasta opened this issue Sep 1, 2024 · 7 comments

Comments

@FezVrasta
Copy link

Contributing guidelines

I've found a bug, and:

  • The documentation does not mention anything about my problem
  • There are no open or closed issues that are related to my problem

Description

I'm trying to use this action to build a multi stage image using a docker compose configuration file. The build is working correctly and the images are pushed to the Google Artifacts registry just fine, but subsequent builds are not taking advantage of the layers cache even though nothing in the repository changed at all.

Screenshot 2024-09-01 at 19 07 08

Expected behaviour

I would expect this to be way higher than 0%

Actual behaviour

Cache seem not to be used at all?

Repository URL

No response

Workflow run URL

No response

YAML workflow

# Setup gcloud CLI
      - uses: "google-github-actions/setup-gcloud@v2"
        if: ${{ env.dryRun == 'false' }}
        with:
          project_id: ${{ env.GCP_PROJECT_ID }}
          version: "482.0.0"

      # This gives us access to buildx
      - name: Set up Docker CLI
        uses: docker/setup-buildx-action@v3

      # Configure Docker to use the gcloud command-line tool as a credential
      # helper for authentication
      - if: ${{ env.dryRun == 'false' }}
        run: |-
          gcloud --quiet auth configure-docker

      # Get the GKE credentials so we can deploy to the cluster
      - uses: google-github-actions/get-gke-credentials@db150f2cc60d1716e61922b832eae71d2a45938f
        if: ${{ env.dryRun == 'false' }}
        with:
          cluster_name: ${{ env.GKE_CLUSTER }}
          location: ${{ env.GCP_LOCATION }}

      - name: Build and Push Docker Images
        uses: docker/bake-action@v5
        env:
          TAG: ${{ steps.release-tag.outputs.tag }}
        with:
          source: "."
          files: "compose.yaml"
          workdir: "./docker"
          push: ${{ env.dryRun == 'false' }}
          load: true

Workflow logs

No response

BuildKit logs

No response

Additional info

No response

@crazy-max
Copy link
Member

but subsequent builds are not taking advantage of the layers cache even though nothing in the repository changed at all.

I don't see any use of cache exporters in your workflow. You can use the gha exporter for example:

      - name: Build and Push Docker Images
        uses: docker/bake-action@v5
        env:
          TAG: ${{ steps.release-tag.outputs.tag }}
        with:
          source: "."
          files: "compose.yaml"
          workdir: "./docker"
          push: ${{ env.dryRun == 'false' }}
          load: true
          set:
            *.cache-from=type=gha
            *.cache-to=type=gha,mode=max

More info: https://docs.docker.com/build/ci/github-actions/cache/

@FezVrasta
Copy link
Author

FezVrasta commented Sep 2, 2024

Thanks, that helped, but still I see only ~60% caching on runs where nothing in the repository changed at all 🤔
Screenshot 2024-09-02 at 13 21 16

@crazy-max
Copy link
Member

Would need to look at your Dockerfile and build logs to figure out if this related to context changes (maybe .git folder).

Can you share your .dockerbuild file from the summary?

@FezVrasta
Copy link
Author

FezVrasta commented Sep 2, 2024

Thanks for the help, this is my Dockerfile and this the .dockerbuild:
dockerbuild.zip

Personally I don't see anything that could result in cache invalidation.

Edit: I even tried to just re-run the same build and I obtained the same results.

@crazy-max
Copy link
Member

Seems cache is busted at COPY --parents instruction:

image

Wonder if this is a bug with new --parents flag 🤔

Can you try without --parents if possible?

Can you also change this step:

      # This gives us access to buildx
      - name: Set up Docker CLI
        uses: docker/setup-buildx-action@v3

to

      # This gives us access to buildx
      - name: Set up Docker CLI
        uses: docker/setup-buildx-action@v3
        with:
          buildkitd-flags: --debug

And post the BuildKit logs from post step: https://docs.docker.com/build/ci/github-actions/configure-builder/#buildkit-container-logs

@FezVrasta
Copy link
Author

Thanks, I removed the --parents and replaced it with several COPY commands one for each file.

This is the buildkit log:
https://gist.github.com/FezVrasta/6d0c2024eb1bbfcbd4c37112136ea58d

This the dockerbuild:
dockerbuild2.zip

I still see low cache percentage.

@ericonr
Copy link

ericonr commented Oct 4, 2024

Hi!

We are observing issues with the cache as well. For identical contents, sometimes the build simply doesn't use the cache.

These two builds:

differ by cnpem/epics-in-docker@635b6d0, and that Dockerfile is not copied into the build at any point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants