feat: add a panel button to update the manager itself

The manager clones SELF_UPDATE_REPO_URL, builds a new image in the shared build queue and
hands over to a short-lived updater container (new image) that swaps the manager container,
health-checks it and rolls back on failure. Exposed as GET/POST /api/system behind requireAuth;
installation changes answer 409 while an update runs. Session cookie is now SameSite=Lax.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Sonnet 5.5 committed 2026-10-19 05:45:25 +02:00
1 parent 5fb1d6b0b4
commit 4b3c8f213a
23 files changed
+705 -5

No files matched your search

+36
View File
@@ -29,3 +29,39 @@ yourself on hosts that support it.
`activeProxyRequests`. A heap that keeps climbing between restarts, or an
`activeProxyRequests` that stays high with no traffic, points at a leak. A line
`memory guard: ... restarting` in the manager's log means the guard fired.
## Updating the manager from the panel
The **Manager** card on the installations page has an *Update manager* button. It is enabled when
`SELF_UPDATE_REPO_URL` is set (operator-only env var, never taken from a request) and the manager
runs in a container whose id it can inspect (production compose; not local `npm run dev`).
Flow:
1. In the serial build queue (so it never overlaps an installation build) the manager clones
`SELF_UPDATE_REPO_URL` at `SELF_UPDATE_REF` (default `master`) and runs `docker build` on it.
Refused with `409` if an installation is cloning/building/starting.
2. It starts a short-lived **updater container** from the *new* image
(`node dist/system/selfUpdateHelper.js`, label `remote-mcp-manager.self-update-helper`). A
manager cannot replace itself: stopping its own container kills the code doing it.
3. The updater stops the old manager, renames it `<name>-pre-update`, creates a replacement with
the same name, bind mounts, port bindings, network aliases, restart policy, labels and operator
env (`buildReplacementSpec`), but the new image's own `Cmd` and image `ENV`, and polls
`/health` for up to 90 s.
4. Healthy: the old container and image are removed. Not healthy: the replacement is removed and
the old container is renamed back and started (rollback). Exit code 0 = updated, 1 = rolled
back, 2 = fatal.
5. The (new or restored) manager reads the exited updater's logs at the next `GET /api/system`,
shows the outcome in the card, and removes the updater container.
Expect a few seconds of downtime while the containers swap; the panel keeps polling and reconnects
on its own. The sessions live in SQLite under `./data`, so the login survives. Compose still sees
the replacement as its `manager` service (labels are copied); a later `docker compose up -d --build`
works as usual. The checkout is kept in `data/repos/_manager` and logs in `data/logs/_manager/`.
Over `ssh://` the clone uses the mounted `SSH_DIR`, like installations do.
Caveats: installation changes (build, deploy, start, stop...) answer `409` while an update is in
progress, and the hand-over runs inside the build queue, so no installation build overlaps it. The
updater removes the old manager image after a successful swap, so before running `docker compose
up -d --build` on the host again, `git pull` its checkout first or compose will rebuild (and
deploy) an older version than the one installed from the panel.