Detect containers running behind already-pulled images
OLD_ID vs NEW_ID only caught updates landed during this run. If an image was pulled externally (Unraid UI), the container stayed on the old image while :latest moved on — this run saw nothing to do. Now also compare the container's current image ID against :latest and rebuild if behind.
This commit is contained in:
@@ -285,7 +285,10 @@ for container in "${TARGET_CONTAINERS[@]}"; do
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Capture image ID before pull to detect whether an update landed
|
# Capture the image ID the container is currently running on, and the
|
||||||
|
# image ID :latest points to before the pull. After pulling, we rebuild if
|
||||||
|
# either a new digest landed OR the container is behind what :latest is now.
|
||||||
|
CONTAINER_IMAGE_ID=$(docker inspect "$container" --format='{{.Image}}' 2>/dev/null || echo "")
|
||||||
OLD_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "")
|
OLD_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "")
|
||||||
|
|
||||||
log "$ICON_SYNC Pulling $IMAGE..."
|
log "$ICON_SYNC Pulling $IMAGE..."
|
||||||
@@ -299,12 +302,16 @@ for container in "${TARGET_CONTAINERS[@]}"; do
|
|||||||
NEW_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "")
|
NEW_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "")
|
||||||
|
|
||||||
if [[ $_pull_rc -eq 0 ]]; then
|
if [[ $_pull_rc -eq 0 ]]; then
|
||||||
if [[ -n "$OLD_ID" ]] && [[ "$OLD_ID" != "$NEW_ID" ]]; then
|
_pull_new=$( [[ -n "$OLD_ID" && "$OLD_ID" != "$NEW_ID" ]] && echo true || echo false)
|
||||||
log "$ICON_DONE $container — updated ✅ (${OLD_ID:7:12} → ${NEW_ID:7:12})"
|
_container_behind=$([[ -n "$CONTAINER_IMAGE_ID" && -n "$NEW_ID" && "$CONTAINER_IMAGE_ID" != "$NEW_ID" ]] && echo true || echo false)
|
||||||
|
|
||||||
|
if [[ "$_pull_new" == true || "$_container_behind" == true ]]; then
|
||||||
|
[[ "$_pull_new" == true ]] && log "$ICON_DONE $container — new image (${OLD_ID:7:12} → ${NEW_ID:7:12})"
|
||||||
|
[[ "$_container_behind" == true && "$_pull_new" == false ]] && log "$ICON_DONE $container — image already pulled, container behind (${CONTAINER_IMAGE_ID:7:12} → ${NEW_ID:7:12})"
|
||||||
UPDATED+=("$container")
|
UPDATED+=("$container")
|
||||||
OLD_IMAGE_IDS+=("$OLD_ID")
|
OLD_IMAGE_IDS+=("$CONTAINER_IMAGE_ID")
|
||||||
else
|
else
|
||||||
log "$container — already up to date (${NEW_ID:7:12})"
|
log "$container — up to date (${NEW_ID:7:12})"
|
||||||
UP_TO_DATE+=("$container")
|
UP_TO_DATE+=("$container")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ for container in "${REMAINING[@]}"; do
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
CONTAINER_IMAGE_ID=$(docker inspect "$container" --format='{{.Image}}' 2>/dev/null || echo "")
|
||||||
OLD_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "")
|
OLD_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "")
|
||||||
|
|
||||||
log "$ICON_SYNC Pulling $IMAGE..."
|
log "$ICON_SYNC Pulling $IMAGE..."
|
||||||
@@ -200,12 +201,16 @@ for container in "${REMAINING[@]}"; do
|
|||||||
NEW_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "")
|
NEW_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "")
|
||||||
|
|
||||||
if [[ $_pull_rc -eq 0 ]]; then
|
if [[ $_pull_rc -eq 0 ]]; then
|
||||||
if [[ -n "$OLD_ID" ]] && [[ "$OLD_ID" != "$NEW_ID" ]]; then
|
_pull_new=$( [[ -n "$OLD_ID" && "$OLD_ID" != "$NEW_ID" ]] && echo true || echo false)
|
||||||
log "$ICON_DONE $container — updated ✅ (${OLD_ID:7:12} → ${NEW_ID:7:12})"
|
_container_behind=$([[ -n "$CONTAINER_IMAGE_ID" && -n "$NEW_ID" && "$CONTAINER_IMAGE_ID" != "$NEW_ID" ]] && echo true || echo false)
|
||||||
|
|
||||||
|
if [[ "$_pull_new" == true || "$_container_behind" == true ]]; then
|
||||||
|
[[ "$_pull_new" == true ]] && log "$ICON_DONE $container — new image (${OLD_ID:7:12} → ${NEW_ID:7:12})"
|
||||||
|
[[ "$_container_behind" == true && "$_pull_new" == false ]] && log "$ICON_DONE $container — image already pulled, container behind (${CONTAINER_IMAGE_ID:7:12} → ${NEW_ID:7:12})"
|
||||||
UPDATED+=("$container")
|
UPDATED+=("$container")
|
||||||
OLD_IMAGE_IDS+=("$OLD_ID")
|
OLD_IMAGE_IDS+=("$CONTAINER_IMAGE_ID")
|
||||||
else
|
else
|
||||||
log "$container — already up to date (${NEW_ID:7:12})"
|
log "$container — up to date (${NEW_ID:7:12})"
|
||||||
UP_TO_DATE+=("$container")
|
UP_TO_DATE+=("$container")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user