Add canonical outbound Device Core deployment controller

This commit is contained in:
Codex
2026-09-29 21:25:03 +03:00
parent d46ecc4cb1
commit f7416bc59a
11 changed files with 1757 additions and 18 deletions
+68 -9
View File
@@ -1,7 +1,8 @@
# Device Core recurring deployment
Status: 2026-09-29. The build runner is installed and push-to-main qualification
works. Production polling is **not activated**. DCPLATFORM-21 owns the deployment
works. Release r7 (`edf69068ec64e3d105d5324d39b8eaeface21215`) is accepted
in canonical ledger 385. Production polling is **not activated**. DCPLATFORM-21 owns the deployment
contract; DCPLATFORM-37 tracks activation.
## Release domain
@@ -42,17 +43,75 @@ for earlier pending runs, records artifact reservation before installation, skip
duplicate/already superseded sources, and requires a canonical journal/archive
receipt after a crash. It does not discover API pages or prove Git ancestry.
## Outbound controller v1
`gitea_source.py` verifies complete stable API pagination, exact repository/run/job
identity and successful qualification steps. Commit-parent traversal proves
installed → candidate → current main. Downloads accept only the API origin and
Gitea's exact signed `/zip/raw?sig&expires` redirect for the same artifact ID;
the persistent Authorization token is removed from that redirected request.
ZIP entries, uncompressed bounds and release receipt are checked before the
canonical TGZ loader independently validates the release.
`controller.py` refreshes discovery, enforces queue order, stages and plans through
an injected canonical installer, rechecks qualification/ancestry, durably reserves,
then invokes apply. It reconciles canonical journal + archive digest + backup after
success, failure or restart. Missing/contradictory evidence stops further installs;
network errors before reservation preserve the ready queue. Failed CI is skipped,
pending CI retains its place, and completed releases are never installed twice.
`embed_library.py` deterministically places these pure modules inside the reviewed
standalone root runner as ordinary Python in a private lexical scope. There is no
runtime import from SMB, dynamic exec or script payload. Tests compare embedded
bytes against source modules.
The `device-core-autodeploy` bootstrap contains only
`deployment/device-core-autodeploy-v1.json`. Its fixed identity is
`device-core-autodeploy-v1-20260929-001`. The root installer creates exactly two
previously absent native units under `/usr/local/lib/systemd/system`:
`nodedc-device-autodeploy.service` and `.timer`. The timer starts 120s after boot
(or immediately when installed after that point), then 30s after each worker
completion. There is one worker, protected by flock, plus the existing canonical
deployment lock. It opens no listener and requires no Mac to remain online.
Commits from any computer qualify through the same Gitea main branch.
Native systemd, trusted Python/systemctl paths and absence of unit collisions are
preconditions, checked in plan before mutation. No unsupported CFS/Pids controls
or fallback schedulers are assumed. The service invokes only the internal fixed
`/usr/bin/python3 /usr/local/sbin/nodedc-deploy --device-core-autodeploy-tick` entry.
Its worker requires a successful canonical bootstrap receipt/archive before any
release installation, preventing an early timer firing from bypassing acceptance.
The dedicated `read:repository` token is imported from a bounded operator handoff
under `nodedc-deploy/runtime/device-core-autodeploy/enrollment.pending.json` into
`/var/lib/nodedc-device-autodeploy/gitea-read-token` (root:root 0600, directory0700).
It is absent from artifacts/build jobs/logs. The operator staging file is removed
only after private-copy verification. SQLite and private status live in the same
private directory. A sanitized `runtime-status.json` under the bootstrap descriptor
root gives SMB-readable operational status; it never authorizes installation.
Gitea's scope applies to repositories visible to that account; the controller's
API route allowlist is fixed to repository38.
Bootstrap preserves all existing containers and the accepted r7 application tree.
It verifies unit bytes, effective FragmentPath/no drop-ins, enabled/active timer,
private credential metadata, API qualification and health. Rollback removes only
its new units and descriptor; it retains private credentials/queue and all apps.
The activation floor is run8, so historical r5/r6 cannot enter automatic delivery.
The frozen generic `run_compose` function is byte-identical to the previous Engine
canon. Device Core uses its own exact Core+Manager Compose entry with unchanged
`--pull never --no-build --no-deps`, including rollback.
## Remaining activation work
- Implement outbound authenticated Gitea polling with complete pagination and
refresh of pending runs; verify repository, run, jobs, artifact and Git ancestry.
- Import a narrowly scoped read token into root-private controller runtime.
- Add and test the canonical controller bootstrap domain and fixed service unit.
- Install via the root runner, then accept push → qualified artifact → canonical
plan/apply, serial commits, failed tests, rollback and restart recovery on NAS.
- Promote the reviewed root runner through the separate SHA-pinned admin gate.
- Build/stage the bootstrap via `build_autodeploy.py`, then fresh plan and apply.
- Accept a new main commit through CI → automatic canonical deployment, including
ordered commits, failed checks and recovery. Source tests are not NAS acceptance.
- Remove the temporary Mac token copy after private NAS import is verified.
No helper from this directory is installed by an application release. Do not run
helper code from SMB or use Docker as a deployment shortcut.
No helper from this directory is executed on NAS or installed by an application
release. User-facing NAS deployment commands remain canonical plan/apply.
## Validation