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:
1 parent
e446e1e09a
commit
9127ac565a
8 files changed
+51
-41
No files matched your search
+26
-28
@@ -83,22 +83,22 @@ jobs:
|
||||
base: "0.1"
|
||||
subpath: images/molecule-ubuntu2404
|
||||
dockerfile: Dockerfile
|
||||
job_image: ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b
|
||||
job_image: ubuntu:24.04@sha256:168a88cc61bdd95c8f871e3903d4e0a525e340c2b28a70dadd6d1503ecc7c391
|
||||
- name: molecule-ubuntu2604
|
||||
base: "0.1"
|
||||
subpath: images/molecule-ubuntu2604
|
||||
dockerfile: Dockerfile
|
||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||
job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
|
||||
- name: ci
|
||||
base: "0.2"
|
||||
subpath: ""
|
||||
dockerfile: images/ci/Dockerfile
|
||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||
job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
|
||||
- name: molecule-controller
|
||||
base: "0.1"
|
||||
subpath: ""
|
||||
dockerfile: images/molecule-controller/Dockerfile
|
||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||
job_image: ubuntu:26.04@sha256:a8417def3fc37c2d8cf513fe69ef871d415a45a27847779fae461c5047710edd
|
||||
container:
|
||||
image: ${{ matrix.job_image }}
|
||||
# Keeps a runaway build from taking the whole runner down with it.
|
||||
@@ -107,21 +107,17 @@ jobs:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
IMAGE_PATH: mortis/${{ matrix.name }}
|
||||
steps:
|
||||
# One step, in this order, so the filesystem the build starts from is the pristine
|
||||
# base image. Kaniko unpacks the base image into the job container's own root
|
||||
# filesystem and snapshots from there, so anything installed in the job container
|
||||
# first (curl and its libraries) would count as "already present" and be missing
|
||||
# from the layers that install the same packages (ca-certificates, libkrb5 ...).
|
||||
# Kaniko unpacks the base image into the job container's own root filesystem and
|
||||
# snapshots from there, so anything left in it (curl and its libraries) would count
|
||||
# as "already present" and be missing from the layers that install the same packages.
|
||||
# The build's --pre-cleanup empties that filesystem first; this step also cleans up
|
||||
# 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
|
||||
# added are purged (not `autoremove`, which would also drop base packages that
|
||||
# are marked auto-installed). The result is compared with what was recorded
|
||||
# before the install: the package names and versions must be identical, and any
|
||||
# file difference under /usr, /lib, /bin, /sbin, /opt or /etc fails the job.
|
||||
# Names only, no sizes or modes, and /var/log, /run and dpkg's *-old files are
|
||||
# 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.
|
||||
# are marked auto-installed). The package names must then equal those recorded before
|
||||
# the install, and a new file under /usr, /lib, /bin, /sbin, /opt or /etc that no
|
||||
# package owns fails the job. Versions may differ: the install upgrades a base package
|
||||
# when Ubuntu has a newer one, and the build starts from the base image's copy again.
|
||||
#
|
||||
# The pinned kaniko v1.28.6 image has index digest
|
||||
# sha256:2fa20b0a4b40c7db72b479d57e55c2cf79f2178533b2d3bcbd129d6bd3c087ed and
|
||||
@@ -163,7 +159,6 @@ jobs:
|
||||
snapshot > /kaniko/fs.before
|
||||
pkgs() { dpkg-query -W -f='${Package}:${Architecture}\n' | LC_ALL=C sort; }
|
||||
pkgs > /kaniko/pkgs.before
|
||||
dpkg-query -W -f='${Package}:${Architecture} ${Version}\n' | LC_ALL=C sort > /kaniko/pkgv.before
|
||||
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends ca-certificates curl python3
|
||||
@@ -243,25 +238,24 @@ jobs:
|
||||
fi
|
||||
fi
|
||||
|
||||
# Back to the pristine base image (see above): purge exactly what the install
|
||||
# added, then compare packages (names and versions) and files with the record.
|
||||
# Purge exactly what the install added, then compare packages and files with the record (see above).
|
||||
pkgs > /kaniko/pkgs.installed
|
||||
comm -13 /kaniko/pkgs.before /kaniko/pkgs.installed | xargs apt-get purge -y
|
||||
apt-get clean
|
||||
rm -rf /var/lib/apt/lists/* /tmp/*
|
||||
dpkg-query -W -f='${Package}:${Architecture} ${Version}\n' | LC_ALL=C sort > /kaniko/pkgv.after
|
||||
if ! diff /kaniko/pkgv.before /kaniko/pkgv.after; then
|
||||
echo "::error::The installed packages differ from the pristine base image (listed above): the install" \
|
||||
"upgraded or left packages behind, so the build would start from a modified filesystem."
|
||||
pkgs > /kaniko/pkgs.after
|
||||
if ! diff /kaniko/pkgs.before /kaniko/pkgs.after; then
|
||||
echo "::error::The installed packages are not those of the base image (differences above)."
|
||||
exit 1
|
||||
fi
|
||||
snapshot > /kaniko/fs.after
|
||||
diff /kaniko/fs.before /kaniko/fs.after > /kaniko/fs.diff || true
|
||||
if grep -E '^[<>] /(usr|lib|bin|sbin|opt|etc)/' /kaniko/fs.diff; then
|
||||
echo "::error::The job container differs from the pristine base image (listed above); the build would produce wrong layers."
|
||||
comm -13 /kaniko/fs.before /kaniko/fs.after > /kaniko/fs.new
|
||||
# dpkg -S fails on a path no package owns; an upgraded base package may bring new files of its own.
|
||||
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
|
||||
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
|
||||
env:
|
||||
@@ -279,6 +273,9 @@ jobs:
|
||||
set +x
|
||||
set -eu
|
||||
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.
|
||||
export SSL_CERT_DIR=/kaniko/ssl/certs
|
||||
registry="${SERVER_URL#https://}"
|
||||
@@ -331,6 +328,7 @@ jobs:
|
||||
"${ctx[@]}" \
|
||||
"${dests[@]}" \
|
||||
"${labels[@]}" \
|
||||
--pre-cleanup \
|
||||
--snapshot-mode=redo \
|
||||
--cache=false \
|
||||
--push-retry 3 \
|
||||
|
||||
Reference in new issue
Block a user