114 lines
3.5 KiB
YAML
114 lines
3.5 KiB
YAML
# Single-VPS production deployment. No Kubernetes, no microservices, no message broker —
|
|
# none of it is needed for one company and a handful of MRs, and every piece of
|
|
# infrastructure added here is a piece somebody has to operate at 2am.
|
|
#
|
|
# Only Caddy publishes ports. The database and the API are reachable solely on the
|
|
# internal compose network. For local development add the dev overlay:
|
|
# docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d db
|
|
|
|
x-logging: &default-logging
|
|
driver: json-file
|
|
options:
|
|
max-size: "10m"
|
|
max-file: "5"
|
|
|
|
services:
|
|
db:
|
|
image: postgres:16-alpine
|
|
environment:
|
|
POSTGRES_USER: ${POSTGRES_USER:-pharma}
|
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
|
|
POSTGRES_DB: ${POSTGRES_DB:-pharma}
|
|
volumes:
|
|
- pgdata:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 10
|
|
restart: unless-stopped
|
|
logging: *default-logging
|
|
|
|
# Daily pg_dump of the whole database into ./backups on the host, the last 14 days kept.
|
|
# See scripts/backup.sh for how to restore one.
|
|
backup:
|
|
image: postgres:16-alpine
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
environment:
|
|
PGHOST: db
|
|
PGUSER: ${POSTGRES_USER:-pharma}
|
|
PGPASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
|
|
PGDATABASE: ${POSTGRES_DB:-pharma}
|
|
BACKUP_KEEP_DAYS: ${BACKUP_KEEP_DAYS:-14}
|
|
volumes:
|
|
- ./backups:/backups
|
|
- ./scripts/backup.sh:/backup.sh:ro
|
|
entrypoint: ["/bin/sh", "/backup.sh"]
|
|
restart: unless-stopped
|
|
logging: *default-logging
|
|
|
|
api:
|
|
build: .
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
environment:
|
|
DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:-pharma}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB:-pharma}
|
|
SECRET_KEY: ${SECRET_KEY:?set SECRET_KEY in .env (64+ random characters)}
|
|
ENVIRONMENT: ${ENVIRONMENT:-production}
|
|
CORS_ORIGINS: ${CORS_ORIGINS:-["https://celtic.upskalor.com","https://www.celtic.upskalor.com","http://localhost:5173","http://localhost:3000"]}
|
|
PDF_STORAGE_PATH: /srv/storage/pdf
|
|
BACKDATING_WINDOW_DAYS: ${BACKDATING_WINDOW_DAYS:-7}
|
|
SUBMISSION_DEADLINE_DAYS: ${SUBMISSION_DEADLINE_DAYS:-1}
|
|
PLAN_AHEAD_DAYS: ${PLAN_AHEAD_DAYS:-2}
|
|
WEB_CONCURRENCY: ${WEB_CONCURRENCY:-2}
|
|
volumes:
|
|
- pdfstore:/srv/storage/pdf
|
|
# Immutable container: the only writable places are the PDF volume and tmpfs.
|
|
read_only: true
|
|
tmpfs:
|
|
- /tmp
|
|
- /home/appuser/.cache
|
|
security_opt:
|
|
- no-new-privileges:true
|
|
cap_drop:
|
|
- ALL
|
|
restart: unless-stopped
|
|
logging: *default-logging
|
|
|
|
# Responsive React web application. It is static after its production build;
|
|
# Caddy below provides the public TLS endpoint.
|
|
web:
|
|
build: ./web
|
|
restart: unless-stopped
|
|
logging: *default-logging
|
|
|
|
# Automatic HTTPS via Let's Encrypt — two lines of config, auto-renewal,
|
|
# no certbot cron job to forget about.
|
|
caddy:
|
|
image: caddy:2-alpine
|
|
depends_on:
|
|
api:
|
|
condition: service_healthy
|
|
web:
|
|
condition: service_started
|
|
ports:
|
|
- "${HTTP_PORT:-80}:80"
|
|
- "${HTTPS_PORT:-443}:443"
|
|
environment:
|
|
DOMAIN: ${DOMAIN:-localhost}
|
|
volumes:
|
|
- ./Caddyfile:/etc/caddy/Caddyfile:ro
|
|
- caddydata:/data
|
|
- caddyconfig:/config
|
|
restart: unless-stopped
|
|
logging: *default-logging
|
|
|
|
volumes:
|
|
pgdata:
|
|
pdfstore:
|
|
caddydata:
|
|
caddyconfig:
|