From a219ff89d330fe5c2493610d217e146aa586f78c Mon Sep 17 00:00:00 2001 From: modem7 Date: Sat, 27 Jun 2026 05:19:43 +0100 Subject: [PATCH 1/3] Reorder Dockerfile layers for better cache utilisation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- CHANGELOG.md | 7 +++++++ Dockerfile | 59 ++++++++++++++++++++++++++-------------------------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06b7ed7..e31a342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/). +## 2026-06-27 (continued 7) + +### Changed + +- Reorder Dockerfile layers for better cache utilisation: `apk` packages now install before S6 overlay is added, and S6 is extracted in its own `RUN` step. Previously a S6 version bump invalidated the entire apk + pip chain; now each concern caches independently. +- Use `--mount=type=cache,id=apk-${TARGETARCH}` for the `apk` step (consistent with the existing pip cache mount). + ## 2026-06-27 (continued 6) ### Fixed diff --git a/Dockerfile b/Dockerfile index 1df0e25..bc40b0d 100755 --- a/Dockerfile +++ b/Dockerfile @@ -18,14 +18,6 @@ FROM base-${TARGETARCH}${TARGETVARIANT} ARG S6_OVERLAY_VERSION=3.2.3.0 -# Add S6 Overlay -ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_OVERLAY_ARCH}.tar.xz /tmp/s6-overlay.tar.xz -ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp - -# Add S6 optional symlinks -ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz /tmp -ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz /tmp - ENV LANG='en_US.UTF-8' \ LANGUAGE='en_US.UTF-8' \ S6_LOGGING="1" \ @@ -33,27 +25,22 @@ ENV LANG='en_US.UTF-8' \ S6_CMD_WAIT_FOR_SERVICES_MAXTIME="0" \ TZ="Europe/London" -RUN < Date: Sat, 27 Jun 2026 05:23:12 +0100 Subject: [PATCH 2/3] Add hadolint inline ignores for Dockerfile layer reorder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index bc40b0d..ed0404d 100755 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,7 @@ ENV LANG='en_US.UTF-8' \ # Install system packages first — this layer is independent of S6 and borgmatic # versions, so it stays cached across S6 bumps and requirements.txt changes. +# hadolint ignore=DL3005,DL3019,DL3059 RUN --mount=type=cache,id=apk-${TARGETARCH},target=/etc/apk/cache \ apk upgrade -U && \ apk add -U \ @@ -51,12 +52,14 @@ RUN --mount=type=cache,id=apk-${TARGETARCH},target=/etc/apk/cache \ tzdata \ xxhash +# hadolint ignore=DL3059 # Add S6 Overlay — separate layer so S6 bumps don't invalidate the apk layer ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_OVERLAY_ARCH}.tar.xz /tmp/s6-overlay.tar.xz ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz /tmp ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz /tmp +# hadolint ignore=DL3059 RUN < Date: Sat, 27 Jun 2026 05:24:08 +0100 Subject: [PATCH 3/3] Add missing hadolint inline ignores (DL3006, DL3018) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ed0404d..6d85f28 100755 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,7 @@ ENV S6_OVERLAY_ARCH=x86_64 FROM base AS base-arm64 ENV S6_OVERLAY_ARCH=aarch64 +# hadolint ignore=DL3006 FROM base-${TARGETARCH}${TARGETVARIANT} ARG S6_OVERLAY_VERSION=3.2.3.0 @@ -27,7 +28,7 @@ ENV LANG='en_US.UTF-8' \ # Install system packages first — this layer is independent of S6 and borgmatic # versions, so it stays cached across S6 bumps and requirements.txt changes. -# hadolint ignore=DL3005,DL3019,DL3059 +# hadolint ignore=DL3005,DL3018,DL3019,DL3059 RUN --mount=type=cache,id=apk-${TARGETARCH},target=/etc/apk/cache \ apk upgrade -U && \ apk add -U \