Files
computer-playbook/scripts/container/purge/entity/README.md
kevinveenbirkenbachandClaude Opus 4.7 d1de165e9c feat(purge): drop orphan default networks per entity + global prune
`docker compose down --remove-orphans` only deletes networks that
compose itself created (those carrying
`com.docker.compose.network=default` + `com.docker.compose.project=<name>`
labels). When the per-entity default network ends up unlabeled or
project-mislabeled — typical after an inter-round matrix-deploy
purge, or when a `community.docker.docker_network` Ansible call
materialised the network before compose ran — compose deliberately
leaves it untouched, and a subsequent `compose up` aborts with
  network <entity> was found but has incorrect label
  com.docker.compose.network set to "" (expected: "default")
The matrix-deploy CI rounds for web-app-matrix, web-app-gitea and
others reliably reproduce this.

Add a new entity-keyed purge primitive
`scripts/container/purge/entity/network.sh <ENTITY>` that runs after
the compose / dir / nginx primitives. It is idempotent: no-op when
the network does not exist, skips removal while active container
endpoints prove the network belongs to a shared service still in
use (svc-db-mariadb, svc-db-postgres, svc-db-openldap, svc-ai-ollama,
…), and otherwise drops the orphan network with `docker network rm`.
`docker network rm` failures are logged and tolerated — the next
`compose up` will surface the same problem with an actionable error.

Wire the primitive into `scripts/container/purge/apps.sh` immediately
after the existing `nginx.sh` call, so every entity-keyed purge
collects its own default network on the same pass.

Finally, after the entity loop, run a single bare `docker network
prune -f` to sweep orphan networks whose name does NOT correspond
to a purged entity (left over from renamed roles, abandoned
matrix-deploy rounds, etc.). The sweep is bare on purpose — no
`|| true` guard — so a daemon-side prune failure aborts the purge
loudly via the script's `set -euo pipefail`. Performance: ~13× faster
than calling prune inside `network.sh` per entity (one ~200 ms
listing pass vs. N × 200 ms for N entities).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 11:45:44 +02:00

1.5 KiB

Entity Purge 🗑️

Entity-keyed purge primitives for stack-level cleanup inside the running container.

For the canonical Make target index that invokes these helpers, see make.md.

Entry Points 🎯

Script What it does Key inputs
compose.sh Stops the compose stack and removes volumes. Stack names
db.sh Drops or truncates the backing database. Stack names, --wipe-data-only
dir.sh Removes the stack directory and its volumes. Stack names
nginx.sh Removes the per-domain nginx vhost files (http + https) belonging to every app under the entity. Thin wrapper around nginx_vhosts.py. Stack names
network.sh Drops the per-entity default Docker network when compose.sh left it behind with the wrong / empty com.docker.compose.network label (typical between matrix-deploy rounds). Skips removal when the network still has active container endpoints, so shared-service networks (svc-db-mariadb, svc-db-postgres, …) stay in place while their provider container is up. The global docker network prune -f sweep that catches orphans whose names do NOT match the entity is run once by the orchestrator apps.sh after the entity loop. Idempotent. Stack name

These primitives are entity-keyed. The app-keyed orchestrator apps.sh maps app ids to entities and drives them in sequence alongside the token-store wipe in tokens.py.