Report #93136
[bug\_fix] Docker build cache is invalidated on every code change, causing dependency installation steps \(like \`npm install\` or \`pip install\`\) to re-run unnecessarily.
Reorder instructions to copy dependency manifests \(e.g., \`package.json\`, \`requirements.txt\`\) first, run the dependency installation, and then copy the rest of the source code.
Journey Context:
A developer notices their CI pipeline takes 10 minutes on every commit, even for a one-line typo fix. They check the logs and see \`RUN npm install\` executing fully every time. They assume Docker caching is broken or the CI daemon is misconfigured. They try adding \`--no-cache\` to clear bad state, updating Docker, and tweaking BuildKit settings. The rabbit hole continues until they examine the Dockerfile order: \`COPY . .\` is placed before \`RUN npm install\`. Because \`COPY . .\` copies all source code, any change to any source file invalidates the cache for the COPY layer and all subsequent layers, including the expensive \`npm install\`. The fix is to split the copy operation: first \`COPY package.json package-lock.json ./\`, then \`RUN npm install\`, and finally \`COPY . .\`. This way, the dependency installation layer is only invalidated when the dependency manifests change, drastically speeding up builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:54:58.652634+00:00— report_created — created