0028. Production on a single VPS first, provider-neutral; AWS later
- Status: Accepted 2026-11-30 (Phase 7a; owner decisions 2026-11-29 and 2026-11-30)
- Date: 2026-11-29
- Phase: 7a
- Amends: ADR 0011 (AWS ECS/RDS/CloudFront moves to a later phase)
Context
Section titled “Context”ADR 0011 planned production on AWS (ECS Fargate, RDS, S3, CloudFront) through CDK. The owner will start smaller: one VPS at a provider other than AWS. Where data lives (the platform has players from 13 up) and which CDN serves game files are left open, to revisit later.
Owner decisions (2026-11-29):
- 7a writes and checks the setup but deploys nothing; the owner deploys when ready. Nothing in 7a costs money.
- A VPS first; AWS (CDK) moves to a later phase. The same Docker images keep that move open.
- DNS and TLS are provider-neutral, and the domain is a setting until the name is chosen.
- The region and data residency are revisited later.
- The game-file CDN stays open: the code keeps the vendor a setting.
Decision
Section titled “Decision”- One VPS running the production Compose stack (
infra/vps/). It uses the same image and services as local Compose, with these changes:- Caddy is the only public service (ports 80 and 443):
- TLS from Let’s Encrypt. Wildcard certificates use the DNS challenge, through a DNS-provider plugin chosen by setting (Cloudflare, Route 53, deSEC, Hetzner and others).
- Hosts:
WEB_DOMAIN(web and API);*.PLAY_DOMAIN(games, on a separate registrable domain as ADR 0012 asks);rooms.WEB_DOMAIN(multiplayer WebSockets). - Security headers, request size limits, and HTTP→HTTPS redirects.
- Internal ports only. No service publishes a port to the host except Caddy.
- Production safeguards:
- No local defaults: the stack refuses to start unless every secret is set (
pnpm platform:check-env). - Restart policies, memory limits, health checks, and log rotation.
- No local defaults: the stack refuses to start unless every secret is set (
- Mail goes to any SMTP provider (
SMTP_URL). Mailpit is not in production. - Storage goes to any S3-compatible store (
S3_*): SeaweedFS on the VPS by default, or an outside store (Cloudflare R2, Backblaze B2, Wasabi, AWS S3) by setting. - Game files: the play origin can sit behind any CDN that forwards the host. Moving game files to a CDN in front of object storage is a later setting, not a code change.
- Caddy is the only public service (ports 80 and 443):
- The builder keeps its sandbox (no network, read-only, no capabilities, limits). On the VPS it can also run
under gVisor (
runsc) when installed (BUILDER_RUNTIME). - Backups: nightly, encrypted and kept off the VPS, using restic to any S3-compatible bucket or SFTP target.
- What is backed up: Postgres (
pg_dump) and object storage. - Retention: 7 daily, 4 weekly and 6 monthly backups.
- A restore script, and a monthly restore test described in the runbook.
- What is backed up: Postgres (
- Monitoring and alerts, kept small for one machine:
- Health checks on every service.
- An
opsservice checks every few minutes: health endpoints, disk space, the age of the last backup, certificate expiry, and the build queue length. - It emails the owner (
ALERT_EMAIL) over the same SMTP, at most once an hour per problem. - An outside uptime check (any provider) is recommended in the runbook.
- Deploys: a script copies the repository to the VPS, builds the image there, runs migrations, then restarts the services (ssh + docker compose, no CI vendor needed). Rollback re-tags the previous image.
- Load test: k6 scripts for the 10k-player profile (
docs/hosting.md): catalog, game page, play-origin files, API saves and scores, and rooms. They run against local Compose, and against the VPS only with the owner’s OK. - Security review of the sandbox and the play origin, written up in
docs/security-review.md, with fixes made in this phase. An outside penetration test is recommended before a public launch. - Runbooks (
docs/runbooks/): first setup, deploy and rollback, backup and restore, rotating secrets, incidents, and taking content down.
Amendment 2026-11-30: the owner’s server
Section titled “Amendment 2026-11-30: the owner’s server”The owner’s VPS is at DreamHost (4 vCPU, 16 GB). It also hosts other small projects behind a Caddy the owner already runs, uses DreamHost DNS, and has no guaranteed static IP. Owner decisions:
- Shared proxy mode. With
PROXY_MODE=shared, the stack runs no Caddy of its own. Web, play and rooms listen on127.0.0.1ports, andinfra/vps/caddy/platform.caddyis the site block to add to the owner’s Caddy. Standalone mode (our own Caddy) stays for a dedicated server. - Wildcard certificates through DreamHost DNS: a DNS module for Caddy, in our Caddy image and in the owner’s
Caddy (rebuilt with xcaddy). Originally the
caddy-dns/dreamhostplugin; DreamHost retired the legacy API it uses in November 2026, so since 2026-12-01 it is our own module for DreamHost’s DNS API v1 (infra/vps/caddy/dreamhost/, same module ID and Caddyfile syntax). The updater moved to API v1 too. - A dynamic DNS updater (
apps/ddns) keeps A records at DreamHost pointing at the server’s current public address. It runs as a service in the stack, and can also update the other projects’ records. - Docker on the VPS is still to be confirmed; managed plans may not allow it.
Alternatives considered
Section titled “Alternatives considered”- AWS through CDK now (ADR 0011): best scaling, but a higher fixed cost (~$60–90/month) and more to run solo before there are players.
- Cloudflare Tunnel for the dynamic IP: no public address needed, but DNS and TLS move to Cloudflare, and the existing Caddy setup would change (owner chose the DreamHost updater, 2026-11-30).
- On-demand certificates per game instead of a wildcard: no DNS plugin, but Let’s Encrypt allows about 50 new certificates a week per domain.
- A managed platform (Fly.io, Render, Railway): less to run, but WebSockets, the offline builder and sandbox options depend on each vendor.
- Kubernetes (k3s) on the VPS: more moving parts than one machine needs.
Consequences
Section titled “Consequences”- One machine is a single point of failure. Backups and a tested restore are the mitigation. Scaling up means a bigger VPS, then moving to several machines or AWS with the same images.
- Rooms and builds share the machine with the web server: CPU limits per service keep a build from starving the rest.
- The design does not depend on one VPS provider: any Linux host with Docker works.