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

GHA export fails with "Cache already exists" #2325

Closed
lucacome opened this issue Aug 21, 2021 · 6 comments · Fixed by #2387
Closed

GHA export fails with "Cache already exists" #2325

lucacome opened this issue Aug 21, 2021 · 6 comments · Fixed by #2387

Comments

@lucacome
Copy link

The workflow is using the following in a matrix (not sure if it's relevant)

  cache-from: type=gha
  cache-to: type=gha,mode=max

and sometimes I get this

#17 ERROR: error writing layer blob: Cache already exists. Scope: refs/pull/1892/merge, Key: buildkit-blob-1-sha256:74328d539a236952c80a22e6e6e7c52d4fed86fb10a7d0b317c8fbb42d5c36fa, Version: 693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2
------
 > exporting cache:
------
error: failed to solve: error writing layer blob: Cache already exists. Scope: refs/pull/1892/merge, Key: buildkit-blob-1-sha256:74328d539a236952c80a22e6e6e7c52d4fed86fb10a7d0b317c8fbb42d5c36fa, Version: 693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2
Error: buildx failed with: error: failed to solve: error writing layer blob: Cache already exists. Scope: refs/pull/1892/merge, Key: buildkit-blob-1-sha256:74328d539a236952c80a22e6e6e7c52d4fed86fb10a7d0b317c8fbb42d5c36fa, Version: 693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2

I tried searching for the sha in the other builds in the matrix, but couldn't find it, I'm assuming it's from a previous run?

@crazy-max
Copy link
Member

@lucacome

in a matrix (not sure if it's relevant)

Could be relevant but can't tell without repro. Would suggest to define scope for each matrix:

  cache-from: type=gha,scope=${{ matrix.name }}-cache
  cache-to: type=gha,scope=${{ matrix.name }}-cache,mode=max

@lucacome
Copy link
Author

@crazy-max thanks for the response. We had to disable caching for now since all the builds were failing, but could you provide more info on what the scope does? I couldn't find much in the docs.

Should I have a different scope for every image that I build? Like if one of the images in the matrix is built in a previous step too, do I need the same scope for caching to work?

@crazy-max
Copy link
Member

@lucacome

I couldn't find much in the docs.

https://github.com/moby/buildkit#github-actions-cache-experimental

Should I have a different scope for every image that I build? Like if one of the images in the matrix is built in a previous step too, do I need the same scope for caching to work?

If you talk about this workflow, scope is pretty much the same as defining a specific folder for the local cache destination like you do atm with actions/cache. So you have to define a scope per image:

  release-docker:
    name: Release Images
    runs-on: ubuntu-20.04
    needs: [binary]
    strategy:
      matrix:
        include:
          - scope: nginx-ingress
            tags: |
              nginx/nginx-ingress:${{ needs.binary.outputs.version }}
              nginx/nginx-ingress:latest
            type: debian
            platforms: linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x
          - scope: nginx-ingress-alpine
            tags: |
              nginx/nginx-ingress:${{ needs.binary.outputs.version }}-alpine
              nginx/nginx-ingress:alpine
            type: alpine
            platforms: linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x
          - scope: nginx-ingress-ubi
            tags: |
              nginx/nginx-ingress:${{ needs.binary.outputs.version }}-ubi
              nginx/nginx-ingress:ubi
            type: ubi
            platforms: linux/arm64,linux/amd64
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v2
      ...
      - name: Push to Dockerhub
        uses: docker/build-push-action@v2
        with:
          file: build/Dockerfile
          context: '.'
          cache-from: type=gha,scope=${{ matrix.scope }}
          cache-to: type=gha,scope=${{ matrix.scope }},mode=max
          target: goreleaser
          tags: ${{ matrix.tags }}
          platforms: ${{ matrix.platforms }}
          push: true
          build-args: |
            BUILD_OS=${{ matrix.type }}
            IC_VERSION=${GITHUB_REF#refs/tags/}
            NGINX_VERSION=${{ steps.commit.outputs.nginx_version }}
            DATE=${{ steps.commit.outputs.date }}
            GIT_COMMIT=${{ github.sha }}

@vterdunov
Copy link

vterdunov commented Aug 25, 2021

Similar problem. It's build without matrix. Scope already used.

BuildKit version
  moby/buildkit:buildx-stable-1 => buildkitd github.com/moby/buildkit v0.9.0 c8bb937807d405d92be91f06ce2629e6202ac7a9
env:
  SERVICE_NAME: web

...

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1

...

      - name: Build image
        uses: docker/build-push-action@v2
        id: docker_build
        with:
          context: web
          builder: ${{ steps.buildx.outputs.name }}
          file: ./web/Dockerfile
          push: true
          tags: ${{ steps.docker_meta.outputs.tags }}
          labels: ${{ steps.docker_meta.outputs.labels }}
          cache-from: type=gha,scope=${{ env.SERVICE_NAME }}
          cache-to: type=gha,scope=${{ env.SERVICE_NAME }},mode=max

The error is:

#34 writing layer sha256:1e987daa2432270bbfaf366f57583c93b48e0ee6c9fe54fe7f4030b84095627f 0.0s done
#34 ERROR: error writing layer blob: Cache already exists. Scope: refs/heads/master, Key: buildkit-blob-1-sha256:1e987daa2432270bbfaf366f57583c93b48e0ee6c9fe54fe7f4030b84095627f, Version: 693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2
------
 > exporting cache:
------
error: failed to solve: error writing layer blob: Cache already exists. Scope: refs/heads/master, Key: buildkit-blob-1-sha256:1e987daa2432270bbfaf366f57583c93b48e0ee6c9fe54fe7f4030b84095627f, Version: 693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2
Error: buildx failed with: error: failed to solve: error writing layer blob: Cache already exists. Scope: refs/heads/master, Key: buildkit-blob-1-sha256:1e987daa2432270bbfaf366f57583c93b48e0ee6c9fe54fe7f4030b84095627f, Version: 693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2

I noticed Scope: refs/heads/master, i believed it should be web
At the same time other services builds without problems.

@lucacome
Copy link
Author

I tried adding the scope but I still get

error: failed to solve: error writing layer blob: Cache already exists. Scope: refs/pull/1913/merge, Key: buildkit-blob-1-sha256:e1acddbe380c63f0de4b77d3f287b7c81cd9d89563a230692378126b46ea6546, Version: 693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2

Seems like the scope is not used?

@jnordberg
Copy link

Have the same issue, scope is set but does not seem to be used:

      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: .
          push: ${{ github.event_name != 'pull_request' }}
          build-args: ${{ matrix.config.args }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha,scope=${{ matrix.config.name }}
          cache-to: type=gha,mode=max,scope=${{ matrix.config.name }}
Error: buildx failed with: error: failed to solve: error writing layer blob: Cache already exists. Scope: refs/tags/v1.0.0-test-ff3, Key: buildkit-blob-1-sha256:705bb4cb554eb7751fd21a994f6f32aee582fbe5ea43037db6c43d321763992b, Version: 693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2

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

Successfully merging a pull request may close this issue.

4 participants