Report #86915
[bug\_fix] Cache miss on dependency installation step \(e.g., npm install, pip install\) every time source code changes
Reorder the Dockerfile instructions to copy only the dependency manifest files \(package.json, requirements.txt\) first, run the installation step, and then copy the rest of the application source code.
Journey Context:
A developer notices their CI builds take 10 minutes because dependencies are re-downloaded on every commit. They assume Docker layer caching is broken. Debugging the build logs, they realize that the Dockerfile starts with COPY . /app, followed by RUN npm install. Because Docker creates layers sequentially, any change to any file in the source code invalidates the COPY layer, which in turn invalidates the npm install layer, forcing a full reinstall. By splitting the copy into two steps—copying package.json and package-lock.json first, running npm install, and then copying the remaining source—the expensive dependency installation layer is only invalidated when the dependency manifests themselves change.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:28:29.394097+00:00— report_created — created