version: '3.8'

# Docker Compose configuration for HTTP/API mode
# Usage: docker-compose -f docker-compose.http.yml up -d

services:
  mcp-memory-service:
    build:
      context: ../..
      dockerfile: tools/docker/Dockerfile
    ports:
      - "${HTTP_PORT:-8000}:8000"  # Map to different port if needed
    volumes:
      # Single data directory for all storage
      - ./data:/app/data

      # Model cache (prevents re-downloading models on each restart)
      # Uncomment the following line to persist Hugging Face models
      # - ${HOME}/.cache/huggingface:/root/.cache/huggingface

      # Optional: mount local config
      # - ./config:/app/config:ro
    environment:
      # Mode selection
      - MCP_MODE=http
      
      # Storage configuration
      - MCP_MEMORY_STORAGE_BACKEND=sqlite_vec
      - MCP_MEMORY_SQLITE_PATH=/app/data/sqlite_vec.db
      - MCP_MEMORY_BACKUPS_PATH=/app/data/backups
      
      # HTTP configuration
      - MCP_HTTP_PORT=8000
      - MCP_HTTP_HOST=0.0.0.0
      - MCP_API_KEY=${MCP_API_KEY:-your-secure-api-key-here}
      
      # Optional: HTTPS configuration
      # - MCP_HTTPS_ENABLED=true
      # - MCP_HTTPS_PORT=8443
      # - MCP_SSL_CERT_FILE=/app/certs/cert.pem
      # - MCP_SSL_KEY_FILE=/app/certs/key.pem
      
      # Performance tuning
      - LOG_LEVEL=${LOG_LEVEL:-INFO}
      - MAX_RESULTS_PER_QUERY=10
      - SIMILARITY_THRESHOLD=0.7
      
      # Python configuration
      - PYTHONUNBUFFERED=1
      - PYTHONPATH=/app/src

      # Offline mode (uncomment if models are pre-cached and network is restricted)
      # - HF_HUB_OFFLINE=1
      # - TRANSFORMERS_OFFLINE=1
    
    # Use the unified entrypoint
    entrypoint: ["/usr/local/bin/docker-entrypoint-unified.sh"]
    
    restart: unless-stopped
    
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/api/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    
    # Resource limits (optional, adjust as needed)
    deploy:
      resources:
        limits:
          cpus: '2.0'
          memory: 2G
        reservations:
          cpus: '0.5'
          memory: 512M