# Docker Compose for Local Development/Testing
#
# Usage:
#   # Build and run single worker
#   docker-compose up --build worker
#
#   # Run with local CSV (standalone mode)
#   docker-compose run --rm worker --csv /data/english_podcasts.csv
#
#   # Run multiple workers (when using coordinator)
#   docker-compose up --scale worker=4

version: '3.8'

services:
  worker:
    build:
      context: .
      dockerfile: Dockerfile
    
    # GPU access
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    
    environment:
      # R2 Storage (required for uploads)
      - R2_ACCESS_ID=${R2_ACCESS_ID:-c3c9190ae7ff98b10271ea8db6940210}
      - R2_SECRET_KEY=${R2_SECRET_KEY}
      - R2_ACCOUNT_ID=${R2_ACCOUNT_ID:-cb908ed13329eb7b186e06ab51bda190}
      - R2_BUCKET=${R2_BUCKET:-diarization-output}
      
      # Coordinator (optional - standalone mode if not set)
      - COORDINATOR_URL=${COORDINATOR_URL:-}
      - COORDINATOR_API_KEY=${COORDINATOR_API_KEY:-}
      
      # HuggingFace token for model access
      - HF_TOKEN=${HF_TOKEN}
      
      # Worker settings
      - WORKER_ID=${WORKER_ID:-}
      - MAX_RETRIES=${MAX_RETRIES:-3}
      - LOG_LEVEL=${LOG_LEVEL:-INFO}
      
      # Region tag (for multi-region deployments)
      - AZURE_REGION=${AZURE_REGION:-local}
    
    volumes:
      # Mount data directory for local CSV access
      - ./data:/data:ro
      
      # Model cache persistence (speeds up restarts)
      - model-cache:/models
      
      # Temp directory for processing
      - /tmp/diarization:/tmp/diarization
    
    # Restart policy
    restart: unless-stopped
    
    # Logging
    logging:
      driver: json-file
      options:
        max-size: "100m"
        max-file: "3"

  # Optional: Local coordinator for testing
  coordinator:
    image: python:3.11-slim
    profiles: ["dev"]
    ports:
      - "8000:8000"
    environment:
      - DATABASE_URL=${DATABASE_URL:-sqlite:///./coordinator.db}
    volumes:
      - ./coordinator:/app
    working_dir: /app
    command: ["python", "-m", "uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]

volumes:
  model-cache:
    name: diarization-model-cache















