fix(build): stop the builder container when the build exits

An idle builder keeps the Docker Desktop VM ballooned: each per-worktree
compose project carries its own ${KICAD_DOCKER_MEM:-32G} cap, build.sh left
the container running afterwards ("interactive use"), and two forgotten
builders plus the VM's page-cache/high-water behavior read as ~56 GB of host
RAM during a ~20 GB build.

stop_builder() now runs from the EXIT trap on every path (success, failure,
Ctrl-C — both the sequential and the pipeline-mode trap). The container is
pure scaffolding — all caches live in the named volumes and `up -d` restarts
it in seconds — so stopping costs nothing. KICAD_KEEP_CONTAINER=1 restores
the old keep-running behavior for interactive debugging; docker/shell.sh is
unaffected (it does its own `up -d`).

Verified live: the full `all --build-deps` run on main left zero containers
running at exit.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Viktor Vaczi 2026-07-03 14:42:38 +02:00
commit 1a24c2894e
2 changed files with 20 additions and 3 deletions

View file

@ -31,7 +31,10 @@ services:
# Output directory for easy access to final WASM files
- ../output:/workspace/output
# Keep container running for interactive use
# Keep the container alive so build.sh can `exec` its stages into it.
# build.sh STOPS it when the build exits (idle builders keep the Docker
# Desktop VM ballooned — 32G cap per per-worktree compose project); set
# KICAD_KEEP_CONTAINER=1 to keep it running afterwards for interactive use.
stdin_open: true
tty: true