services:
  veronica:
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      - VERONICA_DATABASE_URL=postgresql://${POSTGRES_USER:-veronica}:${POSTGRES_PASSWORD}@postgres:5432/veronica
      - VERONICA_METRICS_PORT=9464
      - VERONICA_API_KEY=${VERONICA_API_KEY:?VERONICA_API_KEY must be set in .env}
    ports:
      - "127.0.0.1:8000:8000"
      - "127.0.0.1:9464:9464"
    depends_on:
      postgres:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "uv", "run", "python", "-c",
             "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 20s
    restart: unless-stopped

  postgres:
    image: postgres:16-alpine
    environment:
      - POSTGRES_USER=veronica
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set in .env}
      - POSTGRES_DB=veronica
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U veronica -d veronica"]
      interval: 5s
      timeout: 3s
      retries: 10
    restart: unless-stopped

  prometheus:
    image: prom/prometheus:v2.51.0
    volumes:
      - ./docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus_data:/prometheus
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
      - --storage.tsdb.retention.time=15d
      # --web.enable-lifecycle removed: allows unauthenticated config reload
    ports:
      - "127.0.0.1:9090:9090"
    depends_on:
      - veronica
    restart: unless-stopped

  grafana:
    image: grafana/grafana:10.4.0
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD:?GRAFANA_ADMIN_PASSWORD must be set in .env}
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
      - GF_AUTH_ANONYMOUS_ENABLED=${GF_AUTH_ANONYMOUS_ENABLED:-false}
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer
    volumes:
      - ./docker/grafana/provisioning:/etc/grafana/provisioning:ro
      - ./docker/grafana/dashboards:/var/lib/grafana/dashboards:ro
      - grafana_data:/var/lib/grafana
    ports:
      - "127.0.0.1:3000:3000"
    depends_on:
      - prometheus
    restart: unless-stopped

volumes:
  postgres_data:
  prometheus_data:
  grafana_data:
