Renovate puts the job token in the clone URL, which git drops when the server redirects (dry run 2439: could not read Username). Write a global git http.extraheader like lint.yml does. Renovate exits 0 on a repository failure: set exitCodeForErrors and check the JSON report for a missing file or ERROR/FATAL problems. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
141 lines
11 KiB
Markdown
141 lines
11 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 repo (`Defame1297/ansible-homelab-mono`). The
|
|
design contract is ADR 0004 in that repo (`docs/adr/0004-collection-consumption-and-release.md`)
|
|
and the tracking issue is its epic #486. There are no roles here yet: wave 1 arrives with the
|
|
extraction.
|
|
|
|
The repo is **private and takes no fork pull requests** until the author has verified the
|
|
isolation of its CI runner. 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.
|
|
- **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.
|
|
- 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.
|
|
|
|
## 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` or
|
|
`.pre-commit-config.yaml` takes the slower path that installs the pinned tools.
|
|
- Molecule discovers `extensions/molecule/*/` and `roles/*/molecule/*/`. The `image-smoke`
|
|
scenario tests the molecule image itself.
|
|
|
|
## Images (`images/`)
|
|
|
|
- `ci` and `molecule-ubuntu2404`, built by `image.yml` with kaniko on push to `main` (never on
|
|
pull requests) and pushed to `git.rkdr.net/mortis/<name>`.
|
|
- Each has a semver `version:` in the workflow's build matrix. A published version tag is never
|
|
moved (the job looks it up in the registry first): bump the version in the PR that changes
|
|
the image.
|
|
- 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.
|
|
- 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` tries the job token first with a write probe; Gitea 28 refuses it for the org's packages
|
|
(HTTP 401, run 2237), so the push uses the org Actions secrets `PACKAGE_PUSH_USER` and
|
|
`PACKAGE_PUSH_TOKEN`. Never print or use them anywhere else.
|
|
|
|
## Dependency automation (Renovate)
|
|
|
|
`renovate.json` is run by `.gitea/workflows/renovate.yml` (see below). Items marked unverified have not run yet.
|
|
|
|
- **Policy:** minor and patch bumps automerge, majors are manual. `ansible-core` minor and major
|
|
are manual too (a new minor needs a `tests/sanity/ignore-2.NN.txt`), and `ansible-core` and
|
|
`ansible-lint` bump in one group. Dockerfile base-image tag and digest bumps (`images/*/Dockerfile`)
|
|
stay automergeable: Kamino is the untrusted side and the pin PR's CI exercises the new image. The
|
|
`ubuntu` job container of `image.yml` never automerges: that job holds the registry push credential.
|
|
kaniko is pinned by layer digests in `image.yml`; no Renovate manager reads them, so it is updated by
|
|
hand (the `/kaniko/` rule in `renovate.json` is only a safety net).
|
|
- **Two-PR loop for an image input** (`requirements-dev.txt`, `.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>]`, idempotent, edits only the
|
|
version line; `check_image_versions.py bump` then passes). The merge builds the image on
|
|
`main`. PR 2 moves the consumers' `image:<version>@sha256:<digest>` pins to that digest.
|
|
`renovate.json` runs the script as a `postUpgradeTasks` command of a catch-all rule (matches every package, since
|
|
only the first upgrade of a branch counts; branch mode, file filter `image.yml`; allowed by the one anchored regex in `RENOVATE_ALLOWED_COMMANDS` of `renovate.yml`),
|
|
so PR 1 carries the bump. PR 2 stays a hand edit until Phase 4 (pin-follow for
|
|
`git.rkdr.net/mortis/*` is `enabled: false`; it needs a dry run against the registry first).
|
|
- **Bot-diff gate:** the `lint` workflow runs `scripts/check_bot_pr_diff.py` on pull requests. A
|
|
head ref starting `renovate/` may only change version lines in `requirements-dev.txt`, `rev:`
|
|
lines in `.pre-commit-config.yaml`, FROM tags/digests and the `uv==` pin in `images/*/Dockerfile`,
|
|
the matrix `version:` lines and the ubuntu job container pin in `image.yml`, and the image
|
|
pins in `lint.yml`, `build.yml` and `molecule.yml`. Anything else fails, `renovate.json` included.
|
|
Tags are `[A-Za-z0-9._-]` only, FROM and ubuntu lines must keep their digest, matrix versions must stay in
|
|
place and rise, and a binary or one-sided change fails.
|
|
The branch name is attacker-controlled, so this only constrains the bot's own pull requests; its
|
|
purpose is that automerging them cannot alter workflow logic or reach the org secrets.
|
|
- **No Collection release from tooling bumps:** everything involved is in `galaxy.yml`
|
|
`build_ignore`, so the Collection archive and version do not change. A role-visible change needs
|
|
a changelog fragment and a new `galaxy.yml` version, and only the operator tags.
|
|
- **No production images:** `check_image_versions.py pins` fails when anything under
|
|
`.gitea/workflows` mentions `git.rkdr.net/defame1297/`.
|
|
- **Where Renovate runs:** `.gitea/workflows/renovate.yml`, a daily cron (03:17 UTC) plus
|
|
`workflow_dispatch`, on the `kamino-runner` (`kamino-docker`): the untrusted side, so code from this
|
|
repository never runs in the production cluster (ADR 0004). It authenticates with the workflow's own
|
|
job token (`secrets.GITHUB_TOKEN`): no new account, no secret, and no org secret (only `image.yml` may
|
|
reference those). The job container is `renovate/renovate:<version>-full@sha256:...` from Docker Hub
|
|
(the `-full` flavour for `python3`), same version as the cluster's CronJob, hand-bumped (renovate.json
|
|
disables updates for the workflow file). Lookups of the github.com pre-commit hooks are
|
|
unauthenticated (no `RENOVATE_GITHUB_COM_TOKEN` exists) and may hit rate limits: best effort.
|
|
- **Dry run:** Actions > Renovate > Run workflow with `dry_run=true` (the default for a manual run;
|
|
sets `RENOVATE_DRY_RUN=full`, `LOG_LEVEL=debug`). Read the debug log: no branch or PR is created. The
|
|
schedule runs live. The job fails (it used to stay green) when Renovate exits non-zero
|
|
(`RENOVATE_EXIT_CODE_FOR_ERRORS`, 7 for a failed clone) or when the JSON report
|
|
(`RENOVATE_REPORT_TYPE=file`) is missing or holds an ERROR or FATAL problem; warnings do not fail it.
|
|
A first good dry run shows a clone (no `external-host-error`, no `could not read Username`).
|
|
- **Open item: the first live run (do not enable automerge for bot PRs until one has shown it gets Lint and
|
|
Build).** The dry run proves the READS (lookups, config, branch plan) and, from the Renovate 44.161.0
|
|
source (confirm by the log line for the post-upgrade task), also runs `postUpgradeTasks`. Only the first
|
|
LIVE run proves the writes: (1) that the job token can push a branch and open a PR. Git auth: Renovate
|
|
puts the token in the clone URL, which git drops on a redirect (dry run 2439 failed so: `could not read
|
|
Username`). `renovate.yml` therefore writes a global git config `http.<server>/.extraheader`
|
|
(`AUTHORIZATION: bearer <job token>`, like `lint.yml`); Renovate does not pass `GIT_CONFIG_*` from its
|
|
environment to git but does pass `HOME`. Unproven until a run clones. (2) That PRs opened with the job token trigger the PR workflows: Gitea, like GitHub, may not
|
|
start workflows for events created by the job token, in which case the required `Lint` and `Build`
|
|
checks never run and automerge cannot work. If so, the decision is the operator's: either push the PR
|
|
with a user token held as a repo secret from a Kamino-only user, or have `renovate.yml` dispatch lint
|
|
against the branch; until then bot PRs need a manual run. (3) That bot PRs are held by `main`'s required
|
|
status checks (check the branch protection). Also confirm in the log: Renovate clones blobless with full
|
|
history, so `origin/main` exists for the script (source-based); `python3` is in the image; the
|
|
`permissions:` block is enforced on this Gitea; `github.head_ref` is populated (the gate fails closed
|
|
on an empty one, via `EVENT_NAME`). Safety net: a failing or disallowed post-upgrade command opens the
|
|
PR WITHOUT the bump plus a red `renovate/artifacts` status, and `check_image_versions.py bump` then
|
|
fails lint.
|
|
- **The workflow holds the runner's slot:** the `kamino-runner` host has a single slot (the label is
|
|
`kamino-docker`), and the Renovate job may run up to 30 minutes (`timeout-minutes`) from 03:17 UTC, so
|
|
Lint, Build and Molecule checks queue behind it.
|
|
- **Not enabled yet:** credentials for the `git.rkdr.net` registry (`hostRules`) and pin-follow. The
|
|
`pre-commit` manager is beta.
|
|
- **Hand edits on a bot branch:** a commit pushed by hand to a `renovate/` branch makes Renovate treat
|
|
the branch as modified: it stops rebasing it, so merge that pull request by hand.
|
|
- **The guard runs from `main`:** the lint step extracts `scripts/` from `origin/main` and runs the
|
|
guard from there, so a pull request cannot weaken its own gate (the PR copy runs only while `main`
|
|
has no guard). A change to the guard takes effect for other PRs after it merges.
|
|
- A pin-only pull request (only `lint.yml`, `build.yml`, `molecule.yml`) does not match any
|
|
`image.yml` push path (`images/**`, `requirements-dev.txt`, `.pre-commit-config.yaml`,
|
|
`.gitea/workflows/image.yml`), so it rebuilds nothing.
|