Skip to content

Improve Dockerfile layer caching#239

Merged
modem7 merged 3 commits into
masterfrom
fix/dockerfile-layer-cache
Jun 27, 2026
Merged

Improve Dockerfile layer caching#239
modem7 merged 3 commits into
masterfrom
fix/dockerfile-layer-cache

Conversation

@modem7

@modem7 modem7 commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Summary

Reorders Dockerfile layers so each concern caches independently. Previously a S6 version bump invalidated the entire apk add (55 packages) and pip install chain.

Before:

ADD S6 → RUN (apk upgrade + S6 extract + apk add) → COPY requirements.txt → RUN pip install

After:

RUN apk upgrade + apk add → ADD S6 → RUN S6 extract → COPY requirements.txt → RUN pip install

Cache impact per change type:

Change Before After
S6 bump apk + S6 + pip rebuild S6 + pip rebuild (apk cached)
requirements.txt change pip rebuild pip rebuild only
apk package update apk + S6 + pip rebuild apk + S6 + pip rebuild

Also adds --mount=type=cache,id=apk-${TARGETARCH} to the apk step (mirrors the existing pip cache mount), and inline # hadolint ignore directives for rules that are intentionally violated by this approach (DL3005, DL3006, DL3018, DL3019, DL3059).

Test plan

  • Layer order: apk before S6 ADD
  • Hadolint annotations suppressed
  • CI build passes

modem7 and others added 3 commits June 27, 2026 05:24
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>
@modem7 modem7 merged commit 864f8c0 into master Jun 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant