CI / test (push) Successful in 4m39s
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>
146 lines
5.0 KiB
YAML
146 lines
5.0 KiB
YAML
# Tern's production deployment: the whole stack as one compose project,
|
|
# deployed by tern-web's release workflow through ygg/actions/deploy
|
|
# (`deploy/compose` on kara). See deploy/README.md.
|
|
#
|
|
# `version` arrives as an extra var (the release tag without its v) and is
|
|
# templated in by Ansible. Secrets come from /opt/ygg/secrets/env/tern.env
|
|
# on kara, copied next to compose.yml as .env — never put them in here:
|
|
# this file is sent on the command line.
|
|
#
|
|
# Escaping: Ansible templates {{ }}, and compose interpolates $, so a
|
|
# literal $ (nginx variables) is written $$.
|
|
|
|
compose_project: tern
|
|
|
|
domain: tern.mtps.pl
|
|
cert: mtps.pl
|
|
site_port: 11901
|
|
# Kara's nginx proxies the domain here; the include passes the WebSocket
|
|
# upgrade through for live updates (/api/ws).
|
|
site_includes: websocket.conf
|
|
|
|
compose:
|
|
services:
|
|
db:
|
|
image: postgres:16-alpine
|
|
restart: unless-stopped
|
|
environment:
|
|
POSTGRES_USER: tern
|
|
POSTGRES_DB: tern
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in tern.env}
|
|
volumes:
|
|
- db-data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U tern -d tern"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 20
|
|
|
|
server:
|
|
image: "git.app.ygg/mtps/tern-server:{{ version }}"
|
|
restart: unless-stopped
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
environment:
|
|
DATABASE_URL: postgres://tern:${POSTGRES_PASSWORD}@db:5432/tern
|
|
BIND_ADDR: 0.0.0.0:8080
|
|
CREDENTIAL_KEY: ${CREDENTIAL_KEY:?set CREDENTIAL_KEY in tern.env}
|
|
BLOB_STORAGE_DIR: /data/blobs
|
|
SESSION_TTL_HOURS: ${SESSION_TTL_HOURS:-720}
|
|
TRASH_RETENTION_DAYS: ${TRASH_RETENTION_DAYS:-30}
|
|
OPEN_REGISTRATION: ${OPEN_REGISTRATION:-false}
|
|
PUSH_URL_REWRITE: ${PUSH_URL_REWRITE:-}
|
|
PUSH_TLS_INSECURE: ${PUSH_TLS_INSECURE:-false}
|
|
PUSH_VAPID_SUBJECT: ${PUSH_VAPID_SUBJECT:-mailto:postmaster@mtps.pl}
|
|
RUST_LOG: ${RUST_LOG:-tern_server=info}
|
|
volumes:
|
|
- blob-data:/data/blobs
|
|
# The host's trust store, so IMAP/SMTP and push servers behind the
|
|
# internal CA are trusted like public ones (same as the static role).
|
|
- /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem:/etc/ssl/certs/ca-certificates.crt:ro
|
|
|
|
# The webapp: static-server downloads this version's tern-web release.
|
|
web:
|
|
image: git.app.ygg/ygg/static-server:latest
|
|
restart: unless-stopped
|
|
environment:
|
|
GITEA_REPOSITORY_URL: https://git.app.ygg/mtps/tern-web
|
|
GITEA_RELEASE: "v{{ version }}"
|
|
GITEA_ASSET_NAME: "tern-web-{{ version }}.tgz"
|
|
SSL_CERT_FILE: /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
|
|
volumes:
|
|
- /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem:/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem:ro
|
|
|
|
# One origin for the webapp and its API, as the webapp requires: /api
|
|
# (including the /api/ws socket) goes to the server, the rest to web.
|
|
proxy:
|
|
image: nginx:1.29-alpine
|
|
restart: unless-stopped
|
|
depends_on:
|
|
- server
|
|
- web
|
|
ports:
|
|
- "11901:80"
|
|
configs:
|
|
- source: proxy
|
|
target: /etc/nginx/conf.d/default.conf
|
|
|
|
volumes:
|
|
db-data: {}
|
|
blob-data: {}
|
|
|
|
configs:
|
|
proxy:
|
|
content: |
|
|
# Kara's nginx sits in front; trust its X-Forwarded-For so rate
|
|
# limits apply per client rather than to kara as a whole.
|
|
set_real_ip_from 10.0.0.0/8;
|
|
set_real_ip_from 172.16.0.0/12;
|
|
set_real_ip_from 192.168.0.0/16;
|
|
set_real_ip_from 200::/7;
|
|
real_ip_header X-Forwarded-For;
|
|
real_ip_recursive on;
|
|
|
|
# Login and sign-up: slow enough to make guessing passwords
|
|
# pointless, loose enough for a person retyping one.
|
|
limit_req_zone $$binary_remote_addr zone=tern_auth:10m rate=10r/m;
|
|
|
|
map $$http_upgrade $$connection_upgrade {
|
|
default upgrade;
|
|
'' close;
|
|
}
|
|
|
|
server {
|
|
listen 80;
|
|
|
|
location /api/auth/ {
|
|
limit_req zone=tern_auth burst=10 nodelay;
|
|
limit_req_status 429;
|
|
proxy_pass http://server:8080;
|
|
proxy_set_header Host $$host;
|
|
proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for;
|
|
}
|
|
|
|
location /api/ {
|
|
proxy_pass http://server:8080;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $$host;
|
|
proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for;
|
|
proxy_set_header Upgrade $$http_upgrade;
|
|
proxy_set_header Connection $$connection_upgrade;
|
|
# The server pings sockets every 25 s; this only ends dead ones.
|
|
proxy_read_timeout 1h;
|
|
}
|
|
|
|
location = /healthz {
|
|
proxy_pass http://server:8080;
|
|
access_log off;
|
|
}
|
|
|
|
location / {
|
|
proxy_pass http://web:8080;
|
|
proxy_set_header Host $$host;
|
|
}
|
|
}
|