falcondev-oss / github-actions-cache-server

Self-hosted GitHub Actions cache server implementation. Compatible with official 'actions/cache' action
https://gha-cache-server.falcondev.io
MIT License
84 stars 4 forks source link

Unable to save cache using buildx #49

Open Ebaneck opened 1 week ago

Ebaneck commented 1 week ago

Current setup:

  - name: Checkout repository
    uses: actions/checkout@v4
  - name: Set up QEMU
    uses: docker/setup-qemu-action@v3
  - name: Set up Docker Buildx
    uses: docker/setup-buildx-action@v3
    with:
      buildkitd-flags: --debug

  - name: Build and push
    uses: docker/build-push-action@v5
    with:
      context: .
      push: false
      tags: |
        tag1
        tag2
      cache-from: type=gha
      cache-to: type=gha,mode=max
      #file: Dockerfile
      provenance: false
      sbom: false

Cache server logs:

[cache-server] ℹ Using database driver: mysql
[cache-server] ℹ Migrating database...
[cache-server] ✔ Database migrated
[cache-server] ℹ Using storage driver: s3
[cache-server] ℹ Cleaning up cache entries older than 90d with schedule 0 0 * * * (next run: 7/2/2024, 12:00:00 AM)
Listening on http://[::]:3000

[cache-server]  ERROR  Response: GET /<secret_token>/_apis/artifactcache/caches > 405
 Method get is not allowed on this route.

  at createError$1 (server/chunks/runtime.mjs:1885:15)
  at matchHandler (server/chunks/runtime.mjs:3025:16)
  at Object.handler (server/chunks/runtime.mjs:3036:19)
  at Object.handler (server/chunks/runtime.mjs:2816:31)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async Server.toNodeHandle (server/chunks/runtime.mjs:3082:7)

Actions logs:

  time="2024-07-01T12:52:56Z" level=debug msg="load cache http://github-actions-cache:3000/<toto-token>/_apis/artifactcache/cache?keys=buildkit-blob-1-sha256%3A094f5bbe54aeb3d2d501d9249a5cdce3ba496a476093d15a401438306f60ca85&version=693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2"
  time="2024-07-01T12:52:56Z" level=debug msg="save cache req http://github-actions-cache:3000/<toto-token>/_apis/artifactcache/caches body={\"key\":\"buildkit-blob-1-sha256:094f5bbe54aeb3d2d501d9249a5cdce3ba496a476093d15a401438306f60ca85\",\"version\":\"693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2\"}"
  time="2024-07-01T12:52:56Z" level=error msg="/moby.buildkit.v1.Control/Solve returned error: rpc error: code = Unknown desc = error writing layer blob: Method get is not allowed on this route."
  error writing layer blob: Method get is not allowed on this route.
LouisHaftmann commented 1 week ago

Does it work with the default cache server?

Ebaneck commented 1 week ago

Does it work with the default cache server?

Hello @LouisHaftmann Yes, I can confirm it works.

LouisHaftmann commented 1 week ago

The docker builder in your workflow for some reason does a GET request instead of POST. Looking at the source code of https://github.com/moby/buildkit, I noticed that it actually does a POST request (https://github.com/moby/buildkit/blob/f7bda278b7e2d1de3d8e3f69c51f967fccf6f55b/vendor/github.com/tonistiigi/go-actions-cache/cache.go#L244). So this either is a bug in our http method matching or the docker/build-push-action action is not using the default moby/buildkit.

For now you could try updating docker/build-push-action. Maybe that fixes the problem.

Ebaneck commented 1 week ago

I tried both v3, v4 and v6 of docker/build-push-action and still no luck.

Seems related: https://github.com/moby/buildkit/issues/4961

A bit more logs if this helps:

  time="2024-07-03T10:08:39Z" level=debug msg="load cache http://cache-server:3000/<random-token>/_apis/artifactcache/cache?keys=buildkit-blob-1-sha256%3A0d4c623e273569ef3d9b7f89142096b564f2557d3e909413fa233bbe23f3aeca&version=693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2"
  time="2024-07-03T10:08:39Z" level=debug msg="save cache req http://cache-server:3000/<random-token>/_apis/artifactcache/caches body={\"key\":\"buildkit-blob-1-sha256:0d4c623e273569ef3d9b7f89142096b564f2557d3e909413fa233bbe23f3aeca\",\"version\":\"693bb7016429d80366022f036f84856888c9f13e00145f5f6f4dce303a38d6f2\"}"
  time="2024-07-03T10:08:39Z" level=error msg="/moby.buildkit.v1.Control/Solve returned error: rpc error: code = Unknown desc = error writing layer blob: Method get is not allowed on this route."
  error writing layer blob: Method get is not allowed on this route.
  7 v0.13.2 buildkitd --debug --allow-insecure-entitlement=network.host
  github.com/tonistiigi/go-actions-cache.checkResponse
    /src/vendor/github.com/tonistiigi/go-actions-cache/cache.go:617
  github.com/tonistiigi/go-actions-cache.(*Cache).doWithRetries
    /src/vendor/github.com/tonistiigi/go-actions-cache/cache.go:453
  github.com/tonistiigi/go-actions-cache.(*Cache).reserve
    /src/vendor/github.com/tonistiigi/go-actions-cache/cache.go:246
  github.com/tonistiigi/go-actions-cache.(*Cache).Save
    /src/vendor/github.com/tonistiigi/go-actions-cache/cache.go:320
  github.com/moby/buildkit/cache/remotecache/gha.(*exporter).Finalize
    /src/cache/remotecache/gha/gha.go:174
  github.com/moby/buildkit/solver/llbsolver.runCacheExporters.func1.1
    /src/solver/llbsolver/solver.go:663
  github.com/moby/buildkit/solver/llbsolver.inBuilderContext.func1
    /src/solver/llbsolver/solver.go:996
  github.com/moby/buildkit/solver.(*Job).InContext
    /src/solver/jobs.go:683
  github.com/moby/buildkit/solver/llbsolver.inBuilderContext
    /src/solver/llbsolver/solver.go:992
  github.com/moby/buildkit/solver/llbsolver.runCacheExporters.func1
    /src/solver/llbsolver/solver.go:644
  golang.org/x/sync/errgroup.(*Group).Go.func1
    /src/vendor/golang.org/x/sync/errgroup/errgroup.go:75
  runtime.goexit
    /usr/local/go/src/runtime/asm_amd64.s:1650
  7 v0.13.2 buildkitd --debug --allow-insecure-entitlement=network.host
  github.com/tonistiigi/go-actions-cache.(*Cache).reserve
    /src/vendor/github.com/tonistiigi/go-actions-cache/cache.go:248
  github.com/tonistiigi/go-actions-cache.(*Cache).Save
    /src/vendor/github.com/tonistiigi/go-actions-cache/cache.go:320
  github.com/moby/buildkit/cache/remotecache/gha.(*exporter).Finalize
    /src/cache/remotecache/gha/gha.go:174
  github.com/moby/buildkit/solver/llbsolver.runCacheExporters.func1.1
    /src/solver/llbsolver/solver.go:663
  github.com/moby/buildkit/solver/llbsolver.inBuilderContext.func1
    /src/solver/llbsolver/solver.go:996
  github.com/moby/buildkit/solver.(*Job).InContext
    /src/solver/jobs.go:683
  github.com/moby/buildkit/solver/llbsolver.inBuilderContext
    /src/solver/llbsolver/solver.go:992
  github.com/moby/buildkit/solver/llbsolver.runCacheExporters.func1
    /src/solver/llbsolver/solver.go:644
  golang.org/x/sync/errgroup.(*Group).Go.func1
    /src/vendor/golang.org/x/sync/errgroup/errgroup.go:75
  runtime.goexit
    /usr/local/go/src/runtime/asm_amd64.s:1650
  7 v0.13.2 buildkitd --debug --allow-insecure-entitlement=network.host
  github.com/moby/buildkit/cache/remotecache/gha.(*exporter).Finalize
    /src/cache/remotecache/gha/gha.go:176
  github.com/moby/buildkit/solver/llbsolver.runCacheExporters.func1.1
    /src/solver/llbsolver/solver.go:663
  github.com/moby/buildkit/solver/llbsolver.inBuilderContext.func1
    /src/solver/llbsolver/solver.go:996
  github.com/moby/buildkit/solver.(*Job).InContext
    /src/solver/jobs.go:683
  github.com/moby/buildkit/solver/llbsolver.inBuilderContext
    /src/solver/llbsolver/solver.go:992
  github.com/moby/buildkit/solver/llbsolver.runCacheExporters.func1
    /src/solver/llbsolver/solver.go:644
  golang.org/x/sync/errgroup.(*Group).Go.func1
    /src/vendor/golang.org/x/sync/errgroup/errgroup.go:75
  runtime.goexit
    /usr/local/go/src/runtime/asm_amd64.s:1650
  7 v0.13.2 buildkitd --debug --allow-insecure-entitlement=network.host
  main.unaryInterceptor.func1
    /src/cmd/buildkitd/main.go:711
  main.main.func3.ChainUnaryServer.func2.1.1
    /src/vendor/github.com/grpc-ecosystem/go-grpc-middleware/chain.go:25
  main.main.func3.ChainUnaryServer.func2
    /src/vendor/github.com/grpc-ecosystem/go-grpc-middleware/chain.go:34
  github.com/moby/buildkit/api/services/control._Control_Solve_Handler
    /src/api/services/control/control.pb.go:2466
  google.golang.org/grpc.(*Server).processUnaryRPC
    /src/vendor/google.golang.org/grpc/server.go:1343
  google.golang.org/grpc.(*Server).handleStream
    /src/vendor/google.golang.org/grpc/server.go:1737
  google.golang.org/grpc.(*Server).serveStreams.func1.1
    /src/vendor/google.golang.org/grpc/server.go:986
  runtime.goexit
    /usr/local/go/src/runtime/asm_amd64.s:1650
LouisHaftmann commented 1 week ago

i'll look into it