# /opt/docker/dev/service_finder/docker-compose.yml
services:
  # --- ADATBÁZIS KEZELÉS ---
  migrate:
    build: ./backend
    container_name: sentinel_migrate
    env_file: .env
    volumes:
      - ./backend:/app
    command: >
      bash -c "sleep 5 && alembic upgrade head && python -m app.final_admin_fix"
    networks:
      - sentinel_net
      - shared_db_net
    restart: "no"

  # --- KÖZPONTI API ---
  api:
    build: ./backend
    container_name: sentinel_api
    env_file: .env
    ports:
      - "8000:8000"
    volumes:
      - ./backend:/app
      - /mnt/nas/app_data:/mnt/nas/app_data
      - ./static_previews:/app/static/previews
    depends_on:
      migrate: { condition: service_completed_successfully }
      redis: { condition: service_started }
    networks:
      - sentinel_net
      - shared_db_net
    restart: unless-stopped

  # --- AI MAG (Ollama) ---
  ollama:
    image: ollama/ollama:latest
    container_name: sentinel_ollama
    volumes:
      - ./ollama_data:/root/.ollama
    ports:
      - "11434:11434"
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    networks:
      - sentinel_net

  # --- ROBOT HADSEREG ---
  
  # Robot 0 & 1: Felfedezés és Vadászat
  scout_robot:
    build: ./backend
    container_name: sentinel_scout
    command: python -u -m app.workers.service_hunter
    env_file: .env
    depends_on:
      api: { condition: service_started }
    networks:
      - sentinel_net
      - shared_db_net

  # Robot 2.1: Kutató (Több példányban a gyorsaságért)
  researcher:
    build: ./backend
    command: python -u -m app.workers.researcher_v2_1
    deploy:
      replicas: 2
    env_file: .env
    networks:
      - sentinel_net
      - shared_db_net

  # Robot 2.2: Alkimista (AI dúsító - GPU igényes)
  alchemist:
    build: ./backend
    command: python -u -m app.workers.technical_enricher
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    env_file: .env
    depends_on:
      ollama: { condition: service_started }
    networks:
      - sentinel_net
      - shared_db_net

  # --- INFRASTRUKTÚRA ---
  redis:
    image: redis:alpine
    container_name: sentinel_redis
    networks:
      - sentinel_net

  minio:
    image: minio/minio
    container_name: sentinel_minio
    env_file: .env
    command: server /data --console-address ":9001"
    volumes:
      - /mnt/nas/app_data/minio_data:/data
    networks:
      - sentinel_net

  n8n:
    image: n8nio/n8n:latest
    container_name: sentinel_n8n
    env_file: .env
    ports:
      - "5678:5678"
    networks:
      - sentinel_net
      - shared_db_net

networks:
  sentinel_net:
    driver: bridge
  shared_db_net:
    external: true