version: "3.8"

services:
  postgres:
    image: postgres:15
    environment:
      POSTGRES_DB: docmaster
      POSTGRES_USER: docmaster
      POSTGRES_PASSWORD: ${DB_PASSWORD:-devpassword}
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./migrations:/docker-entrypoint-initdb.d

  inference:
    build:
      context: .
      dockerfile: packages/inference/Dockerfile
    ports:
      - "8000:8000"
    environment:
      - DB_HOST=postgres
      - DB_PORT=5432
      - DB_NAME=docmaster
      - DB_USER=docmaster
      - DB_PASSWORD=${DB_PASSWORD:-devpassword}
      - MODEL_PATH=/app/models/best.pt
    volumes:
      - ./models:/app/models
    depends_on:
      - postgres

  training:
    build:
      context: .
      dockerfile: packages/training/Dockerfile
    environment:
      - DB_HOST=postgres
      - DB_PORT=5432
      - DB_NAME=docmaster
      - DB_USER=docmaster
      - DB_PASSWORD=${DB_PASSWORD:-devpassword}
    volumes:
      - ./models:/app/models
      - ./temp:/app/temp
    depends_on:
      - postgres
    # Override CMD for local dev polling mode
    command: ["python", "run_training.py", "--poll", "--poll-interval", "30"]
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]

volumes:
  pgdata:
