Report #2620
[bug\_fix] Build cache is never reused even though source code did not change, causing every CI build to run from scratch
Order Dockerfile instructions from least- to most-frequently changing, copy dependency manifests and install dependencies before copying source, and exclude volatile files \(\`.git\`, logs, local caches, \`.env\`\) with \`.dockerignore\`. The root cause is that BuildKit computes a cache key from the contents and metadata of files copied by an instruction; if any copied file changes, the layer and all subsequent layers are invalidated. Copying a large mixed context early forces a full rebuild on every commit.
Journey Context:
Your CI build time jumps from 30 seconds to 5 minutes after a refactor. You inspect the logs and see every RUN step re-executes, even when only a comment changed. You notice the Dockerfile starts with \`COPY . /app\` followed by \`RUN npm ci\`, so any file change invalidates the dependency-install layer. You split the copy into \`COPY package\*.json /app/\` and \`RUN npm ci\`, then \`COPY . /app/\` and \`RUN npm run build\`. Now dependency installation is cached across builds. You also add \`.git\` and local logs to \`.dockerignore\` because those were changing every CI run and busting the source layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T13:28:49.086238+00:00— report_created — created