services:
  app:
    build: .
    environment:
      NODE_ENV: production
      DATABASE_URL: postgresql://roast:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}@db:5432/roast
      APP_ORIGIN: https://roast.srmr.xyz
      COOKIE_SECURE: "true"
      # Optional after the one-time administrator bootstrap has completed.
      BOOTSTRAP_SETUP_TOKEN: ${BOOTSTRAP_SETUP_TOKEN:-}
      # Leave unset unless a known reverse-proxy address/CIDR is configured.
      TRUST_PROXY: ${TRUST_PROXY:-}
      # Browser-rendered fallback for storefronts that rate-limit server fetches.
      BROWSERLESS_URL: ${BROWSERLESS_URL:-http://host.docker.internal:9085}
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      # Seed Pi's writable runtime config from this read-only credential mount.
      - ${PI_AGENT_CONFIG_DIR:-./appdata/pi-agent}:/run/pi-agent-config:ro
    depends_on:
      db:
        condition: service_healthy
    # Nginx Proxy Manager routes https://roast.srmr.xyz to this host port.
    ports: ["${APP_PORT:-8090}:8090"]
    restart: unless-stopped
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: roast
      POSTGRES_USER: roast
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}
    volumes: [postgres-data:/var/lib/postgresql/data]
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U roast -d roast"]
      interval: 5s
      timeout: 3s
      retries: 12
    restart: unless-stopped
volumes:
  postgres-data:
