feat(container-prune): prune unused images weekly #61
No reviewers
Labels
No labels
bug
cannot reproduce
duplicate
enhancement
help wanted
invalid
need info
need triage
need verification
not a bug
question
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
claudiomaradonna/castrum!61
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/container-prune"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
Hosts that run containers with Docker or Podman keep every image they
ever pulled or built, and Docker also keeps its build cache. After a few
days of deploys this takes a lot of disk, and nothing in castrum cleans
it up: today someone has to log in and run
pruneby hand.What changed
A new service role,
container-prune, switched on per host withcontainer_prune_enabled. It installscontainer-prune.serviceand aweekly
container-prune.timer(persistent, with a random delay of up toan hour). Where
docker_engine_enabledis set, the service runsdocker image prune -aanddocker builder prune. Wherepodman_enabledis set, it runspodman image prune -aon root'sstorage. Each command gets
--force --filter until=168h. Volumes,containers and networks are never pruned. The age, the calendar and the
delay are role variables.
A host with the flag on and neither engine flag fails the run at this
role, before any unit is written, also under
--check. The role honoursupdate_only. The loader includes it afterdocker-engine.The role's README explains:
untilreads an image's creation time, not its last use;How to verify
Prerequisites: the Setup toolchain, and
rootless podman for molecule. Base
main(d793429); branchfeat/container-prune../tests/molecule/run.sh roles/container-prunebuilds a Debian 12container running systemd, with stub
dockerandpodmanthat logtheir arguments. It applies the role twice and checks that the second
run changes nothing. It then checks that the timer is enabled and
active, starts the service, and compares the logged commands with the
three expected ones. Run on the branch: exit 0, no
^ERRORline. Onmainit fails, because the role does not exist../tests/gates/check_container_prune.shcovers three cases. With theflag on and no engine flag, the run fails before the units, also
under
--check, naming the flags. With the flag off, or underupdate_only=true, no task runs. Passes on the branch. It fails onthe first commit, which has no refusal ("the failure does not name the
flags"), and on
main.make checkpasses on every commit of the branch, all gates included.The molecule scenario above is the only part of
make testthat thischange touches.
Considerations
untilreads creation time, so it mostly protects images built onthe host. An image of a compose stack taken down, or of a swarm
service scaled to zero or running on other nodes, is removed. It is
pulled again when next needed, which needs the registry and, on
swarm, its credentials. The README says to leave the flag off where
the registry cannot be relied on.
/var/lib/containersis pruned.docker-engineis inassertmode,because it does not touch the engine's configuration or packages.
flag-gated role. The README gives the removal commands.
docker builder pruneruns without--all, so only dangling buildcache is removed.
weeklyin its normalized form, and the goal asks only for anenabled, active timer.
the controller's
/etcuntouched, and an override would add avariable.
Command failed
The agent did not complete this command, so nothing came of it. A person should look at this thread.
The run failed at step "aoe_purge". The operator reads the job logs in the Windmill editor, or finds the run with:
wmill job list --path f/agents/bot_commands