Merge branch 'main' into feat/322-unattended-blacklist
This commit is contained in:
commit
163bb21f40
35 files changed
+723
-28
No files matched your search
@@ -31,7 +31,7 @@ jobs:
|
||||
timeout-minutes: 30
|
||||
# The ci image (images/ci, built by image.yml): tag for the release, digest enforced.
|
||||
container:
|
||||
image: git.rkdr.net/mortis/ci:0.2.34@sha256:7e0e5ece9660dc14c638e461766b91650db979b4e72a177b5806dd7598907c4b
|
||||
image: git.rkdr.net/mortis/ci:0.2.35@sha256:307d51be744f3be5965af8783e88bd3fdda911dd53bb8a939d0710256e2e97d3
|
||||
env:
|
||||
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
||||
steps:
|
||||
|
||||
@@ -44,7 +44,7 @@ jobs:
|
||||
# The ci image (images/ci, built by image.yml), at the pin of lint.yml: tag for the
|
||||
# release, digest enforced. Only its /opt/venv Python (with PyYAML) is used here.
|
||||
container:
|
||||
image: git.rkdr.net/mortis/ci:0.2.34@sha256:7e0e5ece9660dc14c638e461766b91650db979b4e72a177b5806dd7598907c4b
|
||||
image: git.rkdr.net/mortis/ci:0.2.35@sha256:307d51be744f3be5965af8783e88bd3fdda911dd53bb8a939d0710256e2e97d3
|
||||
steps:
|
||||
# The container has no Node, so JavaScript actions such as actions/checkout
|
||||
# cannot run; clone with git and the job token.
|
||||
|
||||
@@ -87,7 +87,7 @@ jobs:
|
||||
dockerfile: Dockerfile
|
||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||
- name: ci
|
||||
version: 0.2.35
|
||||
version: 0.2.37
|
||||
subpath: ""
|
||||
dockerfile: images/ci/Dockerfile
|
||||
job_image: ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db
|
||||
|
||||
@@ -35,7 +35,7 @@ jobs:
|
||||
# The tag says which release, the digest is what is enforced (bump both together
|
||||
# when image.yml publishes a new version).
|
||||
container:
|
||||
image: git.rkdr.net/mortis/ci:0.2.34@sha256:7e0e5ece9660dc14c638e461766b91650db979b4e72a177b5806dd7598907c4b
|
||||
image: git.rkdr.net/mortis/ci:0.2.35@sha256:307d51be744f3be5965af8783e88bd3fdda911dd53bb8a939d0710256e2e97d3
|
||||
env:
|
||||
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
||||
PRE_COMMIT_HOME: /opt/pre-commit
|
||||
|
||||
@@ -70,7 +70,7 @@ jobs:
|
||||
# Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run
|
||||
# one locally.
|
||||
MOLECULE_IMAGE: >-
|
||||
git.rkdr.net/mortis/molecule-ubuntu2404:0.1.8@sha256:e1ea7c6f953626c39d9f578d60a1ef668f09ed4e5d537d5c7601668b5c5e0eb3
|
||||
git.rkdr.net/mortis/molecule-ubuntu2404:0.1.9@sha256:2687d921fdcadf49c36bd7a3b01eaf5f2a53fa0e8f9ed91b2c7ab0631022193b
|
||||
# The same for Ubuntu 26.04, the release the hosts are moving to; used by
|
||||
# `image: ${MOLECULE_IMAGE_2604}` in extensions/molecule/image-smoke-2604.
|
||||
MOLECULE_IMAGE_2604: >-
|
||||
|
||||
+11
-1
@@ -68,7 +68,7 @@ repos:
|
||||
# --offline: no network audits, so a run needs no token and gives the same result everywhere.
|
||||
# Overriding args drops the hook's default, so --no-progress is repeated here.
|
||||
- repo: https://github.com/zizmorcore/zizmor-pre-commit
|
||||
rev: 0eb9e4a60caf04df64b499ed1e8bef55f4440eae # frozen: v1.33.0
|
||||
rev: c7d31dc612dffdd4d3b2f2b88b9660d3ab057ee8 # frozen: v1.33.1
|
||||
hooks:
|
||||
- id: zizmor
|
||||
args: [--no-progress, --offline]
|
||||
@@ -126,6 +126,16 @@ repos:
|
||||
require_serial: true
|
||||
fail_fast: true
|
||||
|
||||
# apm compile (target claude), a tool's project init or a skill can create a CLAUDE.md, and
|
||||
# the failure is silent: the agent gets no guidance and no error.
|
||||
- id: refuse-claude-md
|
||||
name: Refuse CLAUDE.md files
|
||||
description: refuse CLAUDE.md, CLAUDE.local.md and .claude/CLAUDE.md at any depth
|
||||
entry: a CLAUDE.md file makes Claude Code ignore every AGENTS.md; delete it
|
||||
language: fail
|
||||
files: (^|/)(\.claude/)?CLAUDE(\.local)?\.md$
|
||||
stages: ['pre-commit']
|
||||
|
||||
- repo: meta
|
||||
hooks:
|
||||
- id: check-hooks-apply
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
minor_changes:
|
||||
- >-
|
||||
docker - ``docker_apt_arch`` now defaults to an empty value that derives the apt architecture from the host (``x86_64`` gives ``amd64``,
|
||||
``aarch64`` gives ``arm64``) instead of always writing ``amd64``, so an arm64 host no longer needs an override. A value set in the inventory
|
||||
is used as before. A host with any other architecture fails the play with a message that names ``docker_apt_arch`` instead of getting an
|
||||
``amd64`` source line that its apt cannot use; set ``docker_apt_arch`` for such a host.
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
minor_changes:
|
||||
- >-
|
||||
gitea_runner - The Docker prune can bound the image cache by count and by disk use. With
|
||||
``gitea_runner_docker_prune_keep_per_repository`` above 0 the weekly prune keeps the newest N image IDs of each
|
||||
repository and removes every other image no container uses. With ``gitea_runner_docker_prune_disk_threshold_percent``
|
||||
set, a timer (``gitea_runner_docker_prune_disk_check_schedule``, hourly by default) runs the count prune and a builder
|
||||
prune capped at ``gitea_runner_docker_prune_builder_keep_storage`` when the filesystem holding the Docker root is
|
||||
fuller than that, behind the same job gate as the weekly prune. Both are off by default.
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
bugfixes:
|
||||
- >-
|
||||
system_baseline - Do not run the apt upgrade in check mode in the main flow. A package that is only waiting for the next patch run, or a
|
||||
package cache older than an hour, is not drift, but the package module reports both as changed, so a scheduled dry run flagged every
|
||||
host. Autoremove and autoclean are now a task of their own and stay checked; as part of the upgrade call the module did not reach
|
||||
autoclean, so ``apt-get autoclean`` now runs (and may report changed once on a host with stale archives), in the main flow and in the
|
||||
``update`` entry point. The ``update`` entry point still previews the upgrade in check mode.
|
||||
@@ -4,7 +4,7 @@ Installs Docker Engine from the upstream Docker APT repository, optionally updat
|
||||
|
||||
## Supported platforms
|
||||
|
||||
Ubuntu. The key and repository URLs point at `download.docker.com/linux/ubuntu`, and the source line uses `ansible_distribution_release`. The default architecture is `amd64`. A limited molecule scenario covers the role's own logic (see [Tests](#tests)); the real Docker Engine is not tested.
|
||||
Ubuntu. The key and repository URLs point at `download.docker.com/linux/ubuntu`, and the source line uses `ansible_distribution_release`. The apt architecture is derived from the host (`x86_64` gives `amd64`, `aarch64` gives `arm64`); any other architecture fails the play until `docker_apt_arch` is set. A limited molecule scenario covers the role's own logic (see [Tests](#tests)); the real Docker Engine is not tested.
|
||||
|
||||
## Requirements and run order
|
||||
|
||||
@@ -25,7 +25,7 @@ Ubuntu. The key and repository URLs point at `download.docker.com/linux/ubuntu`,
|
||||
| `docker_apt_list_path` | `/etc/apt/sources.list.d/docker.list` | no | APT source file. |
|
||||
| `docker_gpg_url` | `https://download.docker.com/linux/ubuntu/gpg` | no | Key URL. |
|
||||
| `docker_repo_base_url` | `https://download.docker.com/linux/ubuntu` | no | Repository base URL. |
|
||||
| `docker_apt_arch` | `amd64` | no | Architecture in the APT source. |
|
||||
| `docker_apt_arch` | derived from the host | no | Architecture in the APT source. Empty derives it (`x86_64` gives `amd64`, `aarch64` gives `arm64`); another architecture fails until this is set. A value set here is always used; lowercase letters and digits only. |
|
||||
| `docker_service` | `docker` | no | systemd unit name. |
|
||||
| `docker_group` | `docker` | no | Group for `docker_users`. |
|
||||
| `docker_users` | `[]` | no | Users added to the group. |
|
||||
|
||||
@@ -13,8 +13,9 @@ docker_apt_list_path: /etc/apt/sources.list.d/docker.list
|
||||
docker_gpg_url: https://download.docker.com/linux/ubuntu/gpg
|
||||
docker_repo_base_url: https://download.docker.com/linux/ubuntu
|
||||
|
||||
# Override per host if a host is not amd64.
|
||||
docker_apt_arch: amd64
|
||||
# Architecture written into the APT source. Empty (the default) derives it from the host: x86_64 gives amd64, aarch64 gives arm64, any
|
||||
# other architecture fails the play, so set it here (for example armhf) when Docker publishes one for it.
|
||||
docker_apt_arch: ""
|
||||
|
||||
docker_service: docker
|
||||
docker_group: docker
|
||||
|
||||
@@ -56,9 +56,12 @@ argument_specs:
|
||||
- Base URL of the repository. The source line uses C(ansible_distribution_release) and the C(stable) component.
|
||||
docker_apt_arch:
|
||||
type: str
|
||||
default: amd64
|
||||
default: ""
|
||||
description:
|
||||
- Architecture written into the APT source. Override per host if a host is not amd64.
|
||||
- >-
|
||||
Architecture written into the APT source. Empty (the default) derives it from the host: C(x86_64) gives C(amd64), C(aarch64)
|
||||
gives C(arm64). Any other host architecture fails the play, so set this to the name Docker publishes for it. Lowercase letters
|
||||
and digits only. A value set here is always used.
|
||||
docker_service:
|
||||
type: str
|
||||
default: docker
|
||||
|
||||
@@ -59,3 +59,27 @@
|
||||
- "'MOLECULE-ACCEPTED' not in ansible_failed_result.msg | default('')"
|
||||
- "'docker_remove' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
|
||||
# The architecture is written into the one-line apt source, so a value with a space or a bracket is refused before anything
|
||||
# changes. The derived default is covered by the converge above and verify.yml (the container is x86_64, so the source says amd64).
|
||||
- name: A docker_apt_arch value that would corrupt the apt source is refused
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars:
|
||||
docker_apt_arch: "bad arch"
|
||||
tasks:
|
||||
- name: Apply the role with a bad architecture
|
||||
block:
|
||||
- name: Include the role
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.docker
|
||||
- name: Fail when the bad architecture was accepted
|
||||
ansible.builtin.fail:
|
||||
msg: MOLECULE-ACCEPTED
|
||||
rescue:
|
||||
- name: The validation stopped the play
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'MOLECULE-ACCEPTED' not in ansible_failed_result.msg | default('')"
|
||||
- "'docker_apt_arch' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
@@ -17,6 +17,7 @@
|
||||
- /srv/docker-stub-repo/docker.asc
|
||||
register: docker_verify_files
|
||||
|
||||
# amd64 because the Molecule container is x86_64: the role derives the architecture from the host now.
|
||||
- name: The source line carries the arch, the keyring and the release
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ docker_apt_list_path }}"
|
||||
content: |
|
||||
deb [arch={{ docker_apt_arch }} signed-by={{ docker_keyring_path }}] {{ docker_repo_base_url }} {{ ansible_distribution_release }} stable
|
||||
deb [arch={{ __docker_apt_arch }} signed-by={{ docker_keyring_path }}] {{ docker_repo_base_url }} {{ ansible_distribution_release }} stable
|
||||
mode: "0644"
|
||||
tags: [docker, install]
|
||||
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
---
|
||||
- name: Validate inputs
|
||||
ansible.builtin.import_tasks: validate.yml
|
||||
when: not (docker_remove | default(false) | bool)
|
||||
tags: always
|
||||
|
||||
- name: Remove Docker (explicit only)
|
||||
ansible.builtin.include_tasks: remove.yml
|
||||
when: docker_remove | default(false) | bool
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
# Fact-computing and assertion only, before any task changes the host. A removal does not write the apt source, so it does not need the architecture.
|
||||
- name: Work out the apt architecture
|
||||
ansible.builtin.set_fact:
|
||||
__docker_apt_arch: >-
|
||||
{{ docker_apt_arch | default('', true) or __docker_arch_by_fact[ansible_facts['architecture'] | default('')] | default('', true) }}
|
||||
tags: always
|
||||
|
||||
# The value is written into the one-line apt source (deb [arch=... signed-by=...]): a space or a bracket would corrupt it.
|
||||
- name: Check the apt architecture
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __docker_apt_arch is match('^[a-z0-9]+\Z')
|
||||
fail_msg: >-
|
||||
{% if docker_apt_arch | default('', true) | length > 0 %}
|
||||
docker_apt_arch '{{ docker_apt_arch }}' is not a valid apt architecture name: use the name Docker publishes (for example amd64 or arm64),
|
||||
lowercase letters and digits only.
|
||||
{% else %}
|
||||
The host architecture '{{ ansible_facts['architecture'] | default('unknown') }}' has no known Docker apt architecture (x86_64 and aarch64 do).
|
||||
Set docker_apt_arch to the name Docker publishes for it, for example armhf.
|
||||
{% endif %}
|
||||
quiet: true
|
||||
tags: always
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
# Constants, not inputs: the Docker apt architecture for each ansible_facts['architecture'] the role derives it for. docker_apt_arch
|
||||
# overrides it for any other architecture.
|
||||
__docker_arch_by_fact:
|
||||
x86_64: amd64
|
||||
aarch64: arm64
|
||||
@@ -53,6 +53,10 @@ Ubuntu 24.04 (noble), the image the molecule scenario runs on. The role uses `an
|
||||
| `gitea_runner_docker_prune_schedule` | `Sun *-*-* 04:30:00` | `OnCalendar` of the prune timer. |
|
||||
| `gitea_runner_docker_prune_container_age`, `_image_age` | `24h`, `168h` | `until` filters (creation time) for containers, and for images and build cache. |
|
||||
| `gitea_runner_docker_prune_job_max_age` | `21600` | Seconds; the prune skips while a younger container runs and ignores older ones as leaked job containers. |
|
||||
| `gitea_runner_docker_prune_keep_per_repository` | `0` (off) | Newest image IDs kept per repository by the weekly and pressure prunes; every other image no container uses is removed. A multi-tag image counts once. |
|
||||
| `gitea_runner_docker_prune_disk_threshold_percent` | `0` (off) | Use % of the Docker root's filesystem above which the pressure prune runs the count prune and a capped builder prune, behind the job gate. 1 to 99; needs the count above 0. |
|
||||
| `gitea_runner_docker_prune_disk_check_schedule` | `hourly` | `OnCalendar` of the pressure prune timer. |
|
||||
| `gitea_runner_docker_prune_builder_keep_storage` | `10GB` | `--keep-storage` of the builder prune under pressure. |
|
||||
| `gitea_runner_molecule_enabled` | `false` | Install molecule tooling and add the host label. |
|
||||
| `gitea_runner_molecule_label` | `molecule` | Host-executor label name, registered as `<label>:host`. |
|
||||
| `gitea_runner_molecule_venv` | `/opt/molecule-venv` | Tooling virtualenv. |
|
||||
@@ -86,7 +90,7 @@ Change the registration scope of a registered runner: set `gitea_runner_registra
|
||||
|
||||
## Tests
|
||||
|
||||
The `default` molecule scenario runs without a Gitea server and without Docker: a stub `docker.service`, a stub runner binary and a seeded `.runner` stand in for them, and the downloads come from local `file://` URLs. It covers the converge with the prune timer and an update through `_binary_update` (and its idempotence), the rendered `config.yaml` and unit, the prune gate script, a failed checksum that leaves the runner running, the input asserts, the CI refusal of a forced re-registration and the mint-before-drop order, and the remove path. Registration, the Docker install and the molecule tooling install are not covered.
|
||||
The `default` molecule scenario runs without a Gitea server and without Docker: a stub `docker.service`, a stub runner binary and a seeded `.runner` stand in for them, and the downloads come from local `file://` URLs. It covers the converge with the prune timer and an update through `_binary_update` (and its idempotence), the rendered `config.yaml` and unit, the prune gate script, the count prune and the disk check against a stub `docker` CLI, turning the pressure prune off, a failed checksum that leaves the runner running, the input asserts, the CI refusal of a forced re-registration and the mint-before-drop order, and the remove path. Registration, the Docker install and the molecule tooling install are not covered.
|
||||
|
||||
## Notes
|
||||
|
||||
@@ -95,6 +99,7 @@ The `default` molecule scenario runs without a Gitea server and without Docker:
|
||||
- Trust: with `gitea_runner_molecule_enabled`, jobs on the host-executor label run as the runner user, who is in the `docker` group, so they are root-equivalent on the runner host, which holds the registration and the secrets of every job it runs. Anyone who can run a workflow on that label can use it. Enable it only on a host whose registration scope (`gitea_runner_registration_scope`) is limited to repositories whose pushers you trust, and keep the job secrets of other repositories off that runner.
|
||||
- The runner binary is verified against `gitea_runner_checksum_url` on install and update; a mismatch fails the download task, and on an update leaves the running binary in place.
|
||||
- Handlers: `Restart Gitea Runner` runs when the config template changes or a registration happens.
|
||||
- The Docker prune units (`gitea-runner-docker-prune.{service,timer}`) are written only while `gitea_runner_docker_prune_enabled` is true. Setting it back to false leaves them in place: run `systemctl disable --now gitea-runner-docker-prune.timer` by hand. `gitea_runner_remove` deletes them and the gate script. A run skipped because a job was running is not retried until the next timer elapse: shorten `gitea_runner_docker_prune_schedule` (e.g. `*-*-* 04:30:00`) if that happens.
|
||||
- The Docker prune units (`gitea-runner-docker-prune.{service,timer}`) are written only while `gitea_runner_docker_prune_enabled` is true. Setting it back to false leaves them in place: run `systemctl disable --now gitea-runner-docker-prune.timer` by hand. `gitea_runner_remove` deletes them, the pressure units and the prune scripts. A run skipped because a job was running is not retried until the next timer elapse: shorten `gitea_runner_docker_prune_schedule` (e.g. `*-*-* 04:30:00`) if that happens.
|
||||
- The pressure prune (`gitea-runner-docker-prune-pressure.{service,timer}`) runs once per check while usage is above the threshold; it has no low watermark, so usage that stays high needs a smaller count or a larger disk. A threshold set back to `0` stops its timer and removes its units and the disk check script. The age prunes and the count prune both apply: an image either one removes is gone.
|
||||
- The play fails when `gitea-runner` is not `active` after start.
|
||||
- `no_log` covers the token mint, the token fact and the registration command.
|
||||
@@ -35,6 +35,12 @@ gitea_runner_docker_prune_image_age: 168h
|
||||
# Seconds. The prune skips while a container younger than this runs and ignores older ones as
|
||||
# leaked. Keep it above the longest job timeout.
|
||||
gitea_runner_docker_prune_job_max_age: 21600
|
||||
# Newest image IDs kept per repository by the weekly and pressure prunes; 0 = off.
|
||||
gitea_runner_docker_prune_keep_per_repository: 0
|
||||
# Use % of the Docker root's filesystem above which the pressure prune runs; 0 = off. Needs the count.
|
||||
gitea_runner_docker_prune_disk_threshold_percent: 0
|
||||
gitea_runner_docker_prune_disk_check_schedule: hourly
|
||||
gitea_runner_docker_prune_builder_keep_storage: 10GB
|
||||
|
||||
# Optional extra mounts
|
||||
# gitea_runner_container_volumes:
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Exit 0 when the filesystem holding the Docker root is more than $1 percent full (the pressure
|
||||
# prune may run), 1 to skip. Every failure skips: the prune must not run when the state is unknown.
|
||||
threshold="$1"
|
||||
case "$threshold" in
|
||||
'' | *[!0-9]*) echo "invalid threshold '$threshold'"; exit 1 ;;
|
||||
esac
|
||||
root=$(/usr/bin/docker info --format '{{.DockerRootDir}}') || { echo "docker info failed"; exit 1; }
|
||||
use=$(df -P "$root" | awk 'NR == 2 { sub(/%$/, "", $5); print $5 }')
|
||||
case "$use" in
|
||||
'' | *[!0-9]*) echo "cannot read the use of '$root'"; exit 1 ;;
|
||||
esac
|
||||
if [ "$use" -gt "$threshold" ]; then
|
||||
echo "$root is $use% full, above $threshold%: pruning"
|
||||
exit 0
|
||||
fi
|
||||
echo "$root is $use% full, not above $threshold%: skipping the prune"
|
||||
exit 1
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
# Keep the newest $1 image IDs of each repository, by creation time, and remove every other image
|
||||
# no container uses, dangling ones included. An image ID counts once however many tags it has, and
|
||||
# one kept by any of its repositories stays. A failed listing exits non-zero and removes nothing.
|
||||
keep="$1"
|
||||
case "$keep" in
|
||||
'' | *[!0-9]* | 0*) echo "invalid count '$keep'"; exit 2 ;;
|
||||
esac
|
||||
|
||||
images=$(/usr/bin/docker image ls --no-trunc --format '{{.ID}} {{.Repository}} {{.CreatedAt}}') ||
|
||||
{ echo "docker image ls failed"; exit 1; }
|
||||
containers=$(/usr/bin/docker ps --all --quiet --no-trunc) || { echo "docker ps failed"; exit 1; }
|
||||
used=""
|
||||
if [ -n "$containers" ]; then
|
||||
# shellcheck disable=SC2086 # one argument per container ID
|
||||
used=$(/usr/bin/docker container inspect --format '{{.Image}}' $containers) ||
|
||||
{ echo "cannot read the images of the containers"; exit 1; }
|
||||
fi
|
||||
|
||||
# CreatedAt is local time with an offset ("2026-01-05 10:00:00 +0100 CET"): compare it as epoch
|
||||
# seconds, or a change of offset would misorder the images.
|
||||
table=$(printf '%s\n' "$images" | while read -r id repo day time offset _; do
|
||||
[ -n "$id" ] || continue
|
||||
created=$(date -d "$day $time $offset" +%s) || exit 1
|
||||
echo "$created $id $repo"
|
||||
done) || { echo "cannot parse the creation time of an image"; exit 1; }
|
||||
|
||||
# Lines in: "used <id>", then "image <created> <id> <repo>", newest first within a repository.
|
||||
# Lines out: "<number of references> <id>" for each image to remove.
|
||||
remove=$({
|
||||
printf '%s\n' "$used" | sed -n 's/^./used &/p'
|
||||
printf '%s\n' "$table" | LC_ALL=C sort -k3,3 -k1,1nr -k2,2 | sed -n 's/^./image &/p'
|
||||
} | awk -v keep="$keep" '
|
||||
$1 == "used" { used[$2] = 1; next }
|
||||
{
|
||||
id = $3; repo = $4; refs[id]++
|
||||
if (!(id in seen)) { seen[id] = 1; order[++n] = id }
|
||||
if (repo != "<none>" && !((repo, id) in counted)) {
|
||||
counted[repo, id] = 1
|
||||
if (++slots[repo] <= keep) kept[id] = 1
|
||||
}
|
||||
}
|
||||
END { for (i = 1; i <= n; i++) if (!(order[i] in kept) && !(order[i] in used)) print refs[order[i]], order[i] }
|
||||
')
|
||||
|
||||
# An image with several references is refused by a plain rmi of its ID, so it needs --force.
|
||||
printf '%s\n' "$remove" | {
|
||||
rc=0
|
||||
while read -r refs id; do
|
||||
[ -n "$id" ] || continue
|
||||
force=""
|
||||
[ "$refs" -gt 1 ] && force="--force"
|
||||
echo "removing image $id"
|
||||
# shellcheck disable=SC2086 # $force is empty or one word
|
||||
/usr/bin/docker rmi $force "$id" || rc=1
|
||||
done
|
||||
exit "$rc"
|
||||
}
|
||||
@@ -231,6 +231,38 @@ argument_specs:
|
||||
- >-
|
||||
Seconds. The prune is skipped while a container younger than this runs (a job may use it). An older
|
||||
container is treated as a leaked job container: it is logged and ignored. Keep it above the longest job timeout.
|
||||
gitea_runner_docker_prune_keep_per_repository:
|
||||
type: int
|
||||
default: 0
|
||||
description:
|
||||
- >-
|
||||
Newest image IDs kept per repository, by creation time; C(0) turns the count prune off. Above C(0) the weekly
|
||||
prune and the pressure prune remove every other image no container uses, dangling images included. An image
|
||||
with several tags counts once, and one kept by any of its repositories stays. Only read when
|
||||
C(gitea_runner_docker_prune_enabled) is true.
|
||||
gitea_runner_docker_prune_disk_threshold_percent:
|
||||
type: int
|
||||
default: 0
|
||||
description:
|
||||
- >-
|
||||
Use, in percent, of the filesystem holding the Docker root above which
|
||||
C(gitea-runner-docker-prune-pressure.service) runs the count prune and a builder prune capped at
|
||||
C(gitea_runner_docker_prune_builder_keep_storage), behind the same job gate as the weekly prune. C(0) turns it
|
||||
off, and setting it back to C(0) stops the timer and removes its units. C(1) to C(99), and above C(0) only with
|
||||
C(gitea_runner_docker_prune_keep_per_repository) above C(0), asserted at role start when the prune is enabled.
|
||||
gitea_runner_docker_prune_disk_check_schedule:
|
||||
type: str
|
||||
default: hourly
|
||||
description:
|
||||
- >-
|
||||
C(OnCalendar) value of the pressure prune timer. Same check as C(gitea_runner_docker_prune_schedule).
|
||||
gitea_runner_docker_prune_builder_keep_storage:
|
||||
type: str
|
||||
default: 10GB
|
||||
description:
|
||||
- >-
|
||||
C(--keep-storage) of the builder prune under disk pressure: the build cache kept. A number with an optional
|
||||
C(B), C(KB), C(MB), C(GB) or C(TB), asserted at role start when the prune is enabled.
|
||||
gitea_runner_container_volumes:
|
||||
type: list
|
||||
elements: str
|
||||
|
||||
@@ -41,6 +41,8 @@ provisioner:
|
||||
- /cache:/cache
|
||||
gitea_runner_docker_prune_enabled: true
|
||||
gitea_runner_docker_prune_job_max_age: 3600
|
||||
gitea_runner_docker_prune_keep_per_repository: 2
|
||||
gitea_runner_docker_prune_disk_threshold_percent: 90
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
gitea_runner_registration_scope: "{{ gitea_runner_test_refused.vars.gitea_runner_registration_scope | default('') }}"
|
||||
gitea_runner_docker_prune_schedule: "{{ gitea_runner_test_refused.vars.gitea_runner_docker_prune_schedule | default('Sun *-*-* 04:30:00') }}"
|
||||
gitea_runner_docker_prune_image_age: "{{ gitea_runner_test_refused.vars.gitea_runner_docker_prune_image_age | default('168h') }}"
|
||||
gitea_runner_docker_prune_keep_per_repository: "{{ gitea_runner_test_refused.vars.gitea_runner_docker_prune_keep_per_repository | default(2) }}"
|
||||
gitea_runner_docker_prune_disk_threshold_percent: "{{ gitea_runner_test_refused.vars.gitea_runner_docker_prune_disk_threshold_percent | default(90) }}"
|
||||
gitea_runner_docker_prune_disk_check_schedule: "{{ gitea_runner_test_refused.vars.gitea_runner_docker_prune_disk_check_schedule | default('hourly') }}"
|
||||
gitea_runner_docker_prune_builder_keep_storage: "{{ gitea_runner_test_refused.vars.gitea_runner_docker_prune_builder_keep_storage | default('10GB') }}"
|
||||
gitea_runner_molecule_enabled: "{{ gitea_runner_test_refused.vars.gitea_runner_molecule_enabled | default(false) }}"
|
||||
|
||||
# Only reached when the include returned. The message must not contain the expected
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
src: /etc/systemd/system/gitea-runner-docker-prune.service
|
||||
register: gitea_runner_test_prune_service
|
||||
|
||||
- name: The prune timer is armed and the service carries the gate and the ages
|
||||
- name: The prune timer is armed and the service carries the gate, the ages and the count
|
||||
vars:
|
||||
gitea_runner_test_prune_text: "{{ gitea_runner_test_prune_service.content | b64decode }}"
|
||||
ansible.builtin.assert:
|
||||
@@ -95,6 +95,30 @@
|
||||
- "'ExecCondition=/usr/local/sbin/gitea-runner-docker-prune-gate 3600' in gitea_runner_test_prune_text"
|
||||
- "'container prune --force --filter until=24h' in gitea_runner_test_prune_text"
|
||||
- "'image prune --all --force --filter until=168h' in gitea_runner_test_prune_text"
|
||||
- "'ExecStart=-/usr/local/sbin/gitea-runner-docker-prune-keep 2' in gitea_runner_test_prune_text"
|
||||
quiet: true
|
||||
|
||||
- name: Ask systemd about the pressure prune timer
|
||||
ansible.builtin.systemd:
|
||||
name: gitea-runner-docker-prune-pressure.timer
|
||||
register: gitea_runner_test_pressure_timer
|
||||
|
||||
- name: Read the pressure prune service
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/systemd/system/gitea-runner-docker-prune-pressure.service
|
||||
register: gitea_runner_test_pressure_service
|
||||
|
||||
- name: The pressure timer is armed and its service runs behind the gate and the disk check
|
||||
vars:
|
||||
gitea_runner_test_pressure_text: "{{ gitea_runner_test_pressure_service.content | b64decode }}"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- gitea_runner_test_pressure_timer.status.ActiveState == 'active'
|
||||
- gitea_runner_test_pressure_timer.status.UnitFileState == 'enabled'
|
||||
- "'ExecCondition=/usr/local/sbin/gitea-runner-docker-prune-gate 3600' in gitea_runner_test_pressure_text"
|
||||
- "'ExecCondition=/usr/local/sbin/gitea-runner-docker-prune-disk-check 90' in gitea_runner_test_pressure_text"
|
||||
- "'ExecStart=-/usr/local/sbin/gitea-runner-docker-prune-keep 2' in gitea_runner_test_pressure_text"
|
||||
- "'ExecStart=-/usr/bin/docker builder prune --force --keep-storage 10GB' in gitea_runner_test_pressure_text"
|
||||
quiet: true
|
||||
|
||||
# The prune gate script against a stub docker CLI: no container, a young one (a job may be
|
||||
@@ -171,6 +195,169 @@
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_path
|
||||
|
||||
# The count prune and the disk check against a stub docker CLI: it answers from the files below,
|
||||
# records `rmi` calls, and a fail-<command> file makes that command fail. With N = 2, app keeps
|
||||
# a1 (two tags: counted twice it would push a2 out), a2 and a4 (used by c1); lib keeps m1 though
|
||||
# it is third in old; s3 (two tags) goes with --force; d1 goes, d2 (used by c2) stays.
|
||||
- name: Verify the count prune and the disk check
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars:
|
||||
gitea_runner_test_dir: /tmp/molecule-docker
|
||||
tasks:
|
||||
- name: Stat the docker CLI
|
||||
ansible.builtin.stat:
|
||||
path: /usr/bin/docker
|
||||
register: gitea_runner_test_docker_cli
|
||||
|
||||
- name: The image has no docker CLI the stub would replace
|
||||
ansible.builtin.assert:
|
||||
that: not gitea_runner_test_docker_cli.stat.exists
|
||||
fail_msg: /usr/bin/docker exists in the test image; this play would overwrite it.
|
||||
quiet: true
|
||||
|
||||
- name: Create the stub's directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ gitea_runner_test_dir }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: Write the stub docker CLI
|
||||
ansible.builtin.copy:
|
||||
dest: /usr/bin/docker
|
||||
mode: "0755"
|
||||
content: |
|
||||
#!/bin/sh
|
||||
d={{ gitea_runner_test_dir }}
|
||||
[ -e "$d/fail-$1" ] && exit 1
|
||||
case "$1" in
|
||||
image) cat "$d/images" ;;
|
||||
ps) cat "$d/containers" ;;
|
||||
container)
|
||||
shift 4
|
||||
for c in "$@"; do grep "^$c " "$d/container-images" | cut -d' ' -f2; done ;;
|
||||
info) cat "$d/root" ;;
|
||||
rmi) echo "$*" >> "$d/rmi" ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
|
||||
- name: Write the stub's images and containers
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ gitea_runner_test_dir }}/{{ gitea_runner_test_fixture.name }}"
|
||||
mode: "0644"
|
||||
content: "{{ gitea_runner_test_fixture.content }}"
|
||||
loop:
|
||||
- name: images
|
||||
content: |
|
||||
sha256:a1 app 2026-01-05 10:00:00 +0000 UTC
|
||||
sha256:a1 app 2026-01-05 10:00:00 +0000 UTC
|
||||
sha256:a2 app 2026-01-04 10:00:00 +0000 UTC
|
||||
sha256:a3 app 2026-01-03 10:00:00 +0000 UTC
|
||||
sha256:a4 app 2026-01-02 10:00:00 +0000 UTC
|
||||
sha256:a5 app 2026-01-01 10:00:00 +0000 UTC
|
||||
sha256:m1 lib 2026-01-01 10:00:00 +0000 UTC
|
||||
sha256:o1 old 2026-01-03 10:00:00 +0000 UTC
|
||||
sha256:o2 old 2026-01-02 10:00:00 +0000 UTC
|
||||
sha256:m1 old 2026-01-01 10:00:00 +0000 UTC
|
||||
sha256:s1 stale 2026-01-03 10:00:00 +0000 UTC
|
||||
sha256:s2 stale 2026-01-02 10:00:00 +0000 UTC
|
||||
sha256:s3 stale 2026-01-01 10:00:00 +0000 UTC
|
||||
sha256:s3 stale 2026-01-01 10:00:00 +0000 UTC
|
||||
sha256:d1 <none> 2026-01-01 10:00:00 +0000 UTC
|
||||
sha256:d2 <none> 2026-01-01 10:00:00 +0000 UTC
|
||||
- name: containers
|
||||
content: |
|
||||
c1
|
||||
c2
|
||||
- name: container-images
|
||||
content: |
|
||||
c1 sha256:a4
|
||||
c2 sha256:d2
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_fixture
|
||||
label: "{{ gitea_runner_test_fixture.name }}"
|
||||
|
||||
- name: Run each count prune case
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
cd {{ gitea_runner_test_dir }} && rm -f rmi fail-*
|
||||
{{ ('touch fail-' ~ gitea_runner_test_case.fail) if gitea_runner_test_case.fail else ':' }}
|
||||
/usr/local/sbin/gitea-runner-docker-prune-keep {{ gitea_runner_test_case.keep }} >&2
|
||||
rc=$?
|
||||
[ -e rmi ] && LC_ALL=C sort rmi
|
||||
exit "$rc"
|
||||
loop:
|
||||
- {name: keep-two, keep: 2, fail: "", rc: 0, rmi: [rmi --force sha256:s3, rmi sha256:a3, rmi sha256:a5, rmi sha256:d1]}
|
||||
- {name: image-ls-fails, keep: 2, fail: image, rc: 1, rmi: []}
|
||||
- {name: ps-fails, keep: 2, fail: ps, rc: 1, rmi: []}
|
||||
- {name: inspect-fails, keep: 2, fail: container, rc: 1, rmi: []}
|
||||
- {name: zero-count, keep: 0, fail: "", rc: 2, rmi: []}
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_case
|
||||
label: "{{ gitea_runner_test_case.name }}"
|
||||
register: gitea_runner_test_keep
|
||||
# The rc and the rmi calls are the result under test; the next task asserts them.
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
|
||||
- name: The count prune removed exactly the expected images, and nothing when a listing failed
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- item.rc == item.gitea_runner_test_case.rc
|
||||
- item.stdout_lines == item.gitea_runner_test_case.rmi
|
||||
fail_msg: "case {{ item.gitea_runner_test_case.name }}: rc {{ item.rc }}, rmi {{ item.stdout_lines }}, output {{ item.stderr }}"
|
||||
quiet: true
|
||||
loop: "{{ gitea_runner_test_keep.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.gitea_runner_test_case.name }}"
|
||||
|
||||
# The above and at-use cases set the threshold one below and equal to the root's use, read
|
||||
# just before (df rounds up, so a used root is at least 1%); /run/lock is never above 50%.
|
||||
- name: Run each disk check case
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
cd {{ gitea_runner_test_dir }} && rm -f fail-*
|
||||
{{ ('touch fail-' ~ gitea_runner_test_case.fail) if gitea_runner_test_case.fail else ':' }}
|
||||
echo '{{ gitea_runner_test_case.root }}' > root
|
||||
threshold={{ gitea_runner_test_case.threshold }}
|
||||
{% if gitea_runner_test_case.threshold in ['below-use', 'use'] %}
|
||||
df -P / > df-root && use=$(awk 'NR == 2 { sub(/%$/, "", $5); print $5 }' df-root)
|
||||
threshold=$((use - {{ 1 if gitea_runner_test_case.threshold == 'below-use' else 0 }}))
|
||||
{% endif %}
|
||||
/usr/local/sbin/gitea-runner-docker-prune-disk-check "$threshold"
|
||||
loop:
|
||||
- {name: above, root: /, threshold: below-use, fail: "", rc: 0}
|
||||
- {name: below, root: /run/lock, threshold: 50, fail: "", rc: 1, out: "% full, not above 50%: skipping the prune"}
|
||||
- {name: at-use, root: /, threshold: use, fail: "", rc: 1, out: "not above"}
|
||||
- {name: info-fails, root: /, threshold: below-use, fail: info, rc: 1}
|
||||
- {name: root-missing, root: /nonexistent, threshold: 1, fail: "", rc: 1}
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_case
|
||||
label: "{{ gitea_runner_test_case.name }}"
|
||||
register: gitea_runner_test_pressure
|
||||
# The rc is the result under test; the next task asserts it.
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
|
||||
- name: The disk check let the pressure prune run only above the threshold
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- item.rc == item.gitea_runner_test_case.rc
|
||||
- item.gitea_runner_test_case.out | default('') in item.stdout
|
||||
fail_msg: "case {{ item.gitea_runner_test_case.name }}: rc {{ item.rc }}, output {{ item.stdout }} {{ item.stderr }}"
|
||||
quiet: true
|
||||
loop: "{{ gitea_runner_test_pressure.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.gitea_runner_test_case.name }}"
|
||||
|
||||
- name: Remove the stub docker CLI and its files
|
||||
ansible.builtin.file:
|
||||
path: "{{ gitea_runner_test_path }}"
|
||||
state: absent
|
||||
loop: [/usr/bin/docker, "{{ gitea_runner_test_dir }}"]
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_path
|
||||
|
||||
# 6.0.2 has a wrong checksum file (prepare.yml): the download must fail before anything is
|
||||
# stopped, so the runner keeps running 6.0.1.
|
||||
- name: Verify a failed download leaves the runner running
|
||||
@@ -237,10 +424,25 @@
|
||||
expect: gitea_runner_registration_scope must be empty
|
||||
- name: prune schedule with a newline
|
||||
vars: {gitea_runner_docker_prune_schedule: "daily\nExecStartPre=/bin/false"}
|
||||
expect: plain OnCalendar value
|
||||
expect: gitea_runner_docker_prune_schedule must be a plain OnCalendar value
|
||||
- name: prune age without a unit
|
||||
vars: {gitea_runner_docker_prune_image_age: "168"}
|
||||
expect: plain OnCalendar value
|
||||
expect: the two ages a number with s, m or h
|
||||
- name: negative prune count
|
||||
vars: {gitea_runner_docker_prune_keep_per_repository: -1}
|
||||
expect: gitea_runner_docker_prune_keep_per_repository must be 0 (off) or more
|
||||
- name: disk threshold of 100
|
||||
vars: {gitea_runner_docker_prune_disk_threshold_percent: 100}
|
||||
expect: gitea_runner_docker_prune_disk_threshold_percent must be 0 (off) or 1 to 99
|
||||
- name: disk check schedule with a newline
|
||||
vars: {gitea_runner_docker_prune_disk_check_schedule: "hourly\nExecStartPre=/bin/false"}
|
||||
expect: gitea_runner_docker_prune_disk_check_schedule must be a plain OnCalendar value
|
||||
- name: builder keep-storage with an extra argument
|
||||
vars: {gitea_runner_docker_prune_builder_keep_storage: "10GB --all"}
|
||||
expect: gitea_runner_docker_prune_builder_keep_storage must be a number
|
||||
- name: disk threshold without a count
|
||||
vars: {gitea_runner_docker_prune_keep_per_repository: 0}
|
||||
expect: needs gitea_runner_docker_prune_keep_per_repository above 0
|
||||
- name: molecule tooling without a requirements file
|
||||
vars: {gitea_runner_molecule_enabled: true}
|
||||
expect: gitea_runner_collections_requirements_file must name
|
||||
@@ -351,6 +553,57 @@
|
||||
- gitea_runner_test_unit.status.ActiveState == 'active'
|
||||
quiet: true
|
||||
|
||||
# A threshold of 0 removes the pressure units; the run after it, with the scenario's inputs,
|
||||
# puts them back, so the remove path below still has them to remove.
|
||||
- name: Verify turning the pressure prune off
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Run the role with the disk threshold at 0
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.gitea_runner
|
||||
vars:
|
||||
gitea_runner_docker_prune_disk_threshold_percent: 0
|
||||
|
||||
- name: Stat the pressure units and script
|
||||
ansible.builtin.stat:
|
||||
path: "{{ gitea_runner_test_path }}"
|
||||
loop:
|
||||
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
|
||||
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
|
||||
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_path
|
||||
register: gitea_runner_test_pressure_off
|
||||
|
||||
- name: Ask systemd about the pressure timer after turning it off
|
||||
ansible.builtin.systemd:
|
||||
name: gitea-runner-docker-prune-pressure.timer
|
||||
register: gitea_runner_test_pressure_timer_off
|
||||
# The module errors for a unit that no longer exists, which is also a pass.
|
||||
failed_when: false
|
||||
|
||||
- name: The pressure units are gone and the timer is not active
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- gitea_runner_test_pressure_off.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0
|
||||
- gitea_runner_test_pressure_timer_off.status.ActiveState | default('inactive') != 'active'
|
||||
quiet: true
|
||||
|
||||
- name: Run the role again with the scenario's inputs
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.gitea_runner
|
||||
|
||||
- name: Ask systemd about the pressure timer after turning it on again
|
||||
ansible.builtin.systemd:
|
||||
name: gitea-runner-docker-prune-pressure.timer
|
||||
register: gitea_runner_test_pressure_timer_on
|
||||
|
||||
- name: The pressure timer is armed again
|
||||
ansible.builtin.assert:
|
||||
that: gitea_runner_test_pressure_timer_on.status.ActiveState == 'active'
|
||||
quiet: true
|
||||
|
||||
# The remove path. Last on purpose: it runs once, outside the idempotence step, and nothing runs
|
||||
# after verify except molecule's own cleanup and destroy of the container. The download URL still
|
||||
# points at a valid 6.0.1 release, so a role that went on to install after the removal would put
|
||||
@@ -376,6 +629,10 @@
|
||||
- /etc/systemd/system/gitea-runner-docker-prune.service
|
||||
- /etc/systemd/system/gitea-runner-docker-prune.timer
|
||||
- /usr/local/sbin/gitea-runner-docker-prune-gate
|
||||
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
|
||||
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
|
||||
- /usr/local/sbin/gitea-runner-docker-prune-keep
|
||||
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
|
||||
- /etc/systemd/system/multi-user.target.wants/gitea-runner.service
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_path
|
||||
@@ -384,7 +641,7 @@
|
||||
- name: Ask systemd whether the runner and the timer are still active
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ gitea_runner_test_unit_name }}"
|
||||
loop: [gitea-runner, gitea-runner-docker-prune.timer]
|
||||
loop: [gitea-runner, gitea-runner-docker-prune.timer, gitea-runner-docker-prune-pressure.timer]
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_unit_name
|
||||
register: gitea_runner_test_after
|
||||
|
||||
@@ -45,6 +45,18 @@
|
||||
when: gitea_runner_docker_prune_enabled | bool
|
||||
tags: [gitea_runner, prune]
|
||||
|
||||
# Used by the weekly and pressure services when gitea_runner_docker_prune_keep_per_repository > 0.
|
||||
- name: Install Docker prune count script
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
src: gitea-runner-docker-prune-keep
|
||||
dest: /usr/local/sbin/gitea-runner-docker-prune-keep
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
when: gitea_runner_docker_prune_enabled | bool
|
||||
tags: [gitea_runner, prune]
|
||||
|
||||
- name: Install Docker prune service
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
@@ -65,6 +77,9 @@
|
||||
ExecStart=-/usr/bin/docker image prune --all --force --filter until={{ gitea_runner_docker_prune_image_age }}
|
||||
ExecStart=-/usr/bin/docker builder prune --force --filter until={{ gitea_runner_docker_prune_image_age }}
|
||||
ExecStart=-/usr/bin/docker volume prune --force
|
||||
{% if gitea_runner_docker_prune_keep_per_repository | int > 0 %}
|
||||
ExecStart=-/usr/local/sbin/gitea-runner-docker-prune-keep {{ gitea_runner_docker_prune_keep_per_repository }}
|
||||
{% endif %}
|
||||
register: gitea_runner_prune_service
|
||||
when: gitea_runner_docker_prune_enabled | bool
|
||||
tags: [gitea_runner, prune]
|
||||
@@ -91,13 +106,108 @@
|
||||
when: gitea_runner_docker_prune_enabled | bool
|
||||
tags: [gitea_runner, prune]
|
||||
|
||||
# Pressure path: above the disk threshold, the count prune and a capped builder prune run behind
|
||||
# the same gate. There is no low watermark: if usage stays high, the count or the disk needs a human.
|
||||
# The builder cache is capped because job containers share the host's docker.sock by default.
|
||||
- name: Install the pressure prune when a disk threshold is set
|
||||
when:
|
||||
- gitea_runner_docker_prune_enabled | bool
|
||||
- gitea_runner_docker_prune_disk_threshold_percent | int > 0
|
||||
tags: [gitea_runner, prune]
|
||||
block:
|
||||
- name: Install Docker disk check script
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
src: gitea-runner-docker-prune-disk-check
|
||||
dest: /usr/local/sbin/gitea-runner-docker-prune-disk-check
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
|
||||
- name: Install Docker pressure prune service
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/systemd/system/gitea-runner-docker-prune-pressure.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Prune Docker images when the disk of the Gitea runner host is filling up
|
||||
After=docker.service
|
||||
Requires=docker.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecCondition=/usr/local/sbin/gitea-runner-docker-prune-gate {{ gitea_runner_docker_prune_job_max_age }}
|
||||
ExecCondition=/usr/local/sbin/gitea-runner-docker-prune-disk-check {{ gitea_runner_docker_prune_disk_threshold_percent }}
|
||||
ExecStart=-/usr/local/sbin/gitea-runner-docker-prune-keep {{ gitea_runner_docker_prune_keep_per_repository }}
|
||||
ExecStart=-/usr/bin/docker builder prune --force --keep-storage {{ gitea_runner_docker_prune_builder_keep_storage }}
|
||||
register: __gitea_runner_prune_pressure_service
|
||||
|
||||
- name: Install Docker pressure prune timer
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Disk check for the Docker pressure prune on the Gitea runner host
|
||||
|
||||
[Timer]
|
||||
OnCalendar={{ gitea_runner_docker_prune_disk_check_schedule }}
|
||||
Persistent=true
|
||||
RandomizedDelaySec=2m
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
register: __gitea_runner_prune_pressure_timer
|
||||
|
||||
# A threshold set back to 0 turns the pressure path off: the units go, so nothing is left armed.
|
||||
- name: Stop the Docker pressure prune timer when the disk threshold is 0
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
name: gitea-runner-docker-prune-pressure.timer
|
||||
state: stopped
|
||||
enabled: false
|
||||
register: __gitea_runner_prune_pressure_stop
|
||||
failed_when:
|
||||
- __gitea_runner_prune_pressure_stop.failed | default(false)
|
||||
- "'Could not find the requested service' not in (__gitea_runner_prune_pressure_stop.msg | default(''))"
|
||||
when:
|
||||
- gitea_runner_docker_prune_enabled | bool
|
||||
- gitea_runner_docker_prune_disk_threshold_percent | int == 0
|
||||
tags: [gitea_runner, prune]
|
||||
|
||||
- name: Remove the Docker pressure prune units when the disk threshold is 0
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: "{{ gitea_runner_prune_pressure_file }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
|
||||
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
|
||||
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
|
||||
loop_control:
|
||||
loop_var: gitea_runner_prune_pressure_file
|
||||
register: __gitea_runner_prune_pressure_removed
|
||||
when:
|
||||
- gitea_runner_docker_prune_enabled | bool
|
||||
- gitea_runner_docker_prune_disk_threshold_percent | int == 0
|
||||
tags: [gitea_runner, prune]
|
||||
|
||||
- name: Reload systemd for the prune units
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
daemon_reload: true
|
||||
when:
|
||||
- gitea_runner_docker_prune_enabled | bool
|
||||
- gitea_runner_prune_service is changed or gitea_runner_prune_timer is changed
|
||||
- >-
|
||||
gitea_runner_prune_service is changed or gitea_runner_prune_timer is changed
|
||||
or __gitea_runner_prune_pressure_service is changed or __gitea_runner_prune_pressure_timer is changed
|
||||
or __gitea_runner_prune_pressure_removed is changed
|
||||
tags: [gitea_runner, prune]
|
||||
|
||||
# Not in check mode: on the first run the unit files above are only simulated, so systemd
|
||||
@@ -112,3 +222,15 @@
|
||||
- gitea_runner_docker_prune_enabled | bool
|
||||
- not ansible_check_mode
|
||||
tags: [gitea_runner, prune]
|
||||
|
||||
- name: Enable the Docker pressure prune timer
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
name: gitea-runner-docker-prune-pressure.timer
|
||||
enabled: true
|
||||
state: "{{ 'restarted' if __gitea_runner_prune_pressure_timer is changed else 'started' }}"
|
||||
when:
|
||||
- gitea_runner_docker_prune_enabled | bool
|
||||
- gitea_runner_docker_prune_disk_threshold_percent | int > 0
|
||||
- not ansible_check_mode
|
||||
tags: [gitea_runner, prune]
|
||||
@@ -15,12 +15,17 @@
|
||||
- "'Could not find the requested service' not in (gitea_runner_stop.msg | default(''))"
|
||||
tags: [gitea_runner, remove]
|
||||
|
||||
- name: Stop the Docker prune timer
|
||||
- name: Stop the Docker prune timers
|
||||
become: true
|
||||
ansible.builtin.systemd:
|
||||
name: gitea-runner-docker-prune.timer
|
||||
name: "{{ gitea_runner_prune_timer_name }}"
|
||||
state: stopped
|
||||
enabled: false
|
||||
loop:
|
||||
- gitea-runner-docker-prune.timer
|
||||
- gitea-runner-docker-prune-pressure.timer
|
||||
loop_control:
|
||||
loop_var: gitea_runner_prune_timer_name
|
||||
register: gitea_runner_prune_stop
|
||||
failed_when:
|
||||
- gitea_runner_prune_stop.failed | default(false)
|
||||
@@ -35,15 +40,23 @@
|
||||
loop:
|
||||
- gitea-runner-docker-prune.timer
|
||||
- gitea-runner-docker-prune.service
|
||||
- gitea-runner-docker-prune-pressure.timer
|
||||
- gitea-runner-docker-prune-pressure.service
|
||||
loop_control:
|
||||
loop_var: gitea_runner_prune_unit
|
||||
tags: [gitea_runner, remove]
|
||||
|
||||
- name: Remove the Docker prune gate script
|
||||
- name: Remove the Docker prune scripts
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: /usr/local/sbin/gitea-runner-docker-prune-gate
|
||||
path: "/usr/local/sbin/{{ gitea_runner_prune_script }}"
|
||||
state: absent
|
||||
loop:
|
||||
- gitea-runner-docker-prune-gate
|
||||
- gitea-runner-docker-prune-keep
|
||||
- gitea-runner-docker-prune-disk-check
|
||||
loop_control:
|
||||
loop_var: gitea_runner_prune_script
|
||||
tags: [gitea_runner, remove]
|
||||
|
||||
- name: Remove systemd unit
|
||||
|
||||
@@ -36,6 +36,50 @@
|
||||
quiet: true
|
||||
when: gitea_runner_docker_prune_enabled | bool
|
||||
|
||||
- name: Validate the Docker prune count
|
||||
ansible.builtin.assert:
|
||||
that: gitea_runner_docker_prune_keep_per_repository | int >= 0
|
||||
fail_msg: gitea_runner_docker_prune_keep_per_repository must be 0 (off) or more.
|
||||
quiet: true
|
||||
when: gitea_runner_docker_prune_enabled | bool
|
||||
|
||||
- name: Validate the Docker prune disk threshold
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- gitea_runner_docker_prune_disk_threshold_percent | int >= 0
|
||||
- gitea_runner_docker_prune_disk_threshold_percent | int <= 99
|
||||
fail_msg: gitea_runner_docker_prune_disk_threshold_percent must be 0 (off) or 1 to 99.
|
||||
quiet: true
|
||||
when: gitea_runner_docker_prune_enabled | bool
|
||||
|
||||
# Same character set as the weekly schedule.
|
||||
- name: Validate the Docker prune disk check schedule
|
||||
ansible.builtin.assert:
|
||||
that: gitea_runner_docker_prune_disk_check_schedule is match('^[A-Za-z0-9 :*,./~-]+$')
|
||||
fail_msg: gitea_runner_docker_prune_disk_check_schedule must be a plain OnCalendar value (no newline or %).
|
||||
quiet: true
|
||||
when: gitea_runner_docker_prune_enabled | bool
|
||||
|
||||
# A subset of the units Docker accepts for --keep-storage.
|
||||
- name: Validate the Docker builder keep-storage size
|
||||
ansible.builtin.assert:
|
||||
that: gitea_runner_docker_prune_builder_keep_storage is match('^[0-9]+(B|KB|MB|GB|TB)?$')
|
||||
fail_msg: >-
|
||||
gitea_runner_docker_prune_builder_keep_storage must be a number with an optional B, KB, MB, GB or TB (e.g. 10GB).
|
||||
quiet: true
|
||||
when: gitea_runner_docker_prune_enabled | bool
|
||||
|
||||
- name: Require a count for the pressure prune
|
||||
ansible.builtin.assert:
|
||||
that: >-
|
||||
gitea_runner_docker_prune_disk_threshold_percent | int == 0
|
||||
or gitea_runner_docker_prune_keep_per_repository | int > 0
|
||||
fail_msg: >-
|
||||
gitea_runner_docker_prune_disk_threshold_percent needs gitea_runner_docker_prune_keep_per_repository above 0:
|
||||
the pressure prune removes images by that count.
|
||||
quiet: true
|
||||
when: gitea_runner_docker_prune_enabled | bool
|
||||
|
||||
- name: Require the collections requirements file for the molecule tooling
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
|
||||
@@ -59,7 +59,7 @@ system_baseline_profile_overrides:
|
||||
|
||||
Besides `main`, two task files are a supported interface, for a caller that drives its own reboot (for example a Kubernetes node patch flow that cordons and drains first). Their names, the fact name and the behaviour below follow the Collection's semantic versioning: changing them is a breaking change.
|
||||
|
||||
- `tasks_from: update`: apt update, upgrade, autoremove and autoclean, nothing else. It does not read `system_baseline_update`: calling the entry point is the request to update.
|
||||
- `tasks_from: update`: apt update, upgrade, autoremove and autoclean, nothing else. It does not read `system_baseline_update`: calling the entry point is the request to update. In check mode it previews the upgrade; the main flow does not (see "Check mode").
|
||||
- `tasks_from: reboot`: sets the fact `system_baseline_reboot_required` (bool, from `/var/run/reboot-required`) on Debian family hosts, then reboots when `system_baseline_reboot_if_required` is true and the fact is true. With `system_baseline_reboot_if_required: false` it only computes the fact. On other families the fact is not set, so read it with `default(false)`.
|
||||
|
||||
```yaml
|
||||
@@ -120,6 +120,10 @@ system_baseline_tmux_windows:
|
||||
|
||||
`system_baseline_update: false` skips the package update of the main flow, for hosts patched by a separate, operator-run flow (for example a full upgrade with a rolling reboot). Everything else, unattended-upgrades included, still runs. The reboot check still runs as well, so set `system_baseline_reboot_if_required: false` too when that flow owns the reboot. Running the play with `--skip-tags update` skips the same task for one run only, and also the reboot.
|
||||
|
||||
## Check mode
|
||||
|
||||
In a dry run (`--check`) the main flow does not run the apt upgrade: a package that is only waiting for the next patch run, or a package cache older than an hour, is not drift, and the package module reports both as `changed`, so a scheduled dry run would flag every host whenever a package landed in between. The autoremove and autoclean step still runs, and is checked: a leftover package it would remove is reported as `changed`, on purpose. `apt-get autoclean` runs in this step in a real run, in the main flow and in the `update` entry point. The `update` entry point is unchanged: it is an explicit request to update, so in check mode it still previews the upgrade.
|
||||
|
||||
## Unattended-upgrades origins
|
||||
|
||||
A profile's `unattended_upgrade_origins` list pins the origins unattended-upgrades may install from. apt merges every file in `/etc/apt/apt.conf.d` and appends list entries across files, so a later file that only lists origins would widen the distribution's `50unattended-upgrades`, never narrow it. A non-empty list is therefore written to `/etc/apt/apt.conf.d/90unattended-upgrades-origins`, which sorts after `50unattended-upgrades`, clears `Unattended-Upgrade::Allowed-Origins` and `Unattended-Upgrade::Origins-Pattern` (apt's `#clear` directive) and sets only the listed patterns. The origin lists in `50unattended-upgrades` itself are not edited. An empty or missing list removes the drop-in.
|
||||
|
||||
@@ -124,11 +124,14 @@ argument_specs:
|
||||
separate flow; the reboot check still runs, so set C(system_baseline_reboot_if_required) as well when that flow also owns
|
||||
the reboot.
|
||||
- The C(update) entry point does not read it.
|
||||
- In check mode the main flow skips the upgrade itself (a pending update is not drift); autoremove and autoclean are still checked.
|
||||
update:
|
||||
short_description: Update and upgrade apt packages
|
||||
description:
|
||||
- Runs an apt update, upgrade, autoremove and autoclean, and nothing else.
|
||||
- Calling it is a request to update, so it does not read C(system_baseline_update), which only gates the main flow.
|
||||
- >-
|
||||
Calling it is a request to update, so it does not read C(system_baseline_update), which only gates the main flow. In check mode it
|
||||
still previews the upgrade.
|
||||
- >-
|
||||
A supported entry point (C(tasks_from=update)) for a caller that drives its own reboot, for example a
|
||||
Kubernetes node patch flow that drains the node first.
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
# Only the main flow honours system_baseline_update: the tasks_from: update entry point is an explicit request to update.
|
||||
- name: Update & Upgrade Dist
|
||||
ansible.builtin.import_tasks: update.yml
|
||||
vars:
|
||||
__system_baseline_main_flow: true
|
||||
when: system_baseline_update | bool
|
||||
tags: update
|
||||
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
---
|
||||
# In the main flow a dry run (--check) does not run the upgrade: a package that is only waiting for the next patch run is not drift, and
|
||||
# the package module reports `changed` for it, so a scheduled dry run flagged every host whenever a package landed in between. The
|
||||
# tasks_from: update entry point is an explicit request to update and still previews the upgrade in check mode: only main.yml sets
|
||||
# __system_baseline_main_flow. Leftover packages (autoremove) and the cache (autoclean) stay checked either way.
|
||||
- name: Update & upgrade apt packages
|
||||
ansible.builtin.package:
|
||||
update_cache: true
|
||||
upgrade: true
|
||||
autoremove: true
|
||||
autoclean: true
|
||||
cache_valid_time: 3600
|
||||
become: true
|
||||
when: not (ansible_check_mode and __system_baseline_main_flow | default(false))
|
||||
|
||||
# autoremove must stay in this task: the apt module accepts autoclean alone only together with one of autoremove, name, update_cache or upgrade.
|
||||
- name: Remove unused packages and clean the apt cache
|
||||
ansible.builtin.package:
|
||||
autoremove: true
|
||||
autoclean: true
|
||||
become: true
|
||||
@@ -89,6 +89,8 @@ FORBIDDEN = [
|
||||
"*.env.*",
|
||||
"*/.env*",
|
||||
".env*",
|
||||
# Contributor rules: a consumer's agent reading an installed role would load them.
|
||||
"*/agents.md",
|
||||
]
|
||||
# Names Windows treats as devices, with or without an extension (and with trailing spaces).
|
||||
WINDOWS_RESERVED = {
|
||||
|
||||
@@ -70,6 +70,22 @@ class TarballTest(unittest.TestCase):
|
||||
self.assertEqual(len(found), 1, name)
|
||||
self.assertIn("forbidden pattern", found[0], name)
|
||||
|
||||
def test_agents_md_is_refused_at_any_depth(self):
|
||||
for name in (
|
||||
"roles/AGENTS.md",
|
||||
"roles/x/AGENTS.md",
|
||||
"roles/x/templates/Agents.md",
|
||||
):
|
||||
found = check_tarball.problems([name])
|
||||
self.assertEqual(len(found), 1, name)
|
||||
self.assertIn("forbidden pattern", found[0], name)
|
||||
self.assertEqual(
|
||||
check_tarball.problems(
|
||||
["roles/x/README.md", "roles/x/files/agents_notes.md"]
|
||||
),
|
||||
[],
|
||||
)
|
||||
|
||||
def test_ambiguous_names_are_rejected(self):
|
||||
cases = {
|
||||
"roles/a/x ": "ends in a space or a dot",
|
||||
|
||||
Reference in new issue
Block a user