version: '3.9'

services:
  # RAG Service (Orchestrator + REST API)
  rag-service:
    build:
      context: ..
      dockerfile: docker/Dockerfile
    container_name: provisioning-rag
    ports:
      - "9090:9090"
    environment:
      PROVISIONING_LOG_LEVEL: debug
      PROVISIONING_API_HOST: 0.0.0.0
      PROVISIONING_API_PORT: 9090
      PROVISIONING_CACHE_SIZE: 1000
      PROVISIONING_CACHE_TTL_SECS: 3600
      RUST_LOG: debug
    volumes:
      - ./data:/app/data
      - ./logs:/app/logs
    networks:
      - provisioning-network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9090/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 5s
    restart: unless-stopped
    labels:
      com.provisioning.component: rag-service
      com.provisioning.phase: "8e"

  # SurrealDB (for optional persistence)
  surrealdb:
    image: surrealdb/surrealdb:latest
    container_name: provisioning-surrealdb
    ports:
      - "8000:8000"
    environment:
      SURREAL_LOG: debug
    volumes:
      - surrealdb-data:/data
    networks:
      - provisioning-network
    command: start --bind 0.0.0.0:8000 file:/data/db.db
    restart: unless-stopped
    labels:
      com.provisioning.component: database
      com.provisioning.phase: "8e"

  # Prometheus (metrics collection)
  prometheus:
    image: prom/prometheus:latest
    container_name: provisioning-prometheus
    ports:
      - "9091:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus-data:/prometheus
    networks:
      - provisioning-network
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
    restart: unless-stopped
    labels:
      com.provisioning.component: metrics
      com.provisioning.phase: "8e"

  # Grafana (visualization)
  grafana:
    image: grafana/grafana:latest
    container_name: provisioning-grafana
    ports:
      - "3000:3000"
    environment:
      GF_SECURITY_ADMIN_PASSWORD: admin
      GF_INSTALL_PLUGINS: grafana-piechart-panel
    volumes:
      - grafana-data:/var/lib/grafana
      - ./grafana-dashboards:/etc/grafana/provisioning/dashboards
    networks:
      - provisioning-network
    depends_on:
      - prometheus
    restart: unless-stopped
    labels:
      com.provisioning.component: visualization
      com.provisioning.phase: "8e"

networks:
  provisioning-network:
    driver: bridge

volumes:
  surrealdb-data:
  prometheus-data:
  grafana-data:
