The integrated stack is gone: deploy/compose.yml is just the server and its Postgres, published on 11901 behind the existing nginx as tern-api.mtps.pl, and this repo's release deploys it after pushing the image. The webapp deploys separately from tern-web. CREDENTIAL_KEY may now be 64 hex digits as well as base64, and a wrong length says how to generate a right one. The database password reaches the server as PGPASSWORD rather than inside DATABASE_URL, so it needs no URL-escaping. CORS now names Authorization and Content-Type instead of `*`: browsers don't let the wildcard cover Authorization, so every signed-in request from the webapp's own origin would have been refused. A route test checks the preflight. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3.5 KiB
Deployment
compose.yml deploys tern-server to tern-api.mtps.pl. It's one compose project with two services:
db:postgres:16-alpine, with its data in thedb-datavolume.server:git.app.ygg/mtps/tern-server:<version>, with mail and attachments in theblob-datavolume.
The server publishes port 11901 on the app host. The existing nginx proxies the domain to it, using the management repo's site role, with websocket.conf included so live updates (/api/ws) pass through. The server mounts the host's CA bundle, so mail and push servers behind the internal CA are trusted.
The webapp deploys separately, from tern-web's own release, to tern.mtps.pl. It calls this API cross-origin. That works because clients authenticate with a bearer token rather than a cookie, and the server allows cross-origin requests.
How a release deploys
tern-server's release workflow has two jobs:
imagebuilds and pushestern-server:<version>and:latestwithygg/actions/push-image.deploysends this file inline throughygg/actions/deploy(type: compose), withversion=<version>.
On the app host, docker compose up --wait replaces the containers. The deploy only succeeds once every service is healthy. The image's HEALTHCHECK runs tern-server healthcheck, which passes once the server answers /healthz, after migrations have run. So a server that can't start fails the workflow instead of leaving the API down.
One-time setup
-
Secrets on kara:
/opt/ygg/secrets/env/tern-server.env. It's copied next to the compose file as.env.POSTGRES_PASSWORD=<openssl rand -hex 24> CREDENTIAL_KEY=<openssl rand -hex 32> # optional: PUSH_URL_REWRITE, PUSH_TLS_INSECURE, PUSH_VAPID_SUBJECT, # SESSION_TTL_HOURS, TRASH_RETENTION_DAYS, OPEN_REGISTRATION, RUST_LOGCREDENTIAL_KEYis 32 bytes, as 64 hex digits or base64.- The database password can contain any characters, because it reaches the server as
PGPASSWORD, not inside a URL. - Back 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-serverrepository:DEPLOY_SSH_KEYandDEPLOY_KNOWN_HOSTS. Theyggorg's secrets don't reachmtpsrepositories. -
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 with:curl -X POST https://tern-api.mtps.pl/api/auth/register \ -H 'Content-Type: application/json' -d '{"username":"…","password":"…"}'
By hand
The same deploy, run directly on kara with this file copied to the dist directory:
/opt/ygg/play.sh deploy/compose -e @/opt/ygg/dist/compose/tern-server.yml -e version=0.9.0
To take it down, add -e compose_state=destroy. That stops the project and removes the nginx site, but keeps the db-data and blob-data volumes.
Escaping in compose.yml
The file is processed twice, so some characters need care:
- 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. Write a literal$as$$.