fix(images): build when Ubuntu upgrades a base package

Installing the job container's tools upgrades base packages once Ubuntu
has newer ones, and the purge does not downgrade them, so the version
check failed every image. Kaniko now empties the root filesystem and
unpacks the base image before its first snapshot (--pre-cleanup), so the
versions no longer matter. Extra packages and files no package owns
still fail the job.

With the filesystem emptied, a failed build can leave no rm for the last
step, so the build step empties the credential file itself.

The images also kept the base image's package versions. Each Dockerfile
now upgrades them, and the base digests move to the newest published.

Refs #508

Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-12-03 08:30:16 +00:00
1 parent e446e1e09a
commit 9127ac565a
8 files changed
+51 -41

No files matched your search

+26 -28
View File
@@ -83,22 +83,22 @@ jobs:
base: "0.1" base: "0.1"
subpath: images/molecule-ubuntu2404 subpath: images/molecule-ubuntu2404
dockerfile: Dockerfile dockerfile: Dockerfile
job_image: ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b job_image: ubuntu:24.04@sha256:168a88cc61bdd95c8f871e3903d4e0a525e340c2b28a70dadd6d1503ecc7c391
- name: molecule-ubuntu2604 - name: molecule-ubuntu2604
base: "0.1" base: "0.1"
subpath: images/molecule-ubuntu2604 subpath: images/molecule-ubuntu2604
dockerfile: Dockerfile dockerfile: Dockerfile
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
- name: ci - name: ci
base: "0.2" base: "0.2"
subpath: "" subpath: ""
dockerfile: images/ci/Dockerfile dockerfile: images/ci/Dockerfile
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
- name: molecule-controller - name: molecule-controller
base: "0.1" base: "0.1"
subpath: "" subpath: ""
dockerfile: images/molecule-controller/Dockerfile dockerfile: images/molecule-controller/Dockerfile
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
container: container:
image: ${{ matrix.job_image }} image: ${{ matrix.job_image }}
# Keeps a runaway build from taking the whole runner down with it. # Keeps a runaway build from taking the whole runner down with it.
@@ -107,21 +107,17 @@ jobs:
DEBIAN_FRONTEND: noninteractive DEBIAN_FRONTEND: noninteractive
IMAGE_PATH: mortis/${{ matrix.name }} IMAGE_PATH: mortis/${{ matrix.name }}
steps: steps:
# One step, in this order, so the filesystem the build starts from is the pristine # Kaniko unpacks the base image into the job container's own root filesystem and
# base image. Kaniko unpacks the base image into the job container's own root # snapshots from there, so anything left in it (curl and its libraries) would count
# filesystem and snapshots from there, so anything installed in the job container # as "already present" and be missing from the layers that install the same packages.
# first (curl and its libraries) would count as "already present" and be missing # The build's --pre-cleanup empties that filesystem first; this step also cleans up
# from the layers that install the same packages (ca-certificates, libkrb5 ...). # after itself, so a leftover fails the job instead of relying on that flag alone.
# The tools are therefore installed, used, and exactly the packages the install # The tools are therefore installed, used, and exactly the packages the install
# added are purged (not `autoremove`, which would also drop base packages that # added are purged (not `autoremove`, which would also drop base packages that
# are marked auto-installed). The result is compared with what was recorded # are marked auto-installed). The package names must then equal those recorded before
# before the install: the package names and versions must be identical, and any # the install, and a new file under /usr, /lib, /bin, /sbin, /opt or /etc that no
# file difference under /usr, /lib, /bin, /sbin, /opt or /etc fails the job. # package owns fails the job. Versions may differ: the install upgrades a base package
# Names only, no sizes or modes, and /var/log, /run and dpkg's *-old files are # when Ubuntu has a newer one, and the build starts from the base image's copy again.
# not compared: logs and dpkg state the install touched may end up in the first
# layer as modified files. That is cosmetic. Not yet checked: listing the layers
# (crane export | tar t, looking for run/act, root/ and var/log/apt) needs a
# read:package token, which the Claude token lacks.
# #
# The pinned kaniko v1.28.6 image has index digest # The pinned kaniko v1.28.6 image has index digest
# sha256:2fa20b0a4b40c7db72b479d57e55c2cf79f2178533b2d3bcbd129d6bd3c087ed and # sha256:2fa20b0a4b40c7db72b479d57e55c2cf79f2178533b2d3bcbd129d6bd3c087ed and
@@ -163,7 +159,6 @@ jobs:
snapshot > /kaniko/fs.before snapshot > /kaniko/fs.before
pkgs() { dpkg-query -W -f='${Package}:${Architecture}\n' | LC_ALL=C sort; } pkgs() { dpkg-query -W -f='${Package}:${Architecture}\n' | LC_ALL=C sort; }
pkgs > /kaniko/pkgs.before pkgs > /kaniko/pkgs.before
dpkg-query -W -f='${Package}:${Architecture} ${Version}\n' | LC_ALL=C sort > /kaniko/pkgv.before
apt-get update apt-get update
apt-get install -y --no-install-recommends ca-certificates curl python3 apt-get install -y --no-install-recommends ca-certificates curl python3
@@ -243,25 +238,24 @@ jobs:
fi fi
fi fi
# Back to the pristine base image (see above): purge exactly what the install # Purge exactly what the install added, then compare packages and files with the record (see above).
# added, then compare packages (names and versions) and files with the record.
pkgs > /kaniko/pkgs.installed pkgs > /kaniko/pkgs.installed
comm -13 /kaniko/pkgs.before /kaniko/pkgs.installed | xargs apt-get purge -y comm -13 /kaniko/pkgs.before /kaniko/pkgs.installed | xargs apt-get purge -y
apt-get clean apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* rm -rf /var/lib/apt/lists/* /tmp/*
dpkg-query -W -f='${Package}:${Architecture} ${Version}\n' | LC_ALL=C sort > /kaniko/pkgv.after pkgs > /kaniko/pkgs.after
if ! diff /kaniko/pkgv.before /kaniko/pkgv.after; then if ! diff /kaniko/pkgs.before /kaniko/pkgs.after; then
echo "::error::The installed packages differ from the pristine base image (listed above): the install" \ echo "::error::The installed packages are not those of the base image (differences above)."
"upgraded or left packages behind, so the build would start from a modified filesystem."
exit 1 exit 1
fi fi
snapshot > /kaniko/fs.after snapshot > /kaniko/fs.after
diff /kaniko/fs.before /kaniko/fs.after > /kaniko/fs.diff || true comm -13 /kaniko/fs.before /kaniko/fs.after > /kaniko/fs.new
if grep -E '^[<>] /(usr|lib|bin|sbin|opt|etc)/' /kaniko/fs.diff; then # dpkg -S fails on a path no package owns; an upgraded base package may bring new files of its own.
echo "::error::The job container differs from the pristine base image (listed above); the build would produce wrong layers." if ! sed -nE '\#^/(usr|lib|bin|sbin|opt|etc)/#p' /kaniko/fs.new | xargs -r -d '\n' dpkg -S > /dev/null; then
echo "::error::The install left files behind that no package owns (listed above)."
exit 1 exit 1
fi fi
echo "Package and filesystem check passed ($(grep -c '^[<>]' /kaniko/fs.diff || true) unrelated file differences outside the checked directories)" echo "Package and filesystem check passed"
- name: Build and push with kaniko - name: Build and push with kaniko
env: env:
@@ -279,6 +273,9 @@ jobs:
set +x set +x
set -eu set -eu
export DOCKER_CONFIG=/kaniko/.docker export DOCKER_CONFIG=/kaniko/.docker
# A build that fails right after --pre-cleanup leaves no rm for the last step, so empty the
# credential file with a shell builtin.
trap '{ : > "$DOCKER_CONFIG/config.json"; } 2> /dev/null || true' EXIT
# The CA bundle from the kaniko image: the base image has none. # The CA bundle from the kaniko image: the base image has none.
export SSL_CERT_DIR=/kaniko/ssl/certs export SSL_CERT_DIR=/kaniko/ssl/certs
registry="${SERVER_URL#https://}" registry="${SERVER_URL#https://}"
@@ -331,6 +328,7 @@ jobs:
"${ctx[@]}" \ "${ctx[@]}" \
"${dests[@]}" \ "${dests[@]}" \
"${labels[@]}" \ "${labels[@]}" \
--pre-cleanup \
--snapshot-mode=redo \ --snapshot-mode=redo \
--cache=false \ --cache=false \
--push-retry 3 \ --push-retry 3 \
+2 -1
View File
@@ -7,7 +7,8 @@ It is the release the hosts run today.
## What is in it ## What is in it
- Ubuntu 24.04 (the official `ubuntu:24.04` image, pinned by digest in the Dockerfile). - Ubuntu 24.04 (the official `ubuntu:24.04` image, pinned by digest in the Dockerfile, with its packages
upgraded when the image is built).
- systemd as the init system (`systemd`, `systemd-sysv`), D-Bus, `sudo`, `iproute2`, - systemd as the init system (`systemd`, `systemd-sysv`), D-Bus, `sudo`, `iproute2`,
`ca-certificates`. `ca-certificates`.
- Python for Ansible on the target: `python3`, `python3-apt`, `python3-systemd`. - Python for Ansible on the target: `python3`, `python3-apt`, `python3-systemd`.
+2 -1
View File
@@ -7,7 +7,8 @@ It is the release the hosts are moving to; every role scenario whose role declar
## What is in it ## What is in it
- Ubuntu 26.04 (the official `ubuntu:26.04` image, pinned by digest in the Dockerfile). - Ubuntu 26.04 (the official `ubuntu:26.04` image, pinned by digest in the Dockerfile, with its packages
upgraded when the image is built).
- systemd as the init system (`systemd`, `systemd-sysv`), D-Bus, `sudo`, `iproute2`, - systemd as the init system (`systemd`, `systemd-sysv`), D-Bus, `sudo`, `iproute2`,
`ca-certificates`. `ca-certificates`.
- Python for Ansible on the target: `python3`, `python3-apt`, `python3-systemd`. - Python for Ansible on the target: `python3`, `python3-apt`, `python3-systemd`.
+2
View File
@@ -65,6 +65,8 @@ it to this repository's organisation in the Gitea registry as `<version>` and `l
the fast path Lint and Build cut the network by environment, so a download through pip or a the fast path Lint and Build cut the network by environment, so a download through pip or a
proxy-honouring client fails the job; review for a raw socket, for the script tests, which keep proxy-honouring client fails the job; review for a raw socket, for the script tests, which keep
network, and for Molecule. network, and for Molecule.
- **Each Dockerfile upgrades the base image's packages in its first apt layer.** *Why:* Ubuntu
publishes package updates before it refreshes the base image. *Held:* review.
- **Recorded speed:** a speed optimisation that adds machinery states its measured saving where - **Recorded speed:** a speed optimisation that adds machinery states its measured saving where
it lives (a comment next to it). *Why:* machinery is kept only for a saving someone can check. it lives (a comment next to it). *Why:* machinery is kept only for a saving someone can check.
*Held:* review. *Held:* review.
+4 -3
View File
@@ -37,15 +37,16 @@
# Layers: each COPY / RUN below is one layer, and a layer is pushed as one request, # Layers: each COPY / RUN below is one layer, and a layer is pushed as one request,
# so it must stay below Cloudflare's 100 MB request-body limit on git.rkdr.net. The # so it must stay below Cloudflare's 100 MB request-body limit on git.rkdr.net. The
# build stage prints the sizes it will copy; the first push is the real test. # build stage prints the sizes it will copy; the first push is the real test.
# Base image: ubuntu:26.04 index digest as of 2026-10-26, same as molecule-ubuntu2604. # Base image: ubuntu:26.04 index digest as of 2026-12-03, same as molecule-ubuntu2604.
FROM ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db AS os FROM ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd AS os
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
# No python3-pip: tools are installed with the venv's own pip. python3-venv brings # No python3-pip: tools are installed with the venv's own pip. python3-venv brings
# ensurepip. apt lists are removed in the same layer. # ensurepip. The upgrade brings in updates newer than the base image. apt lists are removed in the same layer.
RUN apt-get update \ RUN apt-get update \
&& apt-get upgrade -y --with-new-pkgs --no-install-recommends \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
ca-certificates git python3 python3-venv shellcheck \ ca-certificates git python3 python3-venv shellcheck \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
+3 -2
View File
@@ -24,14 +24,15 @@
# stay below Cloudflare's 100 MB request-body limit on git.rkdr.net. The build stage prints the # stay below Cloudflare's 100 MB request-body limit on git.rkdr.net. The build stage prints the
# compressed size of each directory it copies. # compressed size of each directory it copies.
FROM ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db AS os FROM ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd AS os
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
# python3 and python3-venv only bootstrap uv in the build stage; ca-certificates serve the # python3 and python3-venv only bootstrap uv in the build stage; ca-certificates serve the
# install a job runs when a pull request changes a pin; git lets the selector diff the checkout. # install a job runs when a pull request changes a pin; git lets the selector diff the checkout.
# apt lists are removed in the same layer. # The upgrade brings in updates newer than the base image. apt lists are removed in the same layer.
RUN apt-get update \ RUN apt-get update \
&& apt-get upgrade -y --with-new-pkgs --no-install-recommends \
&& apt-get install -y --no-install-recommends ca-certificates git python3 python3-venv \ && apt-get install -y --no-install-recommends ca-certificates git python3 python3-venv \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
+6 -3
View File
@@ -17,15 +17,16 @@
# One RUN layer: at most about 30 MB compressed on top of the 29.8 MB base (estimated from # One RUN layer: at most about 30 MB compressed on top of the 29.8 MB base (estimated from
# the real .debs, with the .pyc files the postinst scripts compile), far below # the real .debs, with the .pyc files the postinst scripts compile), far below
# Cloudflare's 100 MB request-body limit on git.rkdr.net (kaniko pushes a layer as # Cloudflare's 100 MB request-body limit on git.rkdr.net (kaniko pushes a layer as
# one request; gnupg adds a few MB, not measured). apt packages are not version-pinned, as in the original image; the # one request; gnupg adds a few MB, not measured, and the upgraded base packages about 4 MB).
# apt packages are not version-pinned, as in the original image; the
# base image is pinned by digest and a rebuild is a reviewed digest bump downstream. # base image is pinned by digest and a rebuild is a reviewed digest bump downstream.
# #
# The image carries SSH host keys and a machine-id generated at build time (the # The image carries SSH host keys and a machine-id generated at build time (the
# openssh-server and systemd postinst scripts). ssh.service runs `sshd -t` and # openssh-server and systemd postinst scripts). ssh.service runs `sshd -t` and
# fails without host keys, so they cannot be removed; image scanners will flag them. # fails without host keys, so they cannot be removed; image scanners will flag them.
# They are throwaway keys of a test target that is never exposed. # They are throwaway keys of a test target that is never exposed.
# ubuntu:24.04 index digest as of 2026-10-24 (24.04.5). # ubuntu:24.04 index digest as of 2026-12-03.
FROM ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b FROM ubuntu:24.04@sha256:168a88cc61bdd95c8f871e3903d4e0a525e340c2b28a70dadd6d1503ecc7c391
LABEL org.opencontainers.image.title="molecule-ubuntu2404" \ LABEL org.opencontainers.image.title="molecule-ubuntu2404" \
org.opencontainers.image.description="Disposable Ubuntu 24.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection. systemd runs as PID 1 with D-Bus, sudo, python3 and the test fixtures (iptables, openssh-server, gnupg) preinstalled. A package a role installs is not baked in and no APT lists are kept, so a scenario refreshes the APT cache before a role installs one. Start it as a molecule platform (usage label); it carries throwaway SSH host keys and is a test target only, never to be exposed." \ org.opencontainers.image.description="Disposable Ubuntu 24.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection. systemd runs as PID 1 with D-Bus, sudo, python3 and the test fixtures (iptables, openssh-server, gnupg) preinstalled. A package a role installs is not baked in and no APT lists are kept, so a scenario refreshes the APT cache before a role installs one. Start it as a molecule platform (usage label); it carries throwaway SSH host keys and is a test target only, never to be exposed." \
@@ -41,11 +42,13 @@ LABEL org.opencontainers.image.title="molecule-ubuntu2404" \
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
# The upgrade brings in updates newer than the base image.
# systemd as PID 1 with D-Bus, sudo and networking tools; the Python Ansible needs on # systemd as PID 1 with D-Bus, sudo and networking tools; the Python Ansible needs on
# the target (python3-apt for the apt module, python3-systemd for the journal); iptables; # the target (python3-apt for the apt module, python3-systemd for the journal); iptables;
# sshd, enabled so a converge can test it under systemd; gnupg, which the docker scenario # sshd, enabled so a converge can test it under systemd; gnupg, which the docker scenario
# signs its stand-in APT repository with. ufw and fail2ban are left out: their roles install them. # signs its stand-in APT repository with. ufw and fail2ban are left out: their roles install them.
RUN apt-get update \ RUN apt-get update \
&& apt-get upgrade -y --with-new-pkgs --no-install-recommends \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
systemd systemd-sysv dbus sudo iproute2 ca-certificates \ systemd systemd-sysv dbus sudo iproute2 ca-certificates \
python3 python3-apt python3-systemd \ python3 python3-apt python3-systemd \
+6 -3
View File
@@ -17,15 +17,16 @@
# One RUN layer: at most about 30 MB compressed on top of the 29.8 MB base (estimated from # One RUN layer: at most about 30 MB compressed on top of the 29.8 MB base (estimated from
# the real .debs, with the .pyc files the postinst scripts compile), far below # the real .debs, with the .pyc files the postinst scripts compile), far below
# Cloudflare's 100 MB request-body limit on git.rkdr.net (kaniko pushes a layer as # Cloudflare's 100 MB request-body limit on git.rkdr.net (kaniko pushes a layer as
# one request; gnupg adds a few MB, not measured). apt packages are not version-pinned, as in the original image; the # one request; gnupg adds a few MB, not measured, and the upgraded base packages about 4 MB).
# apt packages are not version-pinned, as in the original image; the
# base image is pinned by digest and a rebuild is a reviewed digest bump downstream. # base image is pinned by digest and a rebuild is a reviewed digest bump downstream.
# #
# The image carries SSH host keys and a machine-id generated at build time (the # The image carries SSH host keys and a machine-id generated at build time (the
# openssh-server and systemd postinst scripts). ssh.service runs `sshd -t` and # openssh-server and systemd postinst scripts). ssh.service runs `sshd -t` and
# fails without host keys, so they cannot be removed; image scanners will flag them. # fails without host keys, so they cannot be removed; image scanners will flag them.
# They are throwaway keys of a test target that is never exposed. # They are throwaway keys of a test target that is never exposed.
# ubuntu:26.04 index digest as of 2026-10-26. # ubuntu:26.04 index digest as of 2026-12-03.
FROM ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db FROM ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
LABEL org.opencontainers.image.title="molecule-ubuntu2604" \ LABEL org.opencontainers.image.title="molecule-ubuntu2604" \
org.opencontainers.image.description="Disposable Ubuntu 26.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection. systemd runs as PID 1 with D-Bus, sudo, python3 and the test fixtures (iptables, openssh-server, gnupg) preinstalled. A package a role installs is not baked in and no APT lists are kept, so a scenario refreshes the APT cache before a role installs one. Start it as a molecule platform (usage label); it carries throwaway SSH host keys and is a test target only, never to be exposed." \ org.opencontainers.image.description="Disposable Ubuntu 26.04 test target for the molecule scenarios of the mortis.kamino Ansible Collection. systemd runs as PID 1 with D-Bus, sudo, python3 and the test fixtures (iptables, openssh-server, gnupg) preinstalled. A package a role installs is not baked in and no APT lists are kept, so a scenario refreshes the APT cache before a role installs one. Start it as a molecule platform (usage label); it carries throwaway SSH host keys and is a test target only, never to be exposed." \
@@ -41,6 +42,7 @@ LABEL org.opencontainers.image.title="molecule-ubuntu2604" \
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
# The upgrade brings in updates newer than the base image.
# systemd as PID 1 with D-Bus, sudo and networking tools; the Python Ansible needs on # systemd as PID 1 with D-Bus, sudo and networking tools; the Python Ansible needs on
# the target (python3-apt for the apt module, python3-systemd for the journal); iptables; # the target (python3-apt for the apt module, python3-systemd for the journal); iptables;
# sshd, enabled so a converge can test it under systemd; gnupg, which the docker scenario # sshd, enabled so a converge can test it under systemd; gnupg, which the docker scenario
@@ -48,6 +50,7 @@ ENV DEBIAN_FRONTEND=noninteractive
# root's sudo (Ansible's become here) skips pam_unix's account check, whose unix_chkpwd # root's sudo (Ansible's become here) skips pam_unix's account check, whose unix_chkpwd
# helper fails inside the container; non-root callers still go through pam_unix. # helper fails inside the container; non-root callers still go through pam_unix.
RUN apt-get update \ RUN apt-get update \
&& apt-get upgrade -y --with-new-pkgs --no-install-recommends \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
systemd systemd-sysv dbus sudo iproute2 ca-certificates \ systemd systemd-sysv dbus sudo iproute2 ca-certificates \
python3 python3-apt python3-systemd \ python3 python3-apt python3-systemd \