# Production Docker Compose
# Pulls pre-built images from GitLab Container Registry instead of building locally.
# Uses on the server: docker compose -f docker-compose.prod.yml up -d
#
# Required env vars (in .env on the server):
#   REGISTRY   — e.g. registry.gitlab.com/your-org/shoolini-rag
#   IMAGE_TAG  — commit SHA or "latest"

services:

  # ─── Data Pipeline ─────────────────────────────────────────

  crawler:
    image: ${REGISTRY}/crawler:${IMAGE_TAG:-latest}
    container_name: shoolini_crawler
    ports:
      - "8001:8001"
    volumes:
      - data_raw:/data/raw
      - data_logs:/data/logs
    env_file: .env
    networks:
      - internal
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8001/health', timeout=5)"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 15s

  processor:
    image: ${REGISTRY}/processor:${IMAGE_TAG:-latest}
    container_name: shoolini_processor
    ports:
      - "8002:8002"
    volumes:
      - data_raw:/data/raw:ro
      - data_chunks:/data/chunks
      - data_logs:/data/logs
    env_file: .env
    networks:
      - internal
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8002/health', timeout=5)"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 15s

  indexer:
    image: ${REGISTRY}/indexer:${IMAGE_TAG:-latest}
    container_name: shoolini_indexer
    ports:
      - "8003:8003"
    volumes:
      - data_chunks:/data/chunks:ro
      - data_chroma:/data/chroma_db
      - data_logs:/data/logs
    env_file: .env
    networks:
      - internal
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8003/health', timeout=5)"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 15s

  # ─── Orchestrator ──────────────────────────────────────────

  scheduler:
    image: ${REGISTRY}/scheduler:${IMAGE_TAG:-latest}
    container_name: shoolini_scheduler
    ports:
      - "8005:8005"
    volumes:
      - data_logs:/data/logs
    env_file: .env
    environment:
      - CRAWLER_URL=http://crawler:8001
      - PROCESSOR_URL=http://processor:8002
      - INDEXER_URL=http://indexer:8003
      - API_URL=http://api:8000
    depends_on:
      crawler:
        condition: service_healthy
      processor:
        condition: service_healthy
      indexer:
        condition: service_healthy
    networks:
      - internal
    restart: unless-stopped

  # ─── Chat API ──────────────────────────────────────────────

  api:
    image: ${REGISTRY}/api:${IMAGE_TAG:-latest}
    container_name: shoolini_api
    ports:
      - "4001:8000"
    volumes:
      - data_chroma:/data/chroma_db
      - data_logs:/data/logs
    env_file: .env
    depends_on:
      indexer:
        condition: service_healthy
    networks:
      - internal
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=5)"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 15s

  # ─── Frontend ──────────────────────────────────────────────

  frontend:
    image: ${REGISTRY}/frontend:${IMAGE_TAG:-latest}
    container_name: shoolini_frontend
    ports:
      - "4000:4000"
    depends_on:
      - api
    networks:
      - internal
    restart: unless-stopped

# ─── Volumes ─────────────────────────────────────────────────

volumes:
  data_raw:
  data_chunks:
  data_chroma:
  data_logs:

# ─── Networks ────────────────────────────────────────────────

networks:
  internal:
    driver: bridge
