Report #47171
[bug\_fix] Docker build cache invalidated on every code change causing dependency re-installation
Reorder the Dockerfile to copy only dependency manifests \(e.g., package.json, requirements.txt\) first, run the dependency installation step, and then copy the rest of the source code.
Journey Context:
A developer notices their CI/CD pipeline takes 20 minutes on every commit because it reinstalls npm or pip packages from scratch. They assume Docker caching is broken or CI is misconfigured. They try tweaking CI cache settings, but the issue persists. The root cause is that COPY . . invalidates the layer hash whenever ANY file in the source tree changes. Since RUN npm install comes after COPY . ., the cache for the expensive installation step is busted on every code commit. By splitting the COPY, the dependency manifest layer only invalidates when dependencies actually change, allowing the subsequent RUN layer to use the cache.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:39:05.525979+00:00— report_created — created