version: '3.8'

services:
  # DAGI Router для NODE3
  dagi-router-node3:
    build:
      context: ./services/router
      dockerfile: Dockerfile
    container_name: dagi-router-node3
    ports:
      - "9102:9102"
    environment:
      - NATS_URL=nats://144.76.224.179:4222
      - ROUTER_CONFIG_PATH=/app/router_config.yaml
      - LOG_LEVEL=info
      - NODE_ID=node-3-threadripper-rtx3090
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ./services/router/router_config.yaml:/app/router_config.yaml:ro
      - ./logs:/app/logs
    networks:
      - dagi-network
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9102/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

  # Swapper Service для NODE3
  swapper-service-node3:
    build:
      context: ./services/swapper-service
      dockerfile: Dockerfile
    container_name: swapper-service-node3
    ports:
      - "8890:8890"
      - "8891:8891"  # Metrics
    environment:
      - OLLAMA_BASE_URL=http://host.docker.internal:11434
      - SWAPPER_CONFIG_PATH=/app/config/swapper_config.yaml
      - SWAPPER_MODE=single-active
      - MAX_CONCURRENT_MODELS=1
      - MODEL_SWAP_TIMEOUT=300
      - GPU_ENABLED=true
      - NODE_ID=node-3-threadripper-rtx3090
    volumes:
      - ./services/swapper-service/config/swapper_config_node3.yaml:/app/config/swapper_config.yaml:ro
      - ./logs:/app/logs
    networks:
      - dagi-network
    restart: unless-stopped
    extra_hosts:
      - "host.docker.internal:host-gateway"
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://localhost:8890/health || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

  # Comfy Agent - Image & Video Generation Service
  comfy-agent:
    build:
      context: ./services/comfy-agent
      dockerfile: Dockerfile
    container_name: comfy-agent-node3
    ports:
      - "8880:8880"
    environment:
      - COMFYUI_HTTP=http://host.docker.internal:8188
      - COMFYUI_WS=ws://host.docker.internal:8188/ws
      - NATS_URL=nats://144.76.224.179:4222
      - NATS_SUBJECT_INVOKE=agent.invoke.comfy
      - NATS_SUBJECT_IMAGE=comfy.request.image
      - NATS_SUBJECT_VIDEO=comfy.request.video
      - STORAGE_PATH=/data/comfy-results
      - PUBLIC_BASE_URL=http://212.8.58.133:8880/files
      - MAX_CONCURRENCY=1
    volumes:
      - comfy-results:/data/comfy-results
      - ./logs:/app/logs
    networks:
      - dagi-network
    restart: unless-stopped
    extra_hosts:
      - "host.docker.internal:host-gateway"
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://localhost:8880/healthz || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 15s

networks:
  dagi-network:
    external: true

volumes:
  comfy-results:
    driver: local
