Services: run any container image on a machine (design, #17625)
Part of the cloud mission (#17532). A service is one container image, configured, running on a machine
of the owner's, at an https address. This is a design: nothing here is built unless a line says so. It
reuses the game box (docs/features/game-box.md): one agent, one plan, one machine path.
1. What the game box gives, and what it lacks
| General (a service uses it) | Minecraft's (stays with game boxes) |
|---|---|
src/games/agent.sh: the sync, job queue, logs, diag, self-update by sha | rcon, people, chat, metrics, mods, packs, sleep, lend |
| The machine: plan, drivers, hardening, DNS record, retire, ceiling | Ports 25565 and 19132, swap for the JVMs (src/games/boot.ts) |
The volume's mount, and the file read at a branch HEAD (compose.ts) | Snapshots: the agent knows world folders, not any volume |
The deploy step is not reusable as it is. Today the agent has no health gate and no rollback:
applyrunsdocker compose up -dwithout--wait: a container's health is reported and decides nothing.- It writes the new
compose.ymlover the old one first. A failedupis only remembered, so it is not tried again for that commit (job_tick); nothing puts the old file back. - Moving the branch back to the last good commit sends nothing: the sync compares commit ids
(
src/http/games_routes.ts), and the box still reports that one as current. A revert commit works. - A box has one compose project (
game), so nothing starts beside the old container.
2. A service is a want of its own
service is a new member of Want (src/cloud/plan.ts) with its own row, placed on a machine by name, and
not a kind on the box row. A box row is one machine with one compose file, so it could not hold two
services, and a service changes, rolls back and ends far more often than its machine does.
A machine must still know how it boots, also after a replace: MachineWant.game becomes
boots: "forge" | "game" | "services", kept on its row, and a services machine names its one client.
A game box keeps its row and token, compose project, ports, verbs and deploy step. The agent takes the service path only when the sync answer carries services. Forge apps stay in their cells on the forge's host.
3. The image, pinned by digest
- The first slice takes an image from a public registry. The forge resolves a typed tag once, and the
service's file holds
name@sha256:…. A new digest is a new deploy, shown as "wasabc123, nowdef456". An image without the machine's platform is refused. - Registry code is new, and each registry host goes in
forge.jsonegress. - Building a repository's Dockerfile is a later slice, and not on the client's machine. A build runs arbitrary code there, takes memory from the live service, and leaves no image to pull after a replace. A separate builder pushes to a registry, and the service takes the digest.
4. Settings and secrets
The service's file is in its repository, so a change is a pull the crew can propose: image, port, health
path, host, plain variables, memory and CPU limits. Secrets are sealed at the repository's scope
(src/core/secret_store.ts) and only named in the file; a missing one refuses the deploy. The agent writes
them with mode 600, as files under /run/secrets where the image reads files, else as variables, and
redacts their values from the log lines it posts.
5. https and domains
Caddy runs on the machine, as on a forge's (proxyConfig in src/cloud/machine.ts), its certificates on the
volume. A container publishes on 127.0.0.1 only, because Docker's published ports pass by ufw. Only 80 and
443 are open, so the forge's cloud firewall fits. DNS is the game box's A record; with no Cloudflare token the
plan says to set it by hand and the https check waits. No host given: the plan refuses.
6. Deploy, health, rollback
- Every service has a health path, an expected status and a deadline (120 s).
- No data on disk: the new container starts beside the old one, in its own compose project. Healthy:
Caddy switches and the old one stops. Not healthy in time: it is removed, the old one never stopped, and
/services/<name>says so first. - Data on disk (later): two writers are not safe, so stop, start, check, and put the old one back on failure. That has downtime, and the plan says so.
- After the switch the forge asks the https address from outside; a failure switches back.
- Rollback is one action: a commit with the previous file's content, through the same gate. It does not undo a database migration, and the button says so.
7. Backup, and a restore that was tried
No client data before this is green: until then a service with data on disk is refused. The backup is a
declared dump command, or a copy while the service is stopped, sealed and kept off the machine. The drill puts
the newest one into a scratch directory, starts the service's own image on it with no network, and passes its
health check; a tar that only lists is not a restore. The page says "Last restore tried: <when>, ok" or
"never tried", kept like restore-drill (docs/RECOVERY.md).
8. Isolation
One machine per client. One client's services share it: separate compose projects and networks, memory
and CPU limits, dropped capabilities, no privileged, no host network, no Docker socket. That stops accidents
and noisy neighbours. Containers share the host's kernel, so it does not make a hostile tenant safe, and two
clients on one machine is refused.
Containers on a box have no reach to the cloud's metadata address (#17635): a services machine keeps that rule.
9. When something dies, and cost
- The forge: services keep running; there are no deploys. A container: Docker restarts one that exits, and the agent restarts an unhealthy one, with a limit.
- The machine: the site is down until
replace(src/cloud/machine.ts) mounts the volume on a new one. Update refuses when nothing changed and the row is notfailed(src/actions/pinned.ts), so "Replace this machine" is new, and so is an alarm for a silent box. - The volume: restore the last backup; writes since it are lost. This is recovery, not high availability.
- Cost: the plan shows the machine's catalog price against the ceiling. No saving is claimed until a named service is measured against its bill.
The first slice, in order
One public image, one host, no data on disk. Each is a pull of its own, with its test.
bootsreplacesgame; a services boot has Caddy and 80/443. Test: a game box's boot config is unchanged. Built:bootsand the client are on the machine's row, andsrc/cloud/service_boot.tsis the boot. No door makes such a machine yet, it runs no agent, and no real machine has booted it.- The service row, file and want. Test: the steps, and a refusal each for no host, no health path, data on disk and a second client.
- Tag to digest. Test: a recorded registry answer, a missing platform, and a moved tag that changes nothing.
- The gated deploy in the agent. Test: an unhealthy image leaves the old one serving, and a game box does what it did. Every box updates itself to a new agent, so it runs in Ubuntu first.
- Secrets. Test: mode 600, a missing one refuses, and no value is in a posted log line.
- Rollback and the outside https check. Test: one action serves the old digest; a failed check switches back.
- "Replace this machine" and the silent-box alarm. Test: the same volume and digest; the alarm rises and clears.
/services, the terminal and the MCP tool over one action, and a how-to. Test: the three say the same.- One real service, its results in the issue: a bad image, a rollback, a reboot and a replace.
Next, in order: backup and its drill, data on disk, private registries, builds.