Improve Dockerfile layer caching#239
Merged
Merged
Conversation
Previously: ADD S6 → RUN (apk upgrade + S6 extract + apk add) → pip A S6 bump invalidated the apk and pip layers every time. Now: RUN apk → ADD S6 → RUN S6 extract → pip Each concern is an independent cacheable layer. A S6 bump only invalidates S6 extract onward; an apk-only change doesn't touch S6 or pip; a requirements.txt change only rebuilds pip. Also adds --mount=type=cache for apk to mirror the existing pip cache mount, and removes --no-cache from apk add so the BuildKit cache mount is actually used. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
DL3005/DL3019: apk upgrade and no --no-cache (intentional — using BuildKit cache mount instead of --no-cache for better layer reuse) DL3059: consecutive RUN instructions (intentional split for cache granularity) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
DL3006 on the dynamic FROM base-${TARGETARCH} line — version is
controlled via ARG, not a literal tag.
DL3018 on apk add — already overridden to style in .hadolint.yaml
but inline ignore needed to suppress diff annotations.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reorders Dockerfile layers so each concern caches independently. Previously a S6 version bump invalidated the entire
apk add(55 packages) andpip installchain.Before:
After:
Cache impact per change type:
requirements.txtchangeAlso adds
--mount=type=cache,id=apk-${TARGETARCH}to the apk step (mirrors the existing pip cache mount), and inline# hadolint ignoredirectives for rules that are intentionally violated by this approach (DL3005,DL3006,DL3018,DL3019,DL3059).Test plan