]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
feat(scripts): archive previous image before docker-upgrade rebuild
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 15 Aug 2026 22:41:08 +0000 (00:41 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 15 Aug 2026 22:57:59 +0000 (00:57 +0200)
scripts/docker-upgrade.sh

index a30c6d3e71e4263b97ffc114c2d142518538c9fd..7cabe2fc149718b13d7c569892e17a2cb2c5644f 100755 (executable)
@@ -248,6 +248,28 @@ if [ "$rebuild_local_image" = true ]; then
     echo_timestamped "Error: docker compose down failed"
     exit 1
   fi
+  previous_image_id=$(
+    command docker image inspect --format='{{.Id}}' "$LOCAL_DOCKER_IMAGE" 2>/dev/null ||
+      printf '%s\n' 'none'
+  )
+  if [ "$previous_image_id" != none ]; then
+    image_name_part=${LOCAL_DOCKER_IMAGE##*/}
+    image_repo="${LOCAL_DOCKER_IMAGE%"$image_name_part"}${image_name_part%%:*}"
+    archive_repo="${image_repo}-archive"
+    archive_tag="${archive_repo}:${previous_image_id#sha256:}"
+    if command docker image tag "$previous_image_id" "$archive_tag" >/dev/null 2>&1; then
+      echo_timestamped "Info: archived previous image as ${archive_tag}"
+      command docker image ls "$archive_repo" --format '{{.Repository}}:{{.Tag}}' 2>/dev/null |
+        while IFS= read -r existing_archive; do
+          if [ -z "$existing_archive" ] || [ "$existing_archive" = "$archive_tag" ]; then
+            continue
+          fi
+          command docker image rm "$existing_archive" >/dev/null 2>&1 || true
+        done
+    else
+      echo_timestamped "Warning: failed to archive previous image ${previous_image_id}"
+    fi
+  fi
   if ! command docker image rm "$LOCAL_DOCKER_IMAGE" >/dev/null 2>&1; then
     echo_timestamped "Warning: docker image rm failed for ${LOCAL_DOCKER_IMAGE}"
   fi