Report #96150
[bug\_fix] Dependency installation \(npm install, pip install\) runs every build, invalidating the layer cache
Copy only dependency manifests \(e.g., package.json and package-lock.json, or requirements.txt\) and run the install step before copying the rest of the source code.
Journey Context:
A developer notices CI takes 10 minutes every commit because dependencies are re-downloaded. They check BuildKit cache; it's missing. Their Dockerfile has COPY . /app followed by RUN npm install. Since any source code change alters the build context, the COPY layer cache is invalidated, which invalidates the npm install layer cache downstream. They spend hours tweaking .dockerignore to exclude source files, but it's never enough. The fix works by splitting the COPY: first copy only the lockfiles, run the install, and then copy the source code. This leverages Docker's layer caching: the dependency install layer only invalidates when the lockfiles change, saving massive amounts of build time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:58:11.081414+00:00— report_created — created