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 sharcon, people, chat, metrics, mods, packs, sleep, lend
The machine: plan, drivers, hardening, DNS record, retire, ceilingPorts 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:

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

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

  1. Every service has a health path, an expected status and a deadline (120 s).
  2. 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.
  3. 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.
  4. After the switch the forge asks the https address from outside; a failure switches back.
  5. 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 first slice, in order

One public image, one host, no data on disk. Each is a pull of its own, with its test.

  1. boots replaces game; a services boot has Caddy and 80/443. Test: a game box's boot config is unchanged. Built: boots and the client are on the machine's row, and src/cloud/service_boot.ts is the boot. No door makes such a machine yet, it runs no agent, and no real machine has booted it.
  2. 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.
  3. Tag to digest. Test: a recorded registry answer, a missing platform, and a moved tag that changes nothing.
  4. 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.
  5. Secrets. Test: mode 600, a missing one refuses, and no value is in a posted log line.
  6. Rollback and the outside https check. Test: one action serves the old digest; a failed check switches back.
  7. "Replace this machine" and the silent-box alarm. Test: the same volume and digest; the alarm rises and clears.
  8. /services, the terminal and the MCP tool over one action, and a how-to. Test: the three say the same.
  9. 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.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs