Files
ops-docs/maintenance/woodpecker-ci.md
T

121 lines
7.3 KiB
Markdown

# Woodpecker CI (server + agent)
Self-hosted CI for the co-op's repos. **As of 2026-11-11 the CI is WORKING
end to end for push-gated test runs** — `co-op/docs` (manual, build+deploy),
`code/member-portal` and `code/admin-panel` (push-triggered test gating). Read
the *Current state* section for what is proven and the traps that remain.
Two Cloudron apps, added 2026-11-03:
| App | FQDN | Cloudron id | Image |
|---|---|---|---|
| Woodpecker **server** | `ci.inference.coop` | `4984f95e-0c0a-4af3-9ce1-4ca4f3e8483d` | `cloudron/org.woodpecker_ci.cloudronapp:202610300219490000` (store, v2.22.1 / upstream 3.20.1) |
| Woodpecker **agent** | `ci-agent.inference.coop` | `5ac63873-cf2c-4ad9-acd6-81dc0e016c83` | `registry.inference.coop/co-op/woodpecker-agent:20261104-e070275` (**custom**) |
- The **server** is the stock Cloudron app. It uses the `mysql` addon for storage
and exposes `GRPC_PORT` 9000 to the agent. Its config lives in
`/app/data/env.sh` (`WOODPECKER_GITEA`, `WOODPECKER_ADMIN`,
`WOODPECKER_AGENT_SECRET`, `WOODPECKER_OPEN`, …). **No env vars are set through
the app's Cloudron env** (`env-keys` is empty) — everything is in that file.
- The **agent** is a custom app. Its config is set as Cloudron env (names only):
`WOODPECKER_SERVER` = `ci.inference.coop:9000`, `WOODPECKER_GRPC_SECURE=true`,
`WOODPECKER_BACKEND=local`, `WOODPECKER_MAX_WORKFLOWS=2`,
`WOODPECKER_AGENT_CONFIG_FILE=/app/data/agent.conf`, plus the shared
`WOODPECKER_AGENT_SECRET`.
## Why the agent image is custom (and why the backend is `local`)
Cloudron apps have **no Docker socket**, so the default `docker` backend cannot
run and the agent uses the **`local` backend**: each pipeline step executes as a
shell command *inside the agent container*, and a step's `image:` field selects
the **shell**, not a container image. Consequence: **every tool a pipeline step
needs must be baked into the agent image**, and the Cloudron rootfs is read-only
at run time, so nothing can install at run time.
The image is `FROM woodpeckerci/woodpecker-agent:v3.20.1-alpine` (the **alpine**
variant — the default `scratch` image has no shell). It adds `bash`, `git`,
**`git-lfs`**, `tar`, `ca-certificates`, `python3`, `node`/`npm`, the `cloudron`
CLI, and a pinned MkDocs toolchain at `/opt/docs-venv`. It **runs as root**
(`/app/data` on this Cloudron is root-owned, as for the other custom apps here).
## Building and pinning the agent image
- **Source repo:** `/home/ubuntu/repos/woodpecker-agent` on the agent host.
⚠️ **This repo has no git remote and has never been pushed to Gitea** — the CI
agent's build source exists only on the agent host. Treat that as a gap to close.
- **Tag convention:** `<yyyymmdd>-<gitsha>` (e.g. `20261104-e070275`). Never a
floating tag.
- **Build:** `~/.hermes/scripts/cloudron_builder_build.sh registry.inference.coop/co-op/woodpecker-agent <tag> <dir>`
(the script carries the registry auth triple, which is not optional).
- **Deploy:** write the new tag into `CloudronManifest.json`'s `dockerImage`,
commit, build `--no-cache`, then `cloudron update --app 5ac63873-…` **without**
`--image` (the manifest's pin wins). Verify by the running image tag **and**
something only the new build produces — never by exit code alone.
- `publishing-requirements.txt` mirrors the docs repo's
`publishing/requirements.txt`; **keep the two in step** when the docs toolchain
changes.
## Current state (2026-11-11): push-gated test CI is live
- **The server-side gRPC 500 was never the blocker.** The agent's `Next`
long-poll is cut short by the platform proxy every ~10 minutes (nginx
`upstream timed out`, `could not find named location "@grpc_unavailable"`)
and the agent retries — pipelines are collected and executed regardless.
Re-confirmed 2026-11-11: the 500s continue in the log while push-triggered
pipelines run green. Do not chase it.
- **API access:** a personal token for `inference-admin` lives at
`/home/ubuntu/.hermes/woodpecker.key` (mode 600). Repo enablement is
`POST /api/repos?forge_remote_id=<gitea repo id>` (query param, not body);
a manual run is `POST /api/repos/<id>/pipelines` with `{"branch": "..."}`.
- **Enabled repos:** `co-op/docs` (id 1), `code/member-portal` (id 2),
`code/admin-panel` (id 3). Note `co-op/member-portal` is a Gitea REDIRECT to
`code/member-portal` — the canonical repo lives in the `code` org (Gitea id 6).
- **Test gating (added 2026-11-11):** `.woodpecker.yml` on both apps' default
branches runs their EXISTING suites on every push (12 portal test files;
admin-panel guest-guard test + 4 page-JS harnesses via the vendored
`tests/check-page-js.sh`). Gitea branch protection on `main` of both repos
now requires the status context `ci/woodpecker/push/woodpecker` to merge.
- **Proven with real output:** first push runs green (portal tests step: 439
log lines ending "all portal test suites green"; all four harnesses OK on
the panel), and a deliberately broken assertion on a branch (`ci-red-test`)
produced pipeline #2 **failure** with the failing status context on Gitea —
the gate signal works. The branch was deleted after the proof.
- **The agent's python is 3.14** (agent image base) — the portal's PINNED
requirements (pydantic 2.9.2, psycopg2-binary 2.9.9) have no cp314 wheels,
so the portal pipeline installs a bounded-range subset (fastapi/httpx/PyJWT/
slowapi/cryptography) instead of `-r requirements.txt`. See
`code/member-portal/.woodpecker.yml` for the rationale.
## When a pipeline runs (and when it does not)
- `co-op/docs`: **manual-trigger only** by deliberate decision (the poll
watcher remains the live auto-deploy path until the operator says otherwise).
- `code/member-portal`, `code/admin-panel`: fire on every **push** (any
branch) and can also be triggered manually.
- **`git-lfs` is required by the clone step.** Woodpecker runs `git lfs fetch`
after cloning, so a clone step fails with
`git: 'lfs' is not a git command` on any image without it — this was added to
the agent image on 2026-11-04. If a rebuild ever drops it, clones break again.
## Historical state (2026-11-04): installed, agent connected, could not run jobs
Superseded by the section above. Kept because each entry was a lesson:
the health endpoint lied by omission (liveness, not capability), the missing
git-lfs broke every clone, the missing repo secret (`cloudron_token`) made the
config fail to PARSE with the reason visible ONLY in the web UI, and the gRPC
500s were misread twice as the blocker before pipeline #2 proved otherwise.
The repo-enablement login gate (operator completes Gitea OAuth once) was
cleared the same day: the `inference-admin` user exists with admin rights.
## Enabling a repo (known gate — cleared 2026-11-04)
- Repos are connected through the **Gitea** source (`WOODPECKER_GITEA`). The
OAuth login source was stood up by the operator and the `inference-admin`
user exists (admin). Enabling further repos is now a pure API call (see
*Current state*), not an operator step.
- Reading run/pipeline state is done from the server's **MySQL** database, not
from a public API, when the API view is thin (the pipeline endpoint does not
expose step logs; `log_entries` in the database does).
- Note: the whole point of this CI is to take the docs build and custom-app builds
off the agent host — see `co-op/support#30` (moving `REGISTRY_BUILD_TOKEN` to CI).