fix: remove only the images the deploy replaced, never every unused one #16

Merged
christianmanivong merged 3 commits from fix/remove-only-replaced-images into main 2026-12-02 16:31:23 +00:00
Owner

Summary

The deploy ended with docker image prune -af: every image no container uses at that moment, on a host that may run other things too. The KB's copy of the same line took the license server's rollback images on compute-01 on 2026-10-23 (NetOrk/kb-server#157). The line came from here, written when every target was netOrk's alone. On a customer host that also runs other things, it removes their images too.

Changes

  • Before the database step, the first that can replace a container, deploy.sh records the image IDs of every container of the compose project netork, by its label (docker ps -aq --filter label=com.docker.compose.project=netork). That covers the engine, postgres (behind its compose profile), the broker, apt-cacher-ng, signal-api and a retired service such as the old registry. Only lines that are image IDs are kept, because they are expanded into the removal command.
  • After the verification and the migration it hands those IDs to the new remote/remove_replaced_images.sh. The script removes each image by its tags, or by its ID once a moving tag such as latest-dev left it without one. It keeps any image a container (netOrk's or anyone else's) still uses, without a word: a redeploy of the same tag, or an unchanged database, replaces nothing. It names only what it removed or could not remove.
  • A deploy that fails before the end removes nothing, so the previous images stay for the way back.
  • README step 13 describes the new behaviour (steps renumbered after the merge of main, with the database login from #17 as step 6).

Testing

  • tests/test_remote_replaced_images.py runs the script against a fake docker:
    • the replaced release goes by every tag;
    • an image in use stays, and nothing is printed for it;
    • another project's image is never named;
    • an untagged leftover goes by its ID;
    • nothing to remove is no failure.
  • tests/test_deploy_replaced_images.py, against a fake ssh:
    • no image prune;
    • the record is taken after the pull and before the database step, the broker and the swap;
    • it covers the whole compose project by label;
    • removal comes after the verification and the migration, through the script;
    • a failed migration removes nothing;
    • an empty record means no removal step;
    • only image IDs reach the remote command line.
  • Full suite: 95 passed. ruff format --check, ruff check and shellcheck 0.11.0 on deploy.sh and remote/*.sh are clean.
## Summary The deploy ended with `docker image prune -af`: every image no container uses at that moment, on a host that may run other things too. The KB's copy of the same line took the license server's rollback images on compute-01 on 2026-10-23 (NetOrk/kb-server#157). The line came from here, written when every target was netOrk's alone. On a customer host that also runs other things, it removes their images too. ## Changes - Before the database step, the first that can replace a container, `deploy.sh` records the image IDs of every container of the compose project `netork`, by its label (`docker ps -aq --filter label=com.docker.compose.project=netork`). That covers the engine, postgres (behind its compose profile), the broker, `apt-cacher-ng`, `signal-api` and a retired service such as the old registry. Only lines that are image IDs are kept, because they are expanded into the removal command. - After the verification and the migration it hands those IDs to the new `remote/remove_replaced_images.sh`. The script removes each image by its tags, or by its ID once a moving tag such as `latest-dev` left it without one. It keeps any image a container (netOrk's or anyone else's) still uses, without a word: a redeploy of the same tag, or an unchanged database, replaces nothing. It names only what it removed or could not remove. - A deploy that fails before the end removes nothing, so the previous images stay for the way back. - README step 13 describes the new behaviour (steps renumbered after the merge of main, with the database login from #17 as step 6). ## Testing - `tests/test_remote_replaced_images.py` runs the script against a fake `docker`: - the replaced release goes by every tag; - an image in use stays, and nothing is printed for it; - another project's image is never named; - an untagged leftover goes by its ID; - nothing to remove is no failure. - `tests/test_deploy_replaced_images.py`, against a fake `ssh`: - no `image prune`; - the record is taken after the pull and before the database step, the broker and the swap; - it covers the whole compose project by label; - removal comes after the verification and the migration, through the script; - a failed migration removes nothing; - an empty record means no removal step; - only image IDs reach the remote command line. - Full suite: 95 passed. `ruff format --check`, `ruff check` and shellcheck 0.11.0 on `deploy.sh` and `remote/*.sh` are clean.
christianmanivong added 1 commit 2026-10-23 10:08:03 +00:00
The deploy ended with docker image prune -af: every image no container
used at that moment. On a host that runs other things too, that takes
their rollback images; the KB's copy of this line did exactly that on
compute-01 (NetOrk/kb-server#157).

deploy.sh now records the image IDs netOrk's own containers use before
the swap and, after the verification and the migration, hands them to
remote/remove_replaced_images.sh. It removes each by its tags, or by its
ID once a moving tag left it without one, and keeps any image a
container still uses: a redeploy of the same tag replaces nothing.
christianmanivong added 2 commits 2026-12-02 16:27:07 +00:00
README: main's restricted database login (#17) became step 6, so the
migration is step 12 and the removal of the replaced images step 13.
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.
christianmanivong merged commit b565232a0e into main 2026-12-02 16:31:23 +00:00
christianmanivong deleted branch fix/remove-only-replaced-images 2026-12-02 16:31:23 +00:00
Sign in to join this conversation.