fix: record the replaced images before the database step, for the whole project
CI / check (pull_request) Successful in 22s

The record was taken right before the engine's swap. Since then the database
step and the broker replace their containers earlier, so a new PostgreSQL or
Valkey image left the old one on the host for good; docker image prune -af
used to take it. It also listed only the engine services, so postgres (behind
its compose profile), apt-cacher-ng, signal-api and the retired registry were
never recorded.

deploy.sh now records the images of every container of the compose project
netork, by its label, before the database step, and keeps only image IDs:
they are expanded into the command that removes them. They are still removed
only after the verification and the migration; a failed deploy removes
nothing. remove_replaced_images.sh says nothing about an image still in use,
which most of them now are on every deploy, and names only what it removed or
could not remove.
This commit is contained in:
Christian Manivong committed 2026-12-02 17:27:03 +01:00
1 parent 31cc9da537
commit abefafe070
6 files changed
+121 -44

No files matched your search

+18 -12
View File
@@ -326,6 +326,19 @@ deploy_steps() {
REGISTRY_HOST='${REGISTRY_HOST}' NETORK_VERSION='${SERVER_VERSION}' \
docker compose -f docker-compose.yml -f docker-compose.registry.yml pull ${SERVICES}"
# The images netOrk's containers use now, before the first of them can be
# replaced: the database step and the broker go before the engine's swap. Once
# the deploy went through, these are what it replaced, and the only images it
# removes (at the end). Every container of the compose project, by its label:
# `compose ps` would miss postgres, which sits behind a profile, and a retired
# service that is in no compose file any more. Only image IDs are kept, since
# they are expanded into the command that removes them. A record that fails
# leaves nothing to remove, and the deploy goes on.
local REPLACED
REPLACED=$(ssh -n "$SERVER" "docker ps -aq --filter label=com.docker.compose.project=netork \
| xargs -r docker inspect --format '{{.Image}}'" 2>/dev/null \
| grep -E '^sha256:[0-9a-f]{64}$' | sort -u || true)
# The bundled database, before .env, broker and engine (remote/database.sh). A
# changed image on the same volume (a minor release) is recreated; a new
# volume (a major release) moves only with --infra-db, and without it the
@@ -445,14 +458,6 @@ REMOTE_ENV
# netOrk was down until someone ran the deploy again, which then went through
# (NetOrk/netork#586). The second attempt is that rerun. Should it fail as well,
# the container states go to the log and the deploy fails as before.
# The images netOrk's own containers use now, before the swap: after it, these
# are what the deploy replaced, and the only images it removes (below).
local REPLACED
REPLACED=$(ssh -n "$SERVER" "cd ~/netork && \
REGISTRY_HOST='${REGISTRY_HOST}' NETORK_VERSION='${SERVER_VERSION}' \
docker compose -f docker-compose.yml -f docker-compose.registry.yml ps -aq ${SERVICES} \
| xargs -r docker inspect --format '{{.Image}}' | sort -u" 2>/dev/null || true)
echo "[${SERVER}] Starting containers..."
local RECREATE="cd ~/netork && \
REGISTRY_HOST='${REGISTRY_HOST}' NETORK_VERSION='${SERVER_VERSION}' \
@@ -551,10 +556,11 @@ REMOTE_ENV
run_remote "$SERVER" "alembic upgrade head (containers are ALREADY swapped)" "" \
"cd ~/netork && docker compose exec -T netork-api alembic upgrade head"
# The images the swap replaced, and nothing else. This was `docker image prune
# -af`, which removes every image no container uses at that moment: on a host
# that runs other things too, their rollback images (NetOrk/kb-server#157).
# remote/remove_replaced_images.sh keeps any image a container still uses.
# The images this deploy replaced, and nothing else. This was `docker image
# prune -af`, which removes every image no container uses at that moment: on a
# host that runs other things too, their rollback images (NetOrk/kb-server#157).
# remote/remove_replaced_images.sh keeps any image a container still uses. Not
# earlier: until the deploy went through, the old images are the way back.
if [[ -n "$REPLACED" ]]; then
echo "[${SERVER}] Removing the images this deploy replaced..."
local ids="${REPLACED//$'\n'/ }"