From da5b4bcffff0660afd8e17078aa6d0d4ec3118f7 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 12 Oct 2025 11:02:47 +0200 Subject: [PATCH] container: remove old image when upgrading at startup One unique feature of Infix OS is that you can embed your OCI archive in the rootfs.squashfs. This way your container instance does not need to download anything from the network. To upgrade you drop in a new image and rebuild Infix, when the new Infix boots the container script 'setup' command will recognize that the OCI archive has changed and will reload it into the container store. This patch is an improvement of the way too generic 'podman image prune' command used previously. Instead of looking for any dangling image, we now surgically remove the old image. Signed-off-by: Joachim Wiberg --- board/common/rootfs/usr/sbin/container | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/board/common/rootfs/usr/sbin/container b/board/common/rootfs/usr/sbin/container index 77d9f9d5..9579b251 100755 --- a/board/common/rootfs/usr/sbin/container +++ b/board/common/rootfs/usr/sbin/container @@ -997,6 +997,12 @@ case $cmd in fi fi + # Capture old image ID before recreation (for surgical cleanup after) + old_image_id="" + if podman container exists "$name"; then + old_image_id=$(podman inspect "$name" --format '{{.ImageID}}' 2>/dev/null) + fi + # Save our PID in case we get stuck here and someone wants to # stop us, e.g., due to reconfiguration or reboot. pidfile=$(pidfn "${name}") @@ -1033,8 +1039,17 @@ case $cmd in fi rm -f "$pidfile" - cnt=$(podman image prune -f | wc -l) - log "Pruned $cnt image(s)" + + # Remove the old image if it's not used by any other containers + if [ -n "$old_image_id" ]; then + # Check if the old image is still in use by any containers + if ! podman ps -a --format '{{.ImageID}}' | grep -q "^${old_image_id}$"; then + log "Removing old image $old_image_id" + podman rmi "$old_image_id" 2>/dev/null || true + else + log "Old image $old_image_id still in use by other containers, keeping it" + fi + fi ;; shell) if [ -z "$name" ]; then