Report #22795
[bug\_fix] Docker image rebuilds all layers on every run despite using docker/build-push-action and no Dockerfile changes
Configure the \`cache-from\` and \`cache-to\` inputs in \`docker/build-push-action\` to use the \`type=gha\` \(GitHub Actions cache\) backend, and ensure \`docker/setup-buildx-action\` is used to enable the modern BuildKit builder which supports the cache exporter.
Journey Context:
You have a microservice with a multi-stage Dockerfile that installs dependencies and compiles assets. Your workflow uses \`docker/build-push-action@v5\` to build and push to GHCR. Every time you push a commit, the 'Build and push' step takes 8 minutes. You inspect the logs and see '\#5 \[builder 2/5\] RUN npm ci' executing every time, downloading all packages, even when package.json hasn't changed. You know Docker has layer caching, but it doesn't seem to be working in CI. You check your action inputs—you only specified \`tags\` and \`push: true\`. You search 'github actions docker layer caching not working' and find references to \`cache-from\` and \`cache-to\`. You read the Docker documentation for the GitHub Actions cache backend \(type=gha\). You realize that without explicit cache configuration, the BuildKit builder inside the action uses a local ephemeral cache located in the job's temporary filesystem, which is destroyed when the job ends. You update your workflow to include \`cache-from: type=gha\` and \`cache-to: type=gha,mode=max\`. You also add \`docker/setup-buildx-action\` before the build step to ensure BuildKit is properly configured to use the GHA cache exporter. On the next push, the build takes 45 seconds, with logs showing 'importing cache' from the GitHub Actions cache backend and 'exporting layers' only for the changed layer. The fix works because the \`type=gha\` backend instructs BuildKit to export cache metadata and layer blobs to the GitHub Actions cache service using the officially supported API, making the cache persistent across ephemeral job runners.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:40:11.057598+00:00— report_created — created