# docker-compose.tuning.doctr.yml - Ray Tune with DocTR GPU
# Usage:
#   docker compose -f docker-compose.tuning.doctr.yml up -d doctr-gpu
#   docker compose -f docker-compose.tuning.doctr.yml run raytune --service doctr --samples 64
#   docker compose -f docker-compose.tuning.doctr.yml down

services:
  raytune:
    image: seryus.ddns.net/unir/raytune:latest
    command: ["--service", "doctr", "--host", "doctr-gpu", "--port", "8000", "--samples", "64"]
    volumes:
      - ./results:/app/results:rw
    environment:
      - PYTHONUNBUFFERED=1
    depends_on:
      doctr-gpu:
        condition: service_healthy

  doctr-gpu:
    image: seryus.ddns.net/unir/doctr-gpu:latest
    container_name: doctr-gpu-tuning
    ports:
      - "8003:8000"
    volumes:
      - ./dataset:/app/dataset:ro
      - ./debugset:/app/debugset:rw
      - doctr-cache:/root/.cache/doctr
    environment:
      - PYTHONUNBUFFERED=1
      - CUDA_VISIBLE_DEVICES=0
      - DOCTR_DET_ARCH=db_resnet50
      - DOCTR_RECO_ARCH=crnn_vgg16_bn
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 180s

volumes:
  doctr-cache:
    name: doctr-model-cache
