Legendary Arena Lab

Ubuntu Droplet Setup

wiki

Ubuntu Droplet Setup

Migration in progress. api.legendary-arena.com and its PostgreSQL are moving off Render onto a self-hosted DigitalOcean Ubuntu droplet fronted by Cloudflare, per docs/PLAN.md . Until decommission, Render stays warm as the rollback target.

Summary

This is the umbrella guide for standing up the single DigitalOcean Ubuntu droplet that replaces Render’s web service + managed PostgreSQL: it lays out the ordered bring-up — provision, harden, install runtime and data, front with Nginx/TLS, deploy — and links each step to the wiki page and infra/ artifact that owns it. It duplicates none of those pages’ mechanics; it is the linear path through them. For where the program stands against this sequence, see the Migration Checklist .

Mechanics

The droplet is one box doing everything: Ubuntu 24.04 LTS, 4 vCPU / 8 GB to start (region sfo3), running apps/server under systemd behind Nginx with PostgreSQL 18 co-located on localhost (docs/PLAN.md ; Render-to-DigitalOcean Migration ). The rebuild invariant is “run the numbered infra/scripts/*.ps1 in order” (docs/PLAN.md ) — this guide walks that order.

The bring-up runs in the numbered script sequence, grouped by PLAN §6 phase:

Getting the scripts onto the droplet. The lab repo is private, so the droplet does not clone it. Copy the infra/ folder from your machine; every page runs the scripts as infra/scripts/… from /opt/la-lab, and the backup/monitor timers point at that path:

# From your machine, in the lab repo checkout (PowerShell or bash; scp ships with Windows OpenSSH)
scp -r infra operator@<droplet-ip>:/tmp/la-lab-infra
ssh operator@<droplet-ip> "sudo install -d /opt/la-lab && sudo rm -rf /opt/la-lab/infra && sudo cp -r /tmp/la-lab-infra /opt/la-lab/infra && rm -rf /tmp/la-lab-infra"

Then run each step as cd /opt/la-lab && sudo pwsh -File infra/scripts/<script>.ps1. Re-copy after pulling script changes. PowerShell itself comes from cloud-init (snap install powershell).

Phase 1 — provision + harden

  1. Provision — Provision Droplet , owns infra/cloud-init.yaml . First-boot user-data: the non-root operator user + authorized key, base apt packages, timezone, and the /etc/la anchor for the deploy .env. One-shot — fill the key placeholder before boot.
  2. SSH hardening — SSH Hardening , owns infra/scripts/05-user-and-ssh.ps1 . Key-only login; disables root login and password auth via a managed sshd drop-in, with a two-session anti-lockout sequence.
  3. Firewall — UFW Firewall , owns infra/scripts/06-ufw.ps1 . Default-deny inbound; allow SSH + 80/443 (443 later narrowed to Cloudflare IPs).
  4. Fail2ban + auto-patching — Fail2ban and Unattended Upgrades , owns infra/scripts/07-fail2ban-upgrades.ps1 . SSH brute-force bans + automatic security patching — the patching you now own instead of Render.

Phase 2 — runtime, web, data

  1. Node runtime — Node Runtime , owns infra/scripts/10-node.ps1 . fnm installs Node 24.18.0 into a shared /opt/fnm, /opt/node points at it, and pnpm 10.32.1 is installed alongside, so the operator-owned service can run it.
  2. PostgreSQL — PostgreSQL Setup , owns infra/scripts/30-postgres.ps1 . Self-hosted PostgreSQL 18 on localhost, scram-sha-256, memory tuning sized from the RAM; creates the la role and database and proves the login.
  3. Nginx reverse proxy — Nginx Reverse Proxy , owns infra/nginx/api.conf + infra/scripts/20-nginx.ps1 . Proxies api. to 127.0.0.1:3000 with the WebSocket-upgrade headers Socket.IO needs; the plain-HTTP stage before TLS.
  4. Cloudflare TLS — Cloudflare TLS , owns infra/scripts/21-cloudflare-tls.ps1 . Origin Certificate + Full (strict), 80→443 redirect, and UFW 443 restricted to live Cloudflare IP ranges.

Phase 3 — first deploy (dress rehearsal)

  1. Deploy the server — Deploy Server , owns infra/scripts/40-app-deploy.ps1 + infra/systemd/la-server.service + infra/.env.example . Clone, server-only build from /opt/node, migrations, unit install, restart, and a /health gate. Run it against a COPY of the prod DB (restore a Render dump first with Backup and Restore ), never the live one.

Phase 4 — backups + monitoring (the cutover gate)

  1. Backups — Backup and Restore , owns 50-backup.ps1 + 51-restore.ps1 . Install the daily timer, take a backup, and pass the restore drill.
  2. Monitoring — Monitoring , owns 60-monitor.ps1 . The 5-minute on-box check + dead-man’s-switch ping, plus the external uptime check.
  3. Maintenance (as needed) — PostgreSQL Maintenance , owns 52-vacuum-reclaim.ps1 .

The deploy pipeline (Phase 4), cutover (Phase 5), and Render decommission (Phase 7) continue in the Migration Checklist . Every script above is exercised end to end on a fresh Ubuntu 24.04 runner by the provision smoke workflow .

Interactions

Edge Cases

  • Order is load-bearing for a few steps, not all. Provision must precede everything; SSH hardening must land before you rely on key-only access; Nginx (plain HTTP) comes before Cloudflare TLS so the origin is reachable for cert validation. Node/Postgres can go in either order relative to each other but both precede the app deploy.
  • The anti-lockout window. SSH hardening and the UFW enable both risk locking you out; keep a second authenticated session open until you’ve verified access on a fresh shell (SSH Hardening § Edge Cases ).
  • cloud-init is one-shot. It fires once on first boot and does not re-run; an unreplaced key placeholder means no login, and drift is fixed with the numbered scripts, not by re-running cloud-init (Provision Droplet § Edge Cases ).
  • Snapshot after hardening. PLAN §5 calls for a post-bootstrap-hardened snapshot once Phase 1 + base services are in — take it before layering the app so a rebuild starts from a hardened baseline.
  • This is provisioning, not cutover. A fully built droplet is still not a Render replacement until the Phase 4 restore drill passes and DNS is flipped (Migration Checklist ).

Verify

After the sequence, the box should answer locally and pass its own health check:

# runtime + DB present
node --version            # expected: v24.18.0
systemctl status postgresql   # expected: active (exited)/running

# app service up and healthy
systemctl status la-server    # expected: active (running)
curl -s localhost:3000/health # expected: healthy response from apps/server

# firewall + cloud-init clean
sudo ufw status               # expected: Status: active, 22/80/443 allowed
cloud-init status --long      # expected: status: done

Per-step verification lives on each linked page’s own Verify section.

References