version: "3.9"

services:
  proxy:
    image: traefik:v2.10
    container_name: traefik
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./docker/traefik/traefik.yml:/traefik.yml
      - ./docker/traefik/acme.json:/acme.json
    networks:
      - streamer_net
    restart: unless-stopped

  comfyui:
    build:
      context: ./docker/comfyui
      dockerfile: Dockerfile
    container_name: comfyui
    environment:
      - CLI_ARGS=--listen 0.0.0.0 --port 8188
    volumes:
      - ./com_vicentaotv/media/com_vicentaotv/workflows:/app/ComfyUI/custom_workflows
      - ./com_vicentaotv/media/com_vicentaotv/generated/video:/app/output
      - ./models:/app/models
    gpus: all
    networks:
      - streamer_net
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.comfy.rule=Host(`comfy.live.whatss.app.br`)"
      - "traefik.http.routers.comfy.entrypoints=web,websecure"
      - "traefik.http.routers.comfy.tls.certresolver=letsencrypt"
      - "traefik.http.services.comfy.loadbalancer.server.port=8188"
    restart: unless-stopped

  assistant_api:
    build:
      context: ./docker/assistant-api
      dockerfile: Dockerfile
    container_name: assistant-api
    environment:
      - COMFY_URL=http://comfyui:8188
      - GENERATED_ROOT=/generated
      - WORKFLOWS_DIR=/workflows
      - AZURE_KEY=${AZURE_KEY}
      - AZURE_REGION=${AZURE_REGION}
      - OBS_HOST=host.docker.internal
      - OBS_PORT=4455
      - OBS_PASSWORD=${OBS_PASSWORD}
    volumes:
      - ./com_vicentaotv/media/com_vicentaotv/generated:/generated
      - ./com_vicentaotv/media/com_vicentaotv/workflows:/workflows
    depends_on:
      - comfyui
    networks:
      - streamer_net
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.assistant.rule=Host(`api.live.whatss.app.br`)"
      - "traefik.http.routers.assistant.entrypoints=web,websecure"
      - "traefik.http.routers.assistant.tls.certresolver=letsencrypt"
      - "traefik.http.services.assistant.loadbalancer.server.port=8009"
      - "traefik.http.middlewares.assistant-cors.headers.accesscontrolalloworiginlist=https://live.whatss.app.br,https://api.live.whatss.app.br,https://comfy.live.whatss.app.br,https://vicentethiago.com.br,https://www.vicentethiago.com.br,https://ojusto.vicentethiago.com.br,https://www.ojusto.vicentethiago.com.br"
      - "traefik.http.middlewares.assistant-cors.headers.accesscontrolallowmethods=*"
      - "traefik.http.middlewares.assistant-cors.headers.accesscontrolallowheaders=*"
      - "traefik.http.middlewares.assistant-cors.headers.accesscontrolallowcredentials=true"
      - "traefik.http.routers.assistant.middlewares=assistant-cors"
    restart: unless-stopped

  voiceclone:
    build:
      context: ./docker/voice-clone
      dockerfile: Dockerfile
    container_name: voiceclone
    volumes:
      - ./voice_models:/models
      - ./com_vicentaotv/media/com_vicentaotv/generated/audio:/output
    gpus: all
    networks:
      - streamer_net
    restart: unless-stopped

  asr:
    build:
      context: ./docker/asr-whisper
      dockerfile: Dockerfile
    container_name: asr-whisper
    volumes:
      - ./com_vicentaotv/media/com_vicentaotv/generated/audio:/audio
    networks:
      - streamer_net
    restart: unless-stopped

  tts:
    build:
      context: ./docker/tts-piper
      dockerfile: Dockerfile
    container_name: tts-piper
    volumes:
      - ./voices:/voices
      - ./com_vicentaotv/media/com_vicentaotv/generated/audio:/output
    networks:
      - streamer_net
    restart: unless-stopped

networks:
  default:
    name: streamer_net
  streamer_net:
    name: streamer_net

