build-image: Reste fehlgeschlagener Builds sofort entfernen #56

Merged
kevinheyer merged 1 commit from cleanup-failed-build-leftovers into main 2026-11-18 16:27:41 +01:00
Member

Ein fehlgeschlagener oder abgebrochener Image-Build hinterlässt kein rohes Image mehr auf dem Runner (iac-core#52).

  • tools/build-image.sh, tools/build-base-image.sh: EXIT-Trap (auch bei TERM, INT, HUP) entfernt das rohe Image, die Kopie des Basis-Images und das gesicherte Volume.
  • tools/runner/iac-runner-cleanup: ohne laufenden Build gehen Dateien und Workspaces ab 30 Minuten Alter (vorher: ein Tag), auch volume-*.raw.backup; base/ bleibt.
  • docs/RUNNER.md beschreibt das neue Verhalten.

Geprüft: Auf dem Runner scheiterte ein Build von iac-stump mit zu kleinem Ausgabeverzeichnis (64 MB) im Komprimieren; danach lagen weder .raw noch Kopie der Basis im Workspace. iac-runner-cleanup mit Test-Workspace (alt, frisch, base/, laufender Build). tools/lint.sh grün. Das neue iac-runner-cleanup ist am 2026-11-18 auf dem Runner installiert (Sicherung der alten Version: /root/iac-runner-cleanup.bak-20261118).

Nicht geprüft: Abbruch eines Builds per TERM auf dem Runner, SIGKILL (kein Trap, dafür bleibt das Cleanup), eine ganze Nacht mit vielen Fehlschlägen.

Der Branch baut auf base-image (PR #55) auf und enthält dessen Commits; #53 und #55 zuerst mergen, dann bleibt hier nur der Commit zu #52.

Refs #52

Ein fehlgeschlagener oder abgebrochener Image-Build hinterlässt kein rohes Image mehr auf dem Runner (iac-core#52). - `tools/build-image.sh`, `tools/build-base-image.sh`: `EXIT`-Trap (auch bei `TERM`, `INT`, `HUP`) entfernt das rohe Image, die Kopie des Basis-Images und das gesicherte Volume. - `tools/runner/iac-runner-cleanup`: ohne laufenden Build gehen Dateien und Workspaces ab 30 Minuten Alter (vorher: ein Tag), auch `volume-*.raw.backup`; `base/` bleibt. - `docs/RUNNER.md` beschreibt das neue Verhalten. **Geprüft:** Auf dem Runner scheiterte ein Build von iac-stump mit zu kleinem Ausgabeverzeichnis (64 MB) im Komprimieren; danach lagen weder `.raw` noch Kopie der Basis im Workspace. `iac-runner-cleanup` mit Test-Workspace (alt, frisch, `base/`, laufender Build). `tools/lint.sh` grün. Das neue `iac-runner-cleanup` ist am 2026-11-18 auf dem Runner installiert (Sicherung der alten Version: `/root/iac-runner-cleanup.bak-20261118`). **Nicht geprüft:** Abbruch eines Builds per `TERM` auf dem Runner, `SIGKILL` (kein Trap, dafür bleibt das Cleanup), eine ganze Nacht mit vielen Fehlschlägen. Der Branch baut auf `base-image` (PR #55) auf und enthält dessen Commits; #53 und #55 zuerst mergen, dann bleibt hier nur der Commit zu #52. Refs #52
Print the duration of the steps at the end of build-image.sh
All checks were successful
/ lint (push) Successful in 23s
/ lint (pull_request) Successful in 25s
9d2d185a7c
The build log only shows task names, so it was unclear where an image
build spends its time. build-image.sh now prints the seconds of each
step (prepare sources, bootstrap-vz, compress) when it ends, also when
it fails. The wait for the build lock is part of the bootstrap-vz step.

Tested: bash -n and shellcheck -x (only the existing SC1091 note about
core.func). Ran it on the CI runner for iac-stump (main): 1 s prepare,
901 s bootstrap-vz, 37 s compress; the image was built. Refs #51
Start app images from a daily base image instead of debootstrap
All checks were successful
/ lint (push) Successful in 13s
/ lint (pull_request) Successful in 11s
3b23054b1f
Every app image ran debootstrap and the package installation again,
720 of 900 seconds of bootstrap-vz for iac-stump. build-base-image.sh
now builds Debian plus the package lists once (bootstrap-vz plugin
prebootstrapped saves the volume after the package installation) and
keeps it in /srv/bootstrap-vz/base. build-image.sh copies it, grows
it to image.size (grow-image.sh) and runs bin/iac-install in it.

The base is built daily at 20:30 UTC by base-image.yml, before the
nightly app builds at 22:00 UTC. As a safety net build-image.sh builds
a missing base, one older than 26 hours or one whose image/base.yml,
package lists or render-manifest.py changed, before the app. Both
hold the build lock, so a base is never replaced while an app uses it.
Apps with their own image/manifest.yml build from scratch as before.

Tested on the CI runner: iac-stump on the base: bootstrap-vz 166 s
instead of 901 s, same 276 packages, boot test identical to an image
built the old way (both fail on the known first start of stump).
iac-netbox (8 GiB): grown base, boot test and smoke test green.
The three states of the base check (none, too old, changed inputs)
tested with a stub; tools/lint.sh is green. The workflow base-image.yml
runs only after v2 contains these scripts; not run yet.

Refs #51
Remove the raw image of a failed image build at once
All checks were successful
/ lint (pull_request) Successful in 16s
/ lint (push) Successful in 16s
bb9b386f43
build-image.sh deleted its raw image only after a successful compress.
A build that failed or was stopped before (for example "No space left
on device" in qemu-img) left 3 to 10 GiB in /srv/bootstrap-vz, and
iac-runner-cleanup only removed it once it was older than a day, so
up to 48 hours later. After a night in which many builds fail the disk
could fill up.

build-image.sh and build-base-image.sh now remove what they leave in
the workspace (raw image, copy of the base image, saved volume) in an
EXIT trap that also runs on TERM, INT and HUP. iac-runner-cleanup is
the net for a job killed without its traps: with no build running,
files and workspaces older than 30 minutes go (before: a day), the
saved volumes of the base image included; base/ stays.

Tested: a build with an output directory that is too small (64 MB
tmpfs) failed in qemu-img on the CI runner and left no raw image and no
copy of the base in /srv/bootstrap-vz. iac-runner-cleanup tested with
a temporary workspace (old files, fresh files, base/ and a running
build); tools/lint.sh is green. The new iac-runner-cleanup is not
installed on the runner yet.

Refs #52
Sign in to join this conversation.
No description provided.