Deploy Server
Production has run on the droplet since the 2026-10-12 cutover (Cutover ).
Deploy Server
Every deploy, by hand or from CI, is infra/scripts/40-app-deploy.ps1. It checks the commit out into its own release directory, /opt/la-app/releases/<sha>, beside the one la-server is running, installs with the frozen lockfile, builds the server workspace, and runs migrations with the service environment. Only then does it point the /opt/la-app/current symlink (both units’ WorkingDirectory) at the new release and restart la-server behind a standby. If the new release never reports healthy, current goes back and la-server runs the old release again. The previous release stays on disk for -Rollback. The standby is the same build on 127.0.0.1:3001, and Nginx falls back to it while la-server restarts, so the restart fails no request. The deploy fails unless /health returns 200. The standby adds about 3 s to a deploy (its start-up, measured in provision-smoke).
Summary
This page owns:
infra/scripts/40-app-deploy.ps1andinfra/systemd/la-server.serviceinfra/scripts/41-deploy-user.ps1, the restricted CI deploy userinfra/scripts/la-deploy.ps1, the gate that user is pinned to
Automatic deploys (deploy-on-push)
The engine repo’s .github/workflows/deploy-server.yml runs when its CI workflow finishes successfully on a push to main, so only a commit that has passed CI is deployed. It:
- Asks the droplet which commit is live (
status). - Skips the deploy when nothing server-relevant changed between the live commit and the tested one. These paths don’t count:
wiki/,docs/,.github/, and the front-end apps (arena-client,dashboard,legends-board,registry-viewer,wiki-viewer), which is Render’s oldbuildFilterlist plus.github/. - Otherwise sends
deploy <tested commit>. - Checks
https://api.legendary-arena.com/healththrough Cloudflare.
Runs are serialized (one concurrency group, nothing cancelled). It can also be started by hand from the Actions tab (workflow_dispatch, optionally with a commit), for example to retry after a flaky CI run.
What the CI key can do
The workflow logs in as deployer. That user’s only key is pinned with restrict,command="sudo -n /usr/local/sbin/la-deploy", and one sudoers rule runs the gate as root with the request preserved. The gate accepts exactly:
| Request | Result |
|---|---|
status | prints the live commit: the one 40 recorded in /var/lib/la-deploy/live-commit after its health gate passed. A deploy that failed is not reported as live, so the next run retries it. |
deploy <40-hex commit> | deploys it, unless the commit is unknown, not on origin/main, or older than the live commit (exit 3). If it’s already live, the gate exits 0 without redeploying. |
| anything else | refused (exit 2) |
So a leaked key can only redeploy code that is already on main, and a slow CI run can never roll production back to an older commit. flock serializes the gate with hand deploys (exit 4 means it waited 10 minutes for another deploy).
Setup (once)
- Operator, desktop. Create the key pair. The private half goes straight into the engine repo’s secrets and is never displayed:
ssh-keygen -t ed25519 -N '' -C la-deploy-ci -f $HOME\.ssh\la_deploy_ci Get-Content -Raw $HOME\.ssh\la_deploy_ci | gh secret set DEPLOY_SSH_KEY --repo barefootbetters/legendary-arena - Droplet. Install the public key (it isn’t secret):
sudo DEPLOY_PUBLIC_KEY='<contents of la_deploy_ci.pub>' pwsh -NoProfile -File infra/scripts/41-deploy-user.ps1 - Engine repo:
- The secret
DEPLOY_HOSTholds the droplet IP. It’s kept out of the public repo, which is why it’s a secret. - The secret
DEPLOY_KNOWN_HOSTSholds the droplet’sssh-ed25519host-key line, which pins the host against impersonation. - The variable
DEPLOY_ENABLED=trueturns the workflow on. Set it tofalseto pause deploys without editing anything.
- The secret
- Test from the desktop:
ssh -i $HOME\.ssh\la_deploy_ci deployer@<droplet-ip> statusprints the live commit.
Deploy by hand
Run as root on the droplet:
cd /opt/la-lab/infra
sudo flock -w 600 /run/la-deploy.lock pwsh -NoProfile -File scripts/40-app-deploy.ps1 # current main
sudo DEPLOY_REF=<40-hex commit> flock -w 600 /run/la-deploy.lock pwsh -NoProfile -File scripts/40-app-deploy.ps1 # an exact commit
sudo flock -w 600 /run/la-deploy.lock pwsh -NoProfile -File scripts/40-app-deploy.ps1 -Rollback # back to the previous release
A 40-hex DEPLOY_REF deploys that exact commit; a branch name deploys origin/<branch>. The flock keeps a hand deploy from overlapping a CI one.
Rollback. -Rollback points current at /opt/la-app/previous (the release that was live before the last deploy) and restarts behind the standby, with no rebuild, and records that commit as live. Running it again rolls forward. Migrations are not reversed. To go further back, deploy the older commit by hand: the gate refuses to go backwards, but 40 itself doesn’t.
Verify
sudo systemctl status la-server --no-pager
sudo journalctl -u la-server -n 100 --no-pager
curl -sS http://127.0.0.1:3000/health
journalctl -t la-deploy -n 20 --no-pager # the gate's own record of CI deploys
readlink /opt/la-app/current /opt/la-app/previous
cat /var/lib/la-deploy/live-commit; echo
curl -sS http://127.0.0.1:3000/version
Expected: the service is active, /health is 200, there’s no restart loop in the journal, current is releases/<live-commit>, and /version’s gitSha is a prefix of the live commit.
References
- Plan section 5 (script manifest) and section 9 (Cutover)
- Engine repo
.github/workflows/deploy-server.ymland DECISIONS D-24707 / D-24708