deploy/tern.yml is the whole stack as one compose project for ygg/actions/deploy (deploy/compose on kara): Postgres, the server at the released version, ygg/static-server serving the matching tern-web release, and an nginx proxy putting webapp and API (incl. /api/ws) on one origin on port 11901, with sign-in rate-limited. Kara's nginx fronts it as tern.mtps.pl. tern-web's release triggers the deploy. Only the first user may now register unless OPEN_REGISTRATION=true, so a public deployment isn't open sign-up; an advisory lock keeps two racing first registrations from both succeeding. `tern-server healthcheck` backs a Dockerfile HEALTHCHECK, so `docker compose up --wait` waits for the server to serve — and fails a deploy whose server can't start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4.3 KiB
Deployment
tern.yml deploys the whole Tern stack to tern.mtps.pl as one compose project (deploy/compose in the ygg management repo). The deploy runs automatically at the end of every tern-web release, through the shared ygg/actions/deploy action.
What runs
| service | image | role |
|---|---|---|
db |
postgres:16-alpine |
Tern's database, in the db-data volume |
server |
git.app.ygg/mtps/tern-server:<version> |
the API and sync engine; mail and attachments live in the blob-data volume |
web |
git.app.ygg/ygg/static-server |
serves the matching tern-web release (tern-web-<version>.tgz) |
proxy |
nginx:1.29-alpine |
puts the webapp and its API on one origin, published on port 11901 |
- Routing: the
proxysends/api(including the/api/wsWebSocket) to the server and everything else to the webapp. The webapp needs both on one origin. - Rate limit: sign-in and sign-up are rate-limited per client.
- Kara's nginx: the
siterole proxies tern.mtps.pl to port 11901, withwebsocket.confincluded for live updates. - Trust store: the server and webapp mount the host's CA bundle, so IMAP/SMTP servers, push servers and git.app.ygg behind the internal CA are trusted.
How a release deploys
- Tags go out server-first (see
../docs/release-process.md). tern-server's release pushestern-server:<version>withygg/actions/push-image. - tern-web's release publishes
tern-web-<version>.tgz. Then itsdeployjob does three things:- checks out this file at the same tag;
- checks that the server image for that version exists;
- runs
deploy/composewithversion=<version>.
- On kara,
docker compose up --waitreplaces the running containers. A deploy only succeeds once every service is healthy: the server is healthy when it answers/healthz, which is after migrations have run. So a server that can't start fails the workflow instead of quietly going down.
The deploy lives in tern-web, not tern-server, because of the single runner. Tags are queued server-first, so by the time tern-web's release runs, both artifacts exist. A deploy job in tern-server would have to wait for tern-web while holding the only runner.
One-time setup
-
Secrets on kara:
/opt/ygg/secrets/env/tern.env. It's copied next to the compose file as.env.POSTGRES_PASSWORD=<openssl rand -hex 24> CREDENTIAL_KEY=<openssl rand -base64 32> # optional: PUSH_URL_REWRITE, PUSH_TLS_INSECURE, PUSH_VAPID_SUBJECT, # SESSION_TTL_HOURS, TRASH_RETENTION_DAYS, OPEN_REGISTRATION, RUST_LOGBack up
CREDENTIAL_KEYsomewhere other than kara. Without it, the stored IMAP/SMTP passwords and the VAPID key can't be decrypted. -
Secrets on the
mtps/tern-webrepository:DEPLOY_SSH_KEYandDEPLOY_KNOWN_HOSTS, the same values as theyggorg's secrets. The tern repositories belong tomtps, so the org-level secrets don't reach them. -
PyYAML on the runner (
dnf install python3-pyyaml). The deploy action converts this YAML file to JSON before sending it. -
Create your user. Only the first user can register unless
OPEN_REGISTRATION=trueis set. Sign up once in the Android app (Create a new user on this server) or withcurl -X POST https://tern.mtps.pl/api/auth/register -H 'Content-Type: application/json' -d '{"username":"…","password":"…"}'. After that, sign-up is closed.
By hand
The same deploy, run directly on kara, with tern.yml copied to the dist directory:
/opt/ygg/play.sh deploy/compose -e @/opt/ygg/dist/compose/tern.yml -e version=0.9.0
To take it down, add -e compose_state=destroy. That stops the project and removes the nginx site. The db-data and blob-data volumes are kept.
Escaping in tern.yml
The file is processed twice, so some characters need escaping:
- Ansible templates
{{ … }}. That's how{{ version }}gets filled in. Wrap anything else that looks like Jinja in{% raw %}. - Docker compose interpolates
$. That's how${POSTGRES_PASSWORD}comes from.env. The proxy's nginx variables are therefore written$$host,$$http_upgrade, and so on.