diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 6c63cfd..9c27ddc 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -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: diff --git a/.gitea/workflows/gitea-release-key.yml b/.gitea/workflows/gitea-release-key.yml index 8cdf2b6..f5a7272 100644 --- a/.gitea/workflows/gitea-release-key.yml +++ b/.gitea/workflows/gitea-release-key.yml @@ -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. diff --git a/.gitea/workflows/image.yml b/.gitea/workflows/image.yml index a943a50..33a4109 100644 --- a/.gitea/workflows/image.yml +++ b/.gitea/workflows/image.yml @@ -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 diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index c05b589..5c49283 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -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 diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index 44dd73f..8074d94 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -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: >- diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 25c30c4..56a509c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/changelogs/fragments/docker-apt-arch-from-host.yml b/changelogs/fragments/docker-apt-arch-from-host.yml new file mode 100644 index 0000000..225fe8c --- /dev/null +++ b/changelogs/fragments/docker-apt-arch-from-host.yml @@ -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. diff --git a/changelogs/fragments/gitea-runner-docker-prune-count-threshold.yml b/changelogs/fragments/gitea-runner-docker-prune-count-threshold.yml new file mode 100644 index 0000000..af9bb56 --- /dev/null +++ b/changelogs/fragments/gitea-runner-docker-prune-count-threshold.yml @@ -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. diff --git a/changelogs/fragments/system-baseline-check-mode-upgrade.yml b/changelogs/fragments/system-baseline-check-mode-upgrade.yml new file mode 100644 index 0000000..eef501e --- /dev/null +++ b/changelogs/fragments/system-baseline-check-mode-upgrade.yml @@ -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. diff --git a/roles/docker/README.md b/roles/docker/README.md index 447c5f5..f2be8a2 100644 --- a/roles/docker/README.md +++ b/roles/docker/README.md @@ -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. | diff --git a/roles/docker/defaults/main.yml b/roles/docker/defaults/main.yml index ef8edac..0c7acee 100644 --- a/roles/docker/defaults/main.yml +++ b/roles/docker/defaults/main.yml @@ -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 diff --git a/roles/docker/meta/argument_specs.yml b/roles/docker/meta/argument_specs.yml index ec2a6f1..d9b567c 100644 --- a/roles/docker/meta/argument_specs.yml +++ b/roles/docker/meta/argument_specs.yml @@ -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 diff --git a/roles/docker/molecule/default/converge.yml b/roles/docker/molecule/default/converge.yml index 48d0c6f..e022faa 100644 --- a/roles/docker/molecule/default/converge.yml +++ b/roles/docker/molecule/default/converge.yml @@ -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 diff --git a/roles/docker/molecule/default/verify.yml b/roles/docker/molecule/default/verify.yml index 4298589..2fb7020 100644 --- a/roles/docker/molecule/default/verify.yml +++ b/roles/docker/molecule/default/verify.yml @@ -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: diff --git a/roles/docker/tasks/install.yml b/roles/docker/tasks/install.yml index e22bfb4..9671588 100644 --- a/roles/docker/tasks/install.yml +++ b/roles/docker/tasks/install.yml @@ -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] diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index be0652b..d5c2446 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -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 diff --git a/roles/docker/tasks/validate.yml b/roles/docker/tasks/validate.yml new file mode 100644 index 0000000..a4bf452 --- /dev/null +++ b/roles/docker/tasks/validate.yml @@ -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 diff --git a/roles/docker/vars/main.yml b/roles/docker/vars/main.yml new file mode 100644 index 0000000..0b4a600 --- /dev/null +++ b/roles/docker/vars/main.yml @@ -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 diff --git a/roles/gitea_runner/README.md b/roles/gitea_runner/README.md index 6f7b766..f908d26 100644 --- a/roles/gitea_runner/README.md +++ b/roles/gitea_runner/README.md @@ -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 `