Dry run 3880 showed that since #124 Renovate proposed no bump at all: - pip-compile: the manager refused the lock's header ("Option --newline=LF not supported (yet)"), extracted nothing and only logged a WARN, so the Python tools were never bumped. Drop --newline from scripts/lock-requirements.sh and the lock header (the 81 entries and hashes are unchanged); the manager now reads 81 dependencies. The lock is an image input: ci 0.2.19 -> 0.2.20. - pre-commit: every hook was skipped (skipReason github-token-required, no GitHub token exists), and with the warning off the GitHub GraphQL lookup is refused at once (403 rate limit). Look the hooks up with git ls-remote (packageRule overrideDatasource git-tags, which needs RENOVATE_GITHUB_TOKEN_WARN=false because the token check runs before package rules apply). Renovate dereferences annotated tags, so the new rev is the commit (checked against git ls-remote for conventional-pre-commit v4.5.0). git-tags has no release timestamps, so hook bumps are not automerged. Tested with [email protected].0 --platform=local against this checkout. Not tested: the real job (renovate.json is read from main), the lock replay by Renovate's pip-compile artifact step, and the ci 0.2.20 image build. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTRacjtXvmKxHr5TM5G
156 lines
12 KiB
Markdown
156 lines
12 KiB
Markdown
# CLAUDE.md
|
|
|
|
Guidance for Claude Code (claude.ai/code) in this repository.
|
|
|
|
## What this is
|
|
|
|
`mortis.kamino`: an Ansible Collection (GPL-3.0-or-later, REUSE-compliant), extracted role by
|
|
role from the author's homelab environment repository. The design contract is ADR 0004 (in the
|
|
maintainer's environment repository). Roles arrive here wave by wave; `docker` is in 1.0.0, `fail2ban` in 1.1.0, `network_interfaces` and `systemd_hardening` in 1.2.0, `system_baseline` in 1.3.0, `ufw` in 1.4.0.
|
|
|
|
Fork pull requests from untrusted users are not accepted for now: a fork controls its own
|
|
workflow file, so the `if:` guards are a convenience, not a boundary (see the header of
|
|
`molecule.yml`). Do not change visibility, repository settings, branch or tag protection,
|
|
or create tags: those are the operator's.
|
|
|
|
## Working here
|
|
|
|
- Set up once per clone: `scripts/dev-setup.sh` (a virtualenv with the pinned tools and git
|
|
hooks that find them). The `language: system` hooks run `reuse`, `ansible-lint` and
|
|
`antsibull-changelog` by name, so a hook run without that virtualenv on `PATH` fails.
|
|
- Agent skills come from holocron through apm: `apm install` (the `apm` CLI is not one of the
|
|
pinned tools, and `dev-setup.sh` does not run it) deploys them to `.claude/skills` and
|
|
`.claude/agents`, both gitignored like `apm_modules/`. `apm.yml` and `apm.lock.yaml` are the only
|
|
tracked files. The entries are unpinned on purpose (see the comment in `apm.yml`); `apm install
|
|
--update` moves them. They are tooling, so `galaxy.yml` `build_ignore` keeps them out of the Collection.
|
|
- **Commit with git in a clone, never through the Gitea API.** The hooks (REUSE, yamllint,
|
|
actionlint, ansible-lint, gitleaks, changelog lint, Conventional Commits) only run in
|
|
`git commit`; an API commit skips them and CI finds the problem after the push. The first
|
|
hook run builds the Go hook environments and takes minutes: run commits in the background.
|
|
`git push` also runs `ansible-test sanity` on HEAD (`scripts/ansible-test-sanity.sh`, the Build
|
|
job's check, which ruff and the other hooks do not cover); its first run builds virtualenvs and takes minutes.
|
|
- Feature branch and pull request; `main` and `v*` tags are protected. Never push to `main`.
|
|
Releases are the operator's: annotated `vX.Y.Z` tags equal to `galaxy.yml`'s version.
|
|
- Conventional Commits. A PR says what was verified and what was not.
|
|
- There is no local molecule and no container runtime on the control host: do not install one.
|
|
Molecule runs in CI, on the repository's own runner (label `kamino-molecule`).
|
|
- Changes that can affect a consumer need a changelog fragment (`changelogs/fragments/`).
|
|
New files are covered by `REUSE.toml`; third-party-derived content needs its own annotation.
|
|
|
|
## Agent skills
|
|
|
|
### Issue tracker
|
|
|
|
Issues live in Gitea Issues on `mortis/kamino`, used through the `gitea-issues` skill and the Gitea MCP tools. See `docs/agents/issue-tracker.md`.
|
|
|
|
### Triage labels
|
|
|
|
The five triage roles map onto the repo's scoped `Status/` and `Reviewed/` labels. See `docs/agents/triage-labels.md`.
|
|
|
|
### Domain docs
|
|
|
|
Single-context: `GLOSSARY.md` and `docs/adr/` at the root, both created lazily. See `docs/agents/domain.md`.
|
|
|
|
## Workflows (`.gitea/workflows/`)
|
|
|
|
- Never `pull_request_target`. A fork `pull_request` run gets no secrets and a read-only job token; a same-repo pull request does get the org Actions secrets, so nothing but `image.yml` may reference them. Pass ref, repo and name values to
|
|
scripts through `env:`, never interpolate `${{ github.* }}` into a `run:` block.
|
|
- Runner labels are `kamino-docker` and `kamino-molecule` only (`.gitea/actionlint.yaml`). Use
|
|
the `github.*` contexts, which Gitea aliases; actionlint does not know `gitea.*`.
|
|
- Lint and Build run in the `ci` image. After the checkout they compare the pin files with the
|
|
checksums baked into the image: a PR that changes `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml` or
|
|
`.pre-commit-config.yaml` takes the slower path that installs the pinned tools and collections.
|
|
- Molecule runs on every same-repo pull request, Renovate's included (a new image is tested by its own pin
|
|
pull request), with no workflow path filter, so that it can be a required check. Fork pull requests are skipped.
|
|
What a pull request runs is chosen by `scripts/select_molecule_scenarios.py`, run from the base branch's copy
|
|
(a pull request cannot edit its own rules): only the scenarios of the roles it changes, none for a diff of
|
|
only its IGNORED paths, a failure for a changed role with no scenario, and every scenario for any other file,
|
|
for every push to `main`, for manual dispatch and for the nightly run (04:43 UTC, after Renovate's). A new file outside `roles/<role>/` runs everything until it
|
|
is added to IGNORED, which is right only when no scenario reads it. A new commit cancels the pull request's
|
|
running Molecule run, and the step first removes containers a cancelled run left; two runs never overlap
|
|
because the runner has a single slot, so raising its capacity needs a lock or a shared concurrency group.
|
|
- Every scenario sets `scenario.test_sequence` to molecule's default minus the leading `destroy` (the workflow
|
|
clears stale containers first, and the molecule state lives in the job's own `ANSIBLE_HOME`, so a killed run leaves
|
|
none behind); copy it into a new scenario.
|
|
- Molecule discovers `extensions/molecule/*/` and `roles/*/molecule/*/`. The `image-smoke`
|
|
and `image-smoke-2604` scenarios test the molecule images themselves (24.04 and 26.04); a role scenario that
|
|
must pass on both takes `image: ${MOLECULE_IMAGE}` or `${MOLECULE_IMAGE_2604}` per platform.
|
|
|
|
## Images (`images/`)
|
|
|
|
- `ci`, `molecule-ubuntu2404` and `molecule-ubuntu2604`, built by `image.yml` with kaniko on push to `main` (never on
|
|
pull requests) and pushed to `git.rkdr.net/mortis/<name>`.
|
|
- The molecule images are one Ubuntu release each, by name: the hosts run 24.04 today and 26.04 is the
|
|
target, so roles are tested on both. A new release is a new image added by hand (Renovate's major `ubuntu`
|
|
updates are disabled everywhere); retire an image when no host runs its release. A new image's
|
|
first consumer pin is a hand-made PR with the digest its first build printed; Renovate follows it after.
|
|
- Each has a semver `version:` in the workflow's build matrix. A published version tag is never
|
|
moved and never rebuilt (the job looks it up in the registry first and ends without building):
|
|
bump the version in the PR that changes the image. A new version is pushed as `<version>` and
|
|
`latest`; there is no `sha-*` tag, so one digest belongs to exactly one version.
|
|
- `ansible-test sanity` ignores live in `tests/sanity/ignore-common.txt`; the Build job copies
|
|
it to the file name of the installed core version in its throwaway worktree (a committed
|
|
`ignore-<MAJOR.MINOR>.txt` is appended for findings of one version only).
|
|
- Consumers pin `image:<version>@sha256:<digest>` (`lint.yml`, `build.yml`, `molecule.yml`).
|
|
A build prints the new digest; moving a pin is a reviewed edit, and every build has a new
|
|
digest.
|
|
- kaniko runs inside the job container and unpacks the image it builds over it, so each matrix entry names its
|
|
job container (`job_image: ubuntu:<release>@sha256:...`) and its release must equal the `FROM ubuntu:` release
|
|
of the image's Dockerfile (`check_image_versions.py pins` fails otherwise). Moving an image to a new release is one edit: the Dockerfile `FROM`, the `job_image`
|
|
tag and digest, and the version bump. Digest drift within a release is tolerated. A `job_image`-only bump is
|
|
not an image input: no version bump, nothing rebuilt; the post-merge Images run only reaches the prepare step
|
|
for published versions, so that is its only exercise.
|
|
- Image metadata: Gitea's package page shows the description as plain text (no markdown), lists every label,
|
|
and links source, documentation and licence; it renders no README. So each Dockerfile carries the same
|
|
label block (`org.opencontainers.image.*` plus `net.rkdr.mortis.purpose/contents/usage`), the build adds
|
|
`version`, `revision` and `created`, and the readme-style text lives in `docs/images/<name>.md`, which the
|
|
`documentation` label links to. `check_image_versions.py pins` fails when a label or that file is missing.
|
|
The docs sit outside the image directories on purpose: editing them is not an image input, so it needs no
|
|
new version. Editing a label in a Dockerfile is an input and does.
|
|
- Each pushed layer must stay below 100 MB: Cloudflare rejects larger request bodies with
|
|
HTTP 413. That is why the `ci` image deletes the Go toolchains from the hook cache.
|
|
- `image.yml` is the only workflow that may reference the org Actions secrets (the registry push credential). Never print or use them anywhere else.
|
|
|
|
## Dependency automation (Renovate)
|
|
|
|
`renovate.json` is run by `.gitea/workflows/renovate.yml` (daily cron and `workflow_dispatch`) on the
|
|
`kamino-docker` runner, as a Kamino-only bot user, so code from this repository never runs in the
|
|
maintainer's production environment. Never reuse another Renovate credential here.
|
|
|
|
- **Policy:** minor and patch bumps automerge, majors are manual; the Lint and Build checks are the gate.
|
|
A new Ubuntu release is a deliberate edit, never a bump. The `job_image` of each matrix entry in `image.yml`
|
|
never automerges: that job holds the registry push credential. kaniko is pinned by layer digests in
|
|
`image.yml` and updated by hand.
|
|
- **Two-PR loop for an image input** (`requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml`, `.pre-commit-config.yaml`, `images/**`): PR 1
|
|
carries the input change plus the PATCH bump of the image `version:` in `image.yml`
|
|
(`scripts/bump_image_versions.py [<base-ref>]`; `check_image_versions.py bump` then passes; Renovate runs it
|
|
as a post-upgrade task). The merge builds the image on `main`. PR 2 moves the consumers' pins to the new
|
|
digest (Renovate's pin-follow rule for the `mortis/*` images; a major version stays manual).
|
|
- **Python tool pins and their lock:** `requirements-dev.txt` holds the direct pins, `requirements-dev.lock` is
|
|
their hashed lock (installed with `pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt`;
|
|
pip refuses an unhashed package and any disagreement between the two). Renovate's `pip-compile` manager bumps
|
|
a pin and regenerates the lock by replaying the lock's header command; a weekly lock-file-maintenance PR
|
|
moves transitive packages and is never automerged. By hand: `scripts/lock-requirements.sh [--upgrade]`.
|
|
The header must hold only options Renovate knows: it refuses `--newline=LF` ("not supported (yet)"),
|
|
extracts nothing, and proposes no bump, with only a WARN in an otherwise green run.
|
|
Hook repositories in `.pre-commit-config.yaml` are pinned by commit SHA with a `# frozen: vX.Y.Z` comment.
|
|
Renovate looks them up with `git ls-remote` (packageRule `overrideDatasource: git-tags` plus
|
|
`RENOVATE_GITHUB_TOKEN_WARN=false` in `renovate.yml`), because there is no GitHub token and the default
|
|
`github-tags` lookup is skipped or rate limited. A hook bump is never automerged: `git-tags` has no release
|
|
timestamps, so `minimumReleaseAge` cannot delay it. After a Renovate config change, test it locally before
|
|
the merge: `renovate --platform=local` (same version as `renovate.yml`) reads this checkout; a dry run in
|
|
Actions reads `renovate.json` from `main`.
|
|
- **Bot-diff gate:** `scripts/check_bot_pr_diff.py` runs in the lint workflow, from `origin/main`'s copy so a
|
|
pull request cannot weaken it. A `renovate/` head ref may only change version lines (tool pins and their lock
|
|
entries and hashes, hook `rev:` lines, Dockerfile FROM tags and digests, matrix `version:` lines, `job_image:` pins, consumer image pins);
|
|
anything else fails, `renovate.json` included. The branch name is attacker-controlled, so this only
|
|
constrains the bot's own pull requests.
|
|
- **No Collection release from tooling bumps:** tooling files are in `galaxy.yml` `build_ignore`. A
|
|
role-visible change needs a changelog fragment and a new `galaxy.yml` version; only the operator tags.
|
|
- **No production images:** `check_image_versions.py pins` fails when anything under `.gitea/workflows`
|
|
mentions the maintainer's production image namespace.
|
|
- **Hand edits on a bot branch:** a commit pushed by hand to a `renovate/` branch makes Renovate stop
|
|
rebasing it, so merge that pull request by hand.
|
|
- **The runner has a single slot:** the Renovate job (up to 30 minutes) delays Lint, Build and Molecule.
|
|
- **Open item:** do not enable automerge for bot PRs until a live run has shown that they get Lint and Build.
|