Fix Supervisor image corruption detection (#2953)

* Fix Supervisor image corruption detection

When multiple images match the reference, multiple IDs are passed as a
single argument to docker image rm, leading to an error:
Error response from daemon: page not found

Make sure to pass the ids as separate argument to make the delete work
in any case.

* Cleanup reusing Supervisor from an old/unused reference

As noted in #2113, we don't need this logic anymore after a major OS
releases. So simply drop the logic to also make the image corruption
detection work again.

* Make sure image IDs are sorted to make them unique
This commit is contained in:
Stefan Agner 2023-11-30 14:41:44 +01:00
parent e524a5e03d
commit 1ffaec3acb
No known key found for this signature in database
GPG Key ID: 22D95D15D3A36E95

View File

@ -24,22 +24,20 @@ if [ -f "${SUPERVISOR_STARTUP_MARKER}" ]; then
echo "[WARNING] Supervisor container did not remove the startup marker file. Assuming container image or container corruption." echo "[WARNING] Supervisor container did not remove the startup marker file. Assuming container image or container corruption."
docker container rm --force hassio_supervisor || true docker container rm --force hassio_supervisor || true
SUPERVISOR_CONTAINER_ID="" SUPERVISOR_CONTAINER_ID=""
# Make sure we delete all supervisor images # Make sure we delete all supervisor images
SUPERVISOR_IMAGE_IDS=$(docker images --no-trunc --filter "reference=${SUPERVISOR_IMAGE}" --format "{{.ID}}" | uniq || echo "") SUPERVISOR_IMAGE_IDS=$(docker images --no-trunc --filter "reference=${SUPERVISOR_IMAGE}" --format "{{.ID}}" | sort | uniq || echo "")
docker image rm --force "${SUPERVISOR_IMAGE_IDS}" || true # Intended splitting of SUPERVISOR_IMAGE_IDS
# Busybox sh doesn't support arrays
# shellcheck disable=SC2086
docker image rm --force ${SUPERVISOR_IMAGE_IDS} || true
SUPERVISOR_IMAGE_ID="" SUPERVISOR_IMAGE_ID=""
fi fi
# If Supervisor image is missing, pull it
mkdir -p "$(dirname ${SUPERVISOR_STARTUP_MARKER})" mkdir -p "$(dirname ${SUPERVISOR_STARTUP_MARKER})"
touch ${SUPERVISOR_STARTUP_MARKER} touch ${SUPERVISOR_STARTUP_MARKER}
if [ -z "${SUPERVISOR_IMAGE_ID}" ]; then
# Try tagging legacy image with current name and try get its ID
echo "[WARNING] Supervisor image missing, trying to use the legacy image name"
docker tag "homeassistant/${SUPERVISOR_ARCH}-hassio-supervisor:latest" "${SUPERVISOR_IMAGE}:latest" || true
SUPERVISOR_IMAGE_ID=$(docker images --no-trunc --filter "reference=${SUPERVISOR_IMAGE}:latest" --format "{{.ID}}" || echo "")
fi
# If Supervisor image is missing, pull it
if [ -z "${SUPERVISOR_IMAGE_ID}" ]; then if [ -z "${SUPERVISOR_IMAGE_ID}" ]; then
# Get the latest from update information # Get the latest from update information
# Using updater information instead of config. If the config version is # Using updater information instead of config. If the config version is