Files
NODEDC_PLATFORM/infra/gitea-ci/README.md

241 lines
14 KiB
Markdown

# Synology CI foundation
This additive `gitea-ci` component creates only the Gitea build runner. It does
not activate automatic production apply, change Gitea itself, recreate Device
Core, open a port or modify application databases. Track activation in
DCPLATFORM-37; the canonical runner extension belongs to DCPLATFORM-21.
Initial policy: Device Core push to main automatically qualifies, then deploys
once the separate production controller and recurring release contract have
been accepted. Later repositories receive explicit registrations/policies.
## Reviewed contract
- Root: `/volume1/docker/nodedc-gitea-ci`.
- Compose project: `nodedc-gitea-ci`; selected service: `build-runner`.
- Three fixed data files: Compose, runner config, versioned descriptor.
- Runner and Node images use official Linux amd64 manifest digests (not mutable
tags), resolved from Docker Hub on 2026-09-29. The deploy runner pulls exactly
these two digests. No repository-provided image names or commands.
- Current Synology v4 profile: daemon and the single job share logical CPU7
through CPUSet. Their combined CPU ceiling is one logical CPU. Daemon:
CPU shares64, 512 MiB RAM+swap, readonly root filesystem. Job: CPU shares128,
2 GiB RAM+swap, no privileged mode, no host bind
mounts, no host execution label and no Docker socket in job containers.
- CPU shares also give low relative priority during contention. The NAS kernel
lacks a PIDs controller, so v4 does not set or claim a process-count limit.
V1/v2 retain their exact 0.5/1 NanoCPU quotas; v3 retains its shares-only/PIDs
profile. Historical configuration hashes are not changed.
- No published ports or host networking. Runner cache and metrics listeners
are disabled. Communication uses outbound HTTPS to the existing Gitea.
- Only the trusted runner daemon mounts the Docker socket. That daemon is
privileged infrastructure even with dropped Linux capabilities: access to
Docker is host authority. It is not passed to repository jobs.
- The first worker is registered for `SILVER/NODEDC_DEVICE_CORE`; sharing with
other repositories requires a reviewed enrollment/registry transition.
## Enrollment, separately from the artifact
Use the authenticated Gitea API to obtain the Device Core repository runner
registration token. Do not copy a personal Git token into the runner.
Stage `/volume1/docker/nodedc-deploy/runtime/gitea-ci/enrollment.pending.json`
through the operator's authenticated SMB session, containing only the exact
repository identity and its registration token. Never put this file in Git,
inbox, artifact payload, logs, Ops text or chat. This is a temporary handoff,
not the runtime secret. The NAS owner must be `dctouch` or root. The v2
preflight opens it with `O_NOFOLLOW`, rejects symlinks/hardlinks/special files,
limits the input to 2048 bytes, validates its schema and checks for concurrent
changes. Plan reports only safe filesystem metadata and does not change rights.
On 2026-09-29 the first v1 plan rejected this file's NAS metadata even though
the Mac SMB mount displayed 0700/regular/nlink1. A Mac `chmod 600` and a
successful Mac stat are not proof of the actual NAS permissions. V1's strict
private-file check is retained; use the explicit v2 import transition for SMB.
V2 apply creates the private file on NAS as root: `secrets/registration-token`
is 0600, its directory is 0700. Publication is atomic without overwriting an
existing identity, file and directory entries are fsynced, then the private
copy is revalidated. Only after that is the staging input removed. A mismatch
with an existing private copy is rejected. An interrupted apply can reuse the
same verified private copy after the canonical failure/retry review. Gitea
creates the persistent `/data/.runner` identity on first start. Neither private
file is part of the artifact, source backup, journal or diagnostic output.
The bootstrap accepts no existing installed CI descriptor or CI container.
Preflight reads Docker's actual resource capabilities before any runtime
mutation, and reports only allowlisted version/kernel/resource fields. V4
requires Linux amd64, CPUSet, CPU shares, memory/swap controls, at least eight
logical CPUs and CPU7 available in the installer's affinity. Acceptance also
verifies the actual daemon affinity is exactly CPU7. V3 requires a PIDs
controller; V1/v2 additionally require CFS period/quota. Missing or non-boolean
required capability values do not pass. Preflight also checks at least 8 GiB
free disk and 3 GiB currently available memory.
The v2 apply on 2026-09-29 imported the private token successfully and pulled
the pinned images, but Docker rejected `NanoCPUs`: this NAS kernel does not
provide the needed CFS bandwidth control. Canonical rollback completed with
`ok:gitea-ci-bootstrap`; the private enrollment is retained for v3 reuse.
Artifact `gitea-ci-bootstrap-v2-20260929-002` is terminal failed and must not be
restaged or retried. V3 uses separate reviewed `synology-v3/` configurations and
`bootstrap-v3.json`; historical payloads remain byte-for-byte reproducible.
The subsequent v3 plan established the actual host matrix: Docker24.0.2,
kernel4.4.302+, cgroupv1, x86_64, eight logical CPUs, MemTotal16743616512.
CPUSet/CPUShares/MemoryLimit/SwapLimit=true; CFS period/quota and PidsLimit=false.
It stopped before apply. V4 uses this verified matrix, with separate
`synology-v4/` templates and `bootstrap-v4.json`. The private token from the
rolled-back v2 attempt is reused. Neither v2 nor v3 is the next install target.
## Build and install
Before installing the runner, enable Actions at the **instance** level. On
2026-09-29, bootstrap v4 started correctly but could not register: the current
Gitea configuration explicitly contained `[actions] ENABLED=false`. The public
Actions Ping RPC returned 404 even though the REST registration-token endpoint
worked. The v4 attempt ended with `ok:gitea-ci-bootstrap` rollback; do not reuse
`gitea-ci-bootstrap-v4-20260929-004`. Increasing its registration deadline would
not enable the missing server routes.
The separate `gitea-actions-config` transition has exactly one data descriptor,
`deployment/actions-enable-v1.json`, built by `build_actions_artifact.py`. It
targets the existing `clean-gitea-20260820` container, using the verified
`/volume1/docker/gitea-clean-standalone-v1/compose.yaml` and `production.env`
context. The exact predecessor INI digest is registered in the root runner;
only the Actions boolean changes. Image, command, ports, bind mounts,
repositories, database and LFS remain in place. The existing Gitea container
restarts once, briefly interrupting Git web/SSH service. No Compose recreation,
image pull, new container, new listener or database rewrite occurs.
Plan verifies the effective source hashes, running container/mount/network/image
identity, healthy Gitea 1.27.2 and inactive Actions RPC. Apply keeps a root-only
configuration rollback copy under `nodedc-deploy/runtime/gitea-actions/<backup-id>`;
the shared source archive, artifact, Git, logs and Ops never receive its secrets.
The INI replacement preserves its owner and mode. Acceptance proves healthy
Gitea, the Actions Ping response, unchanged runtime configuration and the
unchanged identities/uptimes of every other container. Failure restores the
exact predecessor and restarts the same container; unrelated drift is rejected.
Install this transition first through runner promotion, fresh plan and apply.
Verify public Actions Ping after `deploy-ok`, then install a new CI bootstrap
patch on the unchanged v4 resource profile. CI preflight now requires the actual
public Actions Ping before runtime mutation. CI rollback records only fixed
startup-error categories/counts, never raw container logs or tokens.
```sh
python3 infra/gitea-ci/build_actions_artifact.py --patch-id gitea-actions-enable-v1-<unique-id> --source-commit <full-sha> --output-dir <output-dir>
```
### Recovery of Actions enable attempt 20260929-001
The first Actions apply stopped before replacing `app.ini` or restarting Gitea,
with `Gitea Actions runtime changed before mutation`. Its rollback repeated the
same fingerprint comparison and failed. Treat the failed archive, journal and
backup as evidence, not as permission to replay the artifact.
The legacy fingerprint compares `docker inspect` JSON including array order.
Docker 24.0.2 constructs
[mount points from a Go map](https://github.com/moby/moby/blob/v24.0.2/container/container_unix.go#L425-L440)
and [default ulimits from a map](https://github.com/moby/moby/blob/v24.0.2/daemon/oci_linux.go#L1012-L1026).
Their order can change without changing the container. Local tests reproduce the
false drift and preserve rejection of changed values, ordered command/env arrays,
image, ports and container identity. This explains a possible failure; the live
NAS must prove that it explains this specific attempt before another apply.
`actions-enable.v2` is a separate, bounded recovery for exactly that failed
attempt. Its read-only `plan` checks the failed journal, failed archive and saved
receipt digests, unchanged disabled config, leftover v1 descriptor, fixed Compose
context, same healthy Gitea and all other container identities/uptimes. For each
of the fresh inspections it must reconstruct the saved legacy fingerprint by
changing only Mounts and HostConfig.Ulimits order, retaining every field and value.
Duplicate mount destinations or limit names are rejected. Any unexplained
difference rejects the plan before mutation.
The initial v2 plan exposed a second algorithm defect: its up-front factorial
count exceeded 4096 before any matching was attempted. The corrected audit does
not enumerate permutations. It collects the actual orders returned by Docker,
their cyclic rotations, and rotations of canonical/reversed order. It tests
combinations of the two catalogs against the exact saved SHA-256; it never
assumes that an unobserved ordering is correct without that hash match. Each
fresh sample must have the same canonical fingerprint, so values from different
runtime configurations cannot be mixed into a proof. A direct legacy hash match
is also accepted without searching.
The audit collects at most 64 samples for the search and two further samples to
confirm a found proof. Each catalog has at most 256 orders, and at most 65536
distinct combinations are hashed; identical observations do not repeat the
search. These are bounds on read-only evidence collection, not on valid list
lengths via factorial size. An incomplete search fails closed with counts and
the last three fingerprint samples. The report never includes raw inspect data
or credentials. Regression tests cover 8 mounts/16 limits, a proof requiring
different observations for the two collections, changing values during sampling,
and exhaustion of the read-only search without mutation. This is an exact-match
search over a bounded candidate set, not an exhaustive solver for arbitrary
permutations; absence of a match is not itself proof of runtime drift.
Only after that plan has been reviewed can a separate apply repeat the audit
under the deploy lock and perform the same one-boolean transition. New comparison
and acceptance sort the two unordered collections. All other preservation checks
stay in force. A pre-mutation failure performs no Docker restart. A failure after
mutation restores the disabled config and removes only the v2 source descriptor;
the v1 marker and original failed evidence remain intact. The v2 backup records
the fingerprint version and reconciled attempt. Historical artifact bytes and
legacy Gitea recovery branches remain unchanged.
```sh
python3 infra/gitea-ci/build_actions_artifact.py --patch-id gitea-actions-enable-v2-<unique-id> --source-commit <full-sha> --output-dir <output-dir>
```
At preparation time, live order equivalence is still unverified and instance
Actions, build-runner registration and automatic production deployment remain
unfinished. Promote the reviewed root runner, run only a fresh read-only v2 plan,
review its three audit samples, and then decide the next registered action.
From a clean Platform commit:
```sh
python3 -m unittest discover -s infra/gitea-ci -p 'test_*.py'
python3 infra/gitea-ci/build_artifact.py --patch-id gitea-ci-bootstrap-v4-<unique-id> --source-commit <full-sha> --output-dir <output-dir>
```
The first use requires promotion of the reviewed root runner through the
separate atomic administrative gate and fresh `verify-install`. Stage the
immutable `.tgz` in the canonical inbox and inspect its lifecycle. Obtain a
fresh `nodedc-deploy plan`, review exact scope, then apply that artifact once.
`apply` snapshots the source partition and identities of all preexisting
containers. Acceptance checks the pinned image, Compose identity, mounts,
resource limits, privileges and absence of port publications. It requires
registration plus ten seconds of stable daemon operation and unchanged
preexisting container identities. All secrets and application data are outside
the artifact/backup source partition.
If startup or acceptance fails, rollback removes only `build-runner` and
restores only the three source paths. Runner registration and enrollment are
preserved for diagnosis. A failed attempt may leave an offline registration in
Gitea; do not create another token or delete persistent identity blindly.
The global failed-artifact replay rule remains in force.
After `deploy-ok`, verify online registration and a real qualification job via
Gitea API/UI. This is separate functional acceptance; do not ask an operator
to re-prove Docker/runtime checks with NAS shell commands. Do not describe the
runner bootstrap or a green build as a completed automatic production deploy.
## Validation baseline
Installed predecessor confirmed by the operator on 2026-09-29:
`f21936f131365bd3993e2d746e332538d628ba50ef62c1cce833161171ffde47`,
Python 3.8.15, `verify-install-ok`. This matches Platform commit
`11b73e64681f83aa2ebfd89ef266d3be2869f7e1`. The older SMB runner copy is not the
installed authority. Historical Gitea recovery guards remain unchanged.
Tests cover deterministic packaging, exact runtime/payload boundaries, secret
file handling, bootstrap reuse rejection, preserved container identity, real
synthetic-host apply receipts, and failed-health source rollback with runtime
registration retained. Existing Platform/Device/Gitea regression suites are
also required before promotion.
References: [official runner configuration](https://docs.gitea.com/runner/configuration/),
[Docker installation](https://docs.gitea.com/runner/installation/docker/),
[Docker resource constraints](https://docs.docker.com/engine/containers/resource_constraints/),
[Docker capabilities API](https://docs.docker.com/reference/api/engine/version/v1.40/).