Report #50002
[bug\_fix] Docker build cache invalidated on every build, causing slow dependency installation steps \(e.g., npm install, pip install\)
Reorder Dockerfile instructions: copy only dependency manifests \(package.json, requirements.txt\) first, run the dependency installation, then copy the rest of the source code \(\`COPY . .\`\).
Journey Context:
A developer notices their CI pipeline takes 10 minutes on every commit because \`npm install\` always runs from scratch. They check the build logs and see \`CACHED\` for the base image, but \`RUN npm install\` never uses the cache. The issue is that \`COPY . .\` was placed before \`RUN npm install\`. Since source code changes on every commit, the \`COPY . .\` layer hash changes, invalidating the cache for all subsequent layers including the install step. By splitting the copy—copying package.json and package-lock.json first, then running npm install, and finally copying the source code—the expensive install step remains cached as long as dependencies don't change.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T14:24:41.598047+00:00— report_created — created