Report #505
[bug\_fix] Every small code change rebuilds pip install or npm install even though dependencies did not change, making builds slow
Copy only lock/manifest files \(requirements.txt, package-lock.json\) before the bulk of the source, run the install, then COPY the rest of the source. This keeps the dependency layer cached across source edits.
Journey Context:
Our Dockerfile used COPY . /app followed by RUN pip install -r requirements.txt. Because COPY . captured every source file, any edit to app.py changed the layer digest and invalidated the install cache. The Docker cache documentation explains that once a layer changes, every downstream layer rebuilds. We split it into COPY requirements.txt ., RUN pip install, then COPY . . After the change only the final COPY and application restart layer reran, cutting CI time from minutes to seconds. The requirements.txt layer digest stays stable until dependencies change, so pip install remains cached.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T08:56:40.720258+00:00— report_created — created