services:
  app:
    image: git.fabledsword.com/bvandeusen/fabledscribe:latest
    environment:
      DATABASE_URL: "postgresql+asyncpg://scribe:${DB_PASSWORD}@db:5432/scribe"
      SECRET_KEY: "${SECRET_KEY}"
      LOG_LEVEL: "${LOG_LEVEL:-INFO}"
      TRUST_PROXY_HEADERS: "true"
      SECURE_COOKIES: "true"
    networks:
      - scribe_backend
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:5000/api/health')"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s
    deploy:
      restart_policy:
        condition: on-failure
        max_attempts: 5

  db:
    # pgvector image (Debian/glibc, PG17) — bundles the `vector` extension that
    # migration 0067 enables. Moved off postgres:16-alpine via logical
    # dump/restore (which doubles as the PG16->PG17 major upgrade); see the
    # TRANSITION runbook in the PR.
    image: pgvector/pgvector:pg17
    stop_grace_period: 120s
    volumes:
      - pgdata:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: scribe
      POSTGRES_PASSWORD: "${DB_PASSWORD}"
      POSTGRES_DB: scribe
    networks:
      - scribe_backend
    # Lenient by design: a transient host exec/healthcheck stall (incident:
    # runc setns failures -> "unhealthy" -> SIGKILL -> crash loop) must never
    # escalate to killing the DB. Health here only gates app startup order.
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U scribe"]
      interval: 30s
      timeout: 10s
      retries: 10
      start_period: 180s
    deploy:
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 0
        window: 120s

volumes:
  pgdata:

networks:
  scribe_backend:
    driver: overlay
