reproducible-containers / buildkit-cache-dance

Save `RUN --mount=type=cache` caches on GitHub Actions ( Forked from https://github.com/overmindtech/buildkit-cache-dance )
Apache License 2.0
98 stars 25 forks source link

Err: cleaning cache source directory: Error: EACCES: permission denied #31

Open Desdemo opened 2 months ago

Desdemo commented 2 months ago

dockerfile

RUN --mount=type=cache,target=/root/.cache/go-build,sharing=locked,id=go-build-cache \
    --mount=type=cache,target=/go/pkg/mod,sharing=locked,id=go-pkg-mod \
     go mod download

COPY . .

RUN --mount=type=cache,target=/root/.cache/go-build \
    --mount=type=cache,target=/go/pkg/mod \
    go build -ldflags="-s -w" -o business main.go

git.yml

      - name: Go Build Cache for Docker
        uses: actions/cache@v4
        with:
          path: |
            go-build-cache
            go-pkg-mod
          key: go-cache-multiarch-${{ hashFiles('go.mod') }}
          restore-keys: |
            go-cache-multiarch-

      - name: inject go-build-cache into docker
          # v1 was composed of two actions: "inject" and "extract".
        # v2 is unified to a single action.
        uses: reproducible-containers/buildkit-cache-dance@v3.1.0
        with:
          cache-map: |
            {
              "go-build-cache": {
                "target": "/root/.cache/go-build",
                "id": "go-build-cache"
              },
              "go-pkg-mod": {
                  "target": "/go/pkg/mod",
                  "id": "go-pkg-mod"
                }
            }
          skip-extraction: true

the log image

Error while cleaning cache source directory: Error: EACCES: permission denied, unlink 'go-build-cache/go.opencensus.io@v0.22.5/.gitignore'. Ignoring...

And it takes about the same amount of time to build as it would if we didn't use the cache.

But, my local cache builds very quickly.

noamcattan commented 1 month ago

Same here!

Dockerfile:

ARG go_mod_cache
ARG go_build_cache
ENV GOMODCACHE=$go_mod_cache
ENV GOCACHE=$go_build_cache
RUN --mount=type=cache,target=${GOMODCACHE} \
    --mount=type=bind,source=go.sum,target=go.sum \
    --mount=type=bind,source=go.mod,target=go.mod \
    go mod download
COPY ./ .
RUN --mount=type=cache,target=${GOMODCACHE} \
    --mount=type=cache,target=${GOCACHE} \
    go build -gcflags="all=-N -l" -tags ent -o /bin/server /src/${service}/cmd/${service}

Worflow file:

      - name: Go Mod Cache
        id: go-mod-cache
        uses: actions/cache@v4
        with:
          path: go-mod-cache
          key: go-mod-cache-${{ hashFiles('go.sum') }}
          restore-keys: |
            go-mod-cache
      - name: Go Build Cache
        id: go-build-cache
        uses: actions/cache@v4
        with:
          path: go-build-cache
          key: go-build-cache-${{ matrix.service }}-${{ hashFiles(format('{0}/**', matrix.service)) }}
          restore-keys: |
            go-build-cache-${{ matrix.service }}
      - name: inject go-build-cache into docker
        uses: reproducible-containers/buildkit-cache-dance@v3.1.0
        with:
          cache-map: |
            {
              "go-mod-cache": "/github/home/go-mod-cache",
              "go-build-cache": "/github/home/go-build-cache"
            }
          skip-extraction: ${{ steps.go-mod-cache.outputs.cache-hit && steps.go-build-cache.outputs.cache-hit }}
      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: ${{ matrix.context }}
          push: true
          file: ${{ matrix.file }}
          target: ${{ matrix.target }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
          build-args: |
            service=${{ matrix.service }}
            CACHEBUST=${{ github.sha }}
            go_mod_cache=/github/home/go-mod-cache
            go_build_cache=/github/home/go-build-cache

And:

image

janvavro commented 3 weeks ago

Any update here? I am hitting the same issues @noamcattan described above (with very similar setup) quite often. Rerun usually help, but it is annoying.