The Docker prune of gitea_runner (tasks/prune.yml) removes only images older than gitea_runner_docker_prune_image_age, via docker image prune --all --filter until=<age>. An age limit does not cap disk use: the space the cache takes grows with how often new image versions are published. A runner whose job images get a new pinned version several times a day keeps every one of them for the whole retention window.
Image builds that run on the runner, such as kaniko compiling Go tools, need several GB of scratch space at the same time. When the cache has filled the disk, those builds fail partway through. Jobs can also fail at container setup. A shorter age only moves the limit; it still depends on how often images are released.
Proposal
Bound the cache by what is kept and by disk pressure, in the manner of kubelet image garbage collection. Decided in triage:
Keep the newest N image IDs per repository. A POSIX sh script, roles/gitea_runner/files/gitea-runner-docker-prune-keep (deployed with copy: src:), groups images by repository, orders image IDs by Created, and keeps the newest N. Every tag of a kept image stays. Images used by any container (docker ps -a) are always kept, and dangling images are always removed. N counts image IDs, not tags, so one image with several tags uses one slot.
Weekly service.gitea-runner-docker-prune.service keeps its age-based prunes unchanged and also runs the count prune when N > 0. An image is removed if either rule removes it.
Pressure path. A separate service and timer (hourly by default) runs behind the same job gate (ExecCondition= gate), plus a second ExecCondition= that checks the use of the filesystem holding docker info --format '{{.DockerRootDir}}' against the threshold. Above the threshold, it runs the count prune and docker builder prune --force --keep-storage <size> once. There is no low watermark: if usage stays high, N or the disk size needs a human. The builder cap is in scope because job containers use the host's docker.sock by default, so a job's docker build fills the host's build cache.
Turning it off. With the threshold at 0 and the prune enabled, the role stops the pressure timer and removes its units. tasks/remove.yml removes the new units and the script.
New inputs (all apply only when gitea_runner_docker_prune_enabled is true):
Input
Type
Default
Meaning
gitea_runner_docker_prune_keep_per_repository
int
0
newest N image IDs per repository; 0 = off
gitea_runner_docker_prune_disk_threshold_percent
int
0
usage % of the Docker root's filesystem that triggers the pressure prune; 0 = off
gitea_runner_docker_prune_disk_check_schedule
str
hourly
OnCalendar of the pressure timer
gitea_runner_docker_prune_builder_keep_storage
str
10GB
--keep-storage of the builder prune under pressure
validate.yml refuses a threshold outside 1–99, a threshold set while N is 0, and a schedule or size outside the character-set and unit checks the existing inputs use.
Acceptance criteria
The four inputs are in defaults/main.yml, argument_specs.yml, the README and validate.yml. With the defaults, behaviour is unchanged.
With N set, a runner holding M > N image IDs of one repository keeps exactly the newest N, plus any image a container uses. A multi-tag image counts once.
With the threshold set, the pressure prune runs when usage is above it and is skipped below it. The job gate still applies.
Setting the threshold back to 0 removes the pressure timer and its units. The remove path removes them and the script.
Molecule verifies the count script and the threshold condition against a stub docker that returns fixed image ls / ps / info output and records rmi calls. Cases: M > N, an image in use, a multi-tag image, and usage above and below the threshold. Molecule has no real Docker.
Changelog fragment (minor_changes).
Assisted-by: Claude Code:claude-opus-5-5
## Problem
The Docker prune of `gitea_runner` (`tasks/prune.yml`) removes only images older than `gitea_runner_docker_prune_image_age`, via `docker image prune --all --filter until=<age>`. An age limit does not cap disk use: the space the cache takes grows with how often new image versions are published. A runner whose job images get a new pinned version several times a day keeps every one of them for the whole retention window.
Image builds that run on the runner, such as kaniko compiling Go tools, need several GB of scratch space at the same time. When the cache has filled the disk, those builds fail partway through. Jobs can also fail at container setup. A shorter age only moves the limit; it still depends on how often images are released.
## Proposal
Bound the cache by what is kept and by disk pressure, in the manner of kubelet image garbage collection. Decided in triage:
1. **Keep the newest N image IDs per repository.** A POSIX sh script, `roles/gitea_runner/files/gitea-runner-docker-prune-keep` (deployed with `copy: src:`), groups images by repository, orders image IDs by `Created`, and keeps the newest N. Every tag of a kept image stays. Images used by any container (`docker ps -a`) are always kept, and dangling images are always removed. N counts image IDs, not tags, so one image with several tags uses one slot.
2. **Weekly service.** `gitea-runner-docker-prune.service` keeps its age-based prunes unchanged and also runs the count prune when N > 0. An image is removed if either rule removes it.
3. **Pressure path.** A separate service and timer (hourly by default) runs behind the same job gate (`ExecCondition=` gate), plus a second `ExecCondition=` that checks the use of the filesystem holding `docker info --format '{{.DockerRootDir}}'` against the threshold. Above the threshold, it runs the count prune and `docker builder prune --force --keep-storage <size>` once. There is no low watermark: if usage stays high, N or the disk size needs a human. The builder cap is in scope because job containers use the host's `docker.sock` by default, so a job's `docker build` fills the host's build cache.
4. **Turning it off.** With the threshold at `0` and the prune enabled, the role stops the pressure timer and removes its units. `tasks/remove.yml` removes the new units and the script.
New inputs (all apply only when `gitea_runner_docker_prune_enabled` is true):
| Input | Type | Default | Meaning |
|---|---|---|---|
| `gitea_runner_docker_prune_keep_per_repository` | int | `0` | newest N image IDs per repository; `0` = off |
| `gitea_runner_docker_prune_disk_threshold_percent` | int | `0` | usage % of the Docker root's filesystem that triggers the pressure prune; `0` = off |
| `gitea_runner_docker_prune_disk_check_schedule` | str | `hourly` | `OnCalendar` of the pressure timer |
| `gitea_runner_docker_prune_builder_keep_storage` | str | `10GB` | `--keep-storage` of the builder prune under pressure |
`validate.yml` refuses a threshold outside 1–99, a threshold set while N is `0`, and a schedule or size outside the character-set and unit checks the existing inputs use.
## Acceptance criteria
- [ ] The four inputs are in `defaults/main.yml`, `argument_specs.yml`, the README and `validate.yml`. With the defaults, behaviour is unchanged.
- [ ] With N set, a runner holding M > N image IDs of one repository keeps exactly the newest N, plus any image a container uses. A multi-tag image counts once.
- [ ] With the threshold set, the pressure prune runs when usage is above it and is skipped below it. The job gate still applies.
- [ ] Setting the threshold back to `0` removes the pressure timer and its units. The remove path removes them and the script.
- [ ] Molecule verifies the count script and the threshold condition against a stub `docker` that returns fixed `image ls` / `ps` / `info` output and records `rmi` calls. Cases: M > N, an image in use, a multi-tag image, and usage above and below the threshold. Molecule has no real Docker.
- [ ] Changelog fragment (`minor_changes`).
Assisted-by: Claude Code:claude-opus-5-5
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.
Problem
The Docker prune of
gitea_runner(tasks/prune.yml) removes only images older thangitea_runner_docker_prune_image_age, viadocker image prune --all --filter until=<age>. An age limit does not cap disk use: the space the cache takes grows with how often new image versions are published. A runner whose job images get a new pinned version several times a day keeps every one of them for the whole retention window.Image builds that run on the runner, such as kaniko compiling Go tools, need several GB of scratch space at the same time. When the cache has filled the disk, those builds fail partway through. Jobs can also fail at container setup. A shorter age only moves the limit; it still depends on how often images are released.
Proposal
Bound the cache by what is kept and by disk pressure, in the manner of kubelet image garbage collection. Decided in triage:
roles/gitea_runner/files/gitea-runner-docker-prune-keep(deployed withcopy: src:), groups images by repository, orders image IDs byCreated, and keeps the newest N. Every tag of a kept image stays. Images used by any container (docker ps -a) are always kept, and dangling images are always removed. N counts image IDs, not tags, so one image with several tags uses one slot.gitea-runner-docker-prune.servicekeeps its age-based prunes unchanged and also runs the count prune when N > 0. An image is removed if either rule removes it.ExecCondition=gate), plus a secondExecCondition=that checks the use of the filesystem holdingdocker info --format '{{.DockerRootDir}}'against the threshold. Above the threshold, it runs the count prune anddocker builder prune --force --keep-storage <size>once. There is no low watermark: if usage stays high, N or the disk size needs a human. The builder cap is in scope because job containers use the host'sdocker.sockby default, so a job'sdocker buildfills the host's build cache.0and the prune enabled, the role stops the pressure timer and removes its units.tasks/remove.ymlremoves the new units and the script.New inputs (all apply only when
gitea_runner_docker_prune_enabledis true):gitea_runner_docker_prune_keep_per_repository00= offgitea_runner_docker_prune_disk_threshold_percent00= offgitea_runner_docker_prune_disk_check_schedulehourlyOnCalendarof the pressure timergitea_runner_docker_prune_builder_keep_storage10GB--keep-storageof the builder prune under pressurevalidate.ymlrefuses a threshold outside 1–99, a threshold set while N is0, and a schedule or size outside the character-set and unit checks the existing inputs use.Acceptance criteria
defaults/main.yml,argument_specs.yml, the README andvalidate.yml. With the defaults, behaviour is unchanged.0removes the pressure timer and its units. The remove path removes them and the script.dockerthat returns fixedimage ls/ps/infooutput and recordsrmicalls. Cases: M > N, an image in use, a multi-tag image, and usage above and below the threshold. Molecule has no real Docker.minor_changes).Assisted-by: Claude Code:claude-opus-5-5