Report #48229
[bug\_fix] Dependency installation layer \(e.g., npm install, pip install\) runs from scratch on every build, invalidating the cache
Split the COPY instruction into two steps: first copy only the dependency manifest files \(package.json, requirements.txt\), then run the install command, and finally copy the rest of the source code.
Journey Context:
A developer notices their CI pipeline takes 10 minutes because \`npm install\` re-downloads the universe on every commit. They check BuildKit output and see the \`CACHED\` marker is missing for the install step. Their Dockerfile has \`COPY . /app\` followed by \`RUN npm install\`. Because any change to any source file alters the layer checksum of \`COPY . /app\`, BuildKit invalidates that layer and all subsequent layers, including the \`RUN npm install\` step. By copying only \`package.json\` and \`package-lock.json\` first, the dependency installation layer only invalidates when the dependencies actually change, allowing the heavy install step to remain cached for routine code changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T11:26:02.410035+00:00— report_created — created