An age-based prune does not cap disk use. The cache grows with how often new image versions are published, so builds on the runner can fail for lack of space. This adds two bounds, both off by default:
Count prune (gitea_runner_docker_prune_keep_per_repository): a POSIX sh script, files/gitea-runner-docker-prune-keep, keeps the newest N image IDs per repository, ordered by Created.
A multi-tag image counts once, and an ID kept by any of its repositories stays.
Images used by any container (ps --all) are never removed. Dangling images are removed.
If any listing fails, nothing is removed.
The weekly service runs it alongside the existing age prunes, which are unchanged.
Pressure prune (gitea_runner_docker_prune_disk_threshold_percent, _disk_check_schedule, _builder_keep_storage): a separate gitea-runner-docker-prune-pressure.service and .timer, hourly by default.
It sits behind the same job gate, plus a second ExecCondition=, files/gitea-runner-docker-prune-disk-check, which passes only when the filesystem holding DockerRootDir is above the threshold.
When it fires, it runs the count prune and docker builder prune --keep-storage once.
Setting the threshold back to 0 removes the timer, both units and the script.
Validation:validate.yml refuses a threshold outside 1–99, a threshold without a count, and a bad schedule or size, each with its own message.
Removal:remove.yml removes everything new.
Changelog: a minor_changes fragment.
Verified
pre-commit run --all-files: all hooks pass.
ansible-test sanity: passes. It ran on the pre-push hook for this push.
The keep script and the disk check, run locally against a stub docker with the verify fixtures, give the expected rmi set and exit codes.
Keep script cases: M > N, an old image in use, a multi-tag image, an ID in two repositories, a dangling image, an in-use dangling image, each listing failing, and N=0.
Disk check cases: above, at, and below the threshold; docker info failing; a missing root.
tasks/validate.yml, run on its own: defaults pass, and each refused input fails with its own message.
--keep-storage is a current, non-deprecated flag of docker builder prune (checked in docker/cli cli/command/builder/prune.go).
Two review passes, Standards and Spec against #319, found nothing blocking. Their findings are addressed in the follow-up commits.
Molecule default (adds stub-docker cases for both scripts, threshold 0 → off → on, and the remove path): runs in CI on this PR.
Not verified
Molecule: not run locally, because there is no container runtime. The new verify plays and the real systemd behaviour of the pressure units are first exercised by CI on this PR.
Docker's containerd image store (the default on fresh Docker 29 installs): not checked on a real host. The keep script assumes image ls --no-trunc{{.ID}} equals container inspect{{.Image}}. Worth one dry run with rmi replaced by echo on such a runner.
docker builder prune --keep-storage without --all (as #319 specifies): it may only consider part of the build cache, so I can't say whether the cap fully holds against heavy docker build cache. docker system df -v on a runner would show it.
Race window: there are a few seconds between the listing and rmi, the same window the weekly prune already documents. A container started in that window keeps its image, but a multi-tag image can lose its tags and be re-pulled.
I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.
Assisted-by: Claude Code
## What and why
Closes #319
An age-based prune does not cap disk use. The cache grows with how often new image versions are published, so builds on the runner can fail for lack of space. This adds two bounds, both off by default:
- **Count prune** (`gitea_runner_docker_prune_keep_per_repository`): a POSIX sh script, `files/gitea-runner-docker-prune-keep`, keeps the newest N image IDs per repository, ordered by `Created`.
- A multi-tag image counts once, and an ID kept by any of its repositories stays.
- Images used by any container (`ps --all`) are never removed. Dangling images are removed.
- If any listing fails, nothing is removed.
- The weekly service runs it alongside the existing age prunes, which are unchanged.
- **Pressure prune** (`gitea_runner_docker_prune_disk_threshold_percent`, `_disk_check_schedule`, `_builder_keep_storage`): a separate `gitea-runner-docker-prune-pressure.service` and `.timer`, hourly by default.
- It sits behind the same job gate, plus a second `ExecCondition=`, `files/gitea-runner-docker-prune-disk-check`, which passes only when the filesystem holding `DockerRootDir` is above the threshold.
- When it fires, it runs the count prune and `docker builder prune --keep-storage` once.
- Setting the threshold back to `0` removes the timer, both units and the script.
- **Validation:** `validate.yml` refuses a threshold outside 1–99, a threshold without a count, and a bad schedule or size, each with its own message.
- **Removal:** `remove.yml` removes everything new.
- **Changelog:** a `minor_changes` fragment.
## Verified
- `pre-commit run --all-files`: all hooks pass.
- `ansible-test sanity`: passes. It ran on the pre-push hook for this push.
- The keep script and the disk check, run locally against a stub `docker` with the verify fixtures, give the expected `rmi` set and exit codes.
- Keep script cases: M > N, an old image in use, a multi-tag image, an ID in two repositories, a dangling image, an in-use dangling image, each listing failing, and N=0.
- Disk check cases: above, at, and below the threshold; `docker info` failing; a missing root.
- `tasks/validate.yml`, run on its own: defaults pass, and each refused input fails with its own message.
- `--keep-storage` is a current, non-deprecated flag of `docker builder prune` (checked in docker/cli `cli/command/builder/prune.go`).
- Two review passes, Standards and Spec against #319, found nothing blocking. Their findings are addressed in the follow-up commits.
- Molecule `default` (adds stub-docker cases for both scripts, threshold 0 → off → on, and the remove path): runs in CI on this PR.
## Not verified
- **Molecule:** not run locally, because there is no container runtime. The new verify plays and the real systemd behaviour of the pressure units are first exercised by CI on this PR.
- **Docker's containerd image store** (the default on fresh Docker 29 installs): not checked on a real host. The keep script assumes `image ls --no-trunc` `{{.ID}}` equals `container inspect` `{{.Image}}`. Worth one dry run with `rmi` replaced by `echo` on such a runner.
- **`docker builder prune --keep-storage` without `--all`** (as #319 specifies): it may only consider part of the build cache, so I can't say whether the cap fully holds against heavy `docker build` cache. `docker system df -v` on a runner would show it.
- **Race window:** there are a few seconds between the listing and `rmi`, the same window the weekly prune already documents. A container started in that window keeps its image, but a multi-tag image can lose its tags and be re-pulled.
---
- [ ] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none.
Assisted-by: Claude Code
Defame1297
was assigned by Claude2026-11-23 18:39:15 +00:00
An age-based prune does not cap disk use: the cache grows with how often
new image versions are published, and builds on the runner then fail for
lack of space. Keep the newest N image IDs per repository in the weekly
prune, and add an hourly pressure prune that runs the count prune and a
capped builder prune when the Docker root's filesystem passes a
threshold, behind the same job gate. Both are off by default.
Refs #319
Assisted-by: Claude Code
Give each new input its own assert message so every refused-input case
matches only its own input, and cover a negative count and a bad disk
check schedule. Fire the pressure prune only above the threshold, as
the inputs describe it. Name the disk check script apart from the
pressure service, prefix the new registers as internal, and keep the
new comments short.
Refs #319
Assisted-by: Claude Code
The weekly schedule and image age cases matched text the disk check
schedule message also holds; match each assert's own message. Add a
case at exactly the root's use so the strict comparison is pinned, and
check the below message so a df failure cannot pass for it.
Refs #319
Assisted-by: Claude Code
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What and why
Closes #319
An age-based prune does not cap disk use. The cache grows with how often new image versions are published, so builds on the runner can fail for lack of space. This adds two bounds, both off by default:
gitea_runner_docker_prune_keep_per_repository): a POSIX sh script,files/gitea-runner-docker-prune-keep, keeps the newest N image IDs per repository, ordered byCreated.ps --all) are never removed. Dangling images are removed.gitea_runner_docker_prune_disk_threshold_percent,_disk_check_schedule,_builder_keep_storage): a separategitea-runner-docker-prune-pressure.serviceand.timer, hourly by default.ExecCondition=,files/gitea-runner-docker-prune-disk-check, which passes only when the filesystem holdingDockerRootDiris above the threshold.docker builder prune --keep-storageonce.0removes the timer, both units and the script.validate.ymlrefuses a threshold outside 1–99, a threshold without a count, and a bad schedule or size, each with its own message.remove.ymlremoves everything new.minor_changesfragment.Verified
pre-commit run --all-files: all hooks pass.ansible-test sanity: passes. It ran on the pre-push hook for this push.dockerwith the verify fixtures, give the expectedrmiset and exit codes.docker infofailing; a missing root.tasks/validate.yml, run on its own: defaults pass, and each refused input fails with its own message.--keep-storageis a current, non-deprecated flag ofdocker builder prune(checked in docker/clicli/command/builder/prune.go).default(adds stub-docker cases for both scripts, threshold 0 → off → on, and the remove path): runs in CI on this PR.Not verified
image ls --no-trunc{{.ID}}equalscontainer inspect{{.Image}}. Worth one dry run withrmireplaced byechoon such a runner.docker builder prune --keep-storagewithout--all(as #319 specifies): it may only consider part of the build cache, so I can't say whether the cap fully holds against heavydocker buildcache.docker system df -von a runner would show it.rmi, the same window the weekly prune already documents. A container started in that window keeps its image, but a multi-tag image can lose its tags and be re-pulled.NOTICEandREUSE.toml, or there is none.Assisted-by: Claude Code