Paper Sats: design and print paper notes that carry sats. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
121 lines
3.8 KiB
YAML
121 lines
3.8 KiB
YAML
# Production stack behind nginx. Copy .env.example to .env and fill it in, then: docker compose -f infra/docker-compose.prod.yml up -d --build
|
|
# Migrations run on their own before web and worker start. See docs/runbook.md.
|
|
# NOT YET RUN: Docker was unavailable where this was written. It has only had static checks.
|
|
x-logging: &logging
|
|
driver: json-file
|
|
options: { max-size: '20m', max-file: '5' }
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:16
|
|
restart: always
|
|
logging: *logging
|
|
environment:
|
|
POSTGRES_DB: paper
|
|
POSTGRES_USER: paper
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ['CMD-SHELL', 'pg_isready -U paper -d paper']
|
|
interval: 10s
|
|
retries: 10
|
|
|
|
migrate:
|
|
build: { context: .., dockerfile: infra/Dockerfile.web }
|
|
restart: 'no'
|
|
logging: *logging
|
|
env_file: ../.env
|
|
environment:
|
|
DATABASE_URL: postgres://paper:${POSTGRES_PASSWORD}@postgres:5432/paper
|
|
command: ['node', '--import', 'tsx', 'src/db/migrate.ts']
|
|
depends_on:
|
|
postgres: { condition: service_healthy }
|
|
|
|
web:
|
|
build: { context: .., dockerfile: infra/Dockerfile.web }
|
|
restart: always
|
|
init: true
|
|
logging: *logging
|
|
env_file: ../.env
|
|
environment:
|
|
DATABASE_URL: postgres://paper:${POSTGRES_PASSWORD}@postgres:5432/paper
|
|
# /api/live, not /api/health: a dead worker must not restart the site.
|
|
healthcheck:
|
|
test:
|
|
- CMD
|
|
- node
|
|
- -e
|
|
- "fetch('http://localhost:3000/api/live').then(r=>process.exit(r.ok?0:1),()=>process.exit(1))"
|
|
interval: 15s
|
|
timeout: 5s
|
|
retries: 4
|
|
start_period: 30s
|
|
depends_on:
|
|
postgres: { condition: service_healthy }
|
|
migrate: { condition: service_completed_successfully }
|
|
|
|
worker:
|
|
build: { context: .., dockerfile: infra/Dockerfile.worker }
|
|
restart: always
|
|
init: true
|
|
logging: *logging
|
|
env_file: ../.env
|
|
environment:
|
|
DATABASE_URL: postgres://paper:${POSTGRES_PASSWORD}@postgres:5432/paper
|
|
WORKER_ALIVE_FILE: /tmp/worker-alive
|
|
# Longer than the worker's own drain limit (100 s), so a melt in progress can finish.
|
|
stop_grace_period: 120s
|
|
healthcheck:
|
|
test:
|
|
- CMD
|
|
- node
|
|
- -e
|
|
- "process.exit(Date.now()-require('fs').statSync('/tmp/worker-alive').mtimeMs<120000?0:1)"
|
|
interval: 30s
|
|
timeout: 5s
|
|
retries: 3
|
|
start_period: 60s
|
|
depends_on:
|
|
postgres: { condition: service_healthy }
|
|
migrate: { condition: service_completed_successfully }
|
|
|
|
# A dump a day, kept for 14 days. Copy them off this machine: see docs/runbook.md.
|
|
backup:
|
|
image: postgres:16
|
|
restart: always
|
|
logging: *logging
|
|
environment:
|
|
PGPASSWORD: ${POSTGRES_PASSWORD}
|
|
volumes:
|
|
- ${BACKUP_DIR:?set BACKUP_DIR to the folder for database dumps}:/backups
|
|
entrypoint:
|
|
- sh
|
|
- -c
|
|
- |
|
|
while true; do
|
|
f=/backups/paper-$$(date +%F).dump
|
|
pg_dump -h postgres -U paper -Fc paper > "$$f.tmp" && mv "$$f.tmp" "$$f" && echo "backup ok $$f" || echo "backup FAILED"
|
|
find /backups -name 'paper-*.dump' -mtime +14 -delete
|
|
sleep 86400
|
|
done
|
|
depends_on:
|
|
postgres: { condition: service_healthy }
|
|
|
|
nginx:
|
|
image: nginx:stable
|
|
restart: always
|
|
logging: *logging
|
|
ports: ['80:80', '443:443']
|
|
environment:
|
|
DOMAIN: ${DOMAIN:?set DOMAIN to the site address without https}
|
|
volumes:
|
|
# The image fills in DOMAIN and writes the result to conf.d when it starts.
|
|
- ./nginx.conf.template:/etc/nginx/templates/default.conf.template:ro
|
|
- ${TLS_DIR:?set TLS_DIR to the folder with fullchain.pem and privkey.pem}:/etc/nginx/tls:ro
|
|
depends_on:
|
|
web: { condition: service_healthy }
|
|
|
|
volumes:
|
|
pgdata:
|