services:
  traefik:
    image: traefik:v3.6.13
    container_name: mediabridge-traefik
    command:
      - --providers.docker=true
      - --providers.docker.exposedbydefault=false
      - --entrypoints.srt-udp.address=:${TRAEFIK_UDP_PORT:-9000}/udp
      - --log.level=${TRAEFIK_LOG_LEVEL:-INFO}
    ports:
      - "${TRAEFIK_UDP_PORT:-9000}:${TRAEFIK_UDP_PORT:-9000}/udp"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    restart: unless-stopped

  mediabridge:
    build: .
    container_name: mediabridge
    environment:
      LISTEN_PORT: ${LISTEN_PORT}
      ALLOWLIST_FILE: ${ALLOWLIST_FILE}
      RING_CHUNKS: ${RING_CHUNKS}
      CHUNK_SIZE: ${CHUNK_SIZE}
      LOW_LATENCY: ${LOW_LATENCY}
      MAX_LAG_CHUNKS: ${MAX_LAG_CHUNKS}
      LAG_HIGH_CHUNKS: ${LAG_HIGH_CHUNKS}
      LAG_LOW_CHUNKS: ${LAG_LOW_CHUNKS}
      PLAYER_WAIT_MS: ${PLAYER_WAIT_MS}
      EDGE_BACK: ${EDGE_BACK}
      JUMP_COOLDOWN_MS: ${JUMP_COOLDOWN_MS}
      PLAY_LOG_MS: ${PLAY_LOG_MS}
      HEALTH_BIND: ${HEALTH_BIND}
      SERVICE_ID: ${SERVICE_ID}
      SERVICE_DESCRIPTION: ${SERVICE_DESCRIPTION}
      RELEASE_ID: ${RELEASE_ID}
      STALLED_FLOW_MS: ${STALLED_FLOW_MS}
      MEMORY_WARN_PERCENT: ${MEMORY_WARN_PERCENT}
      MEMORY_FAIL_PERCENT: ${MEMORY_FAIL_PERCENT}
      STATS_SRT_HOST: ${STATS_SRT_HOST}
      STATS_SRT_LATENCY_MS: ${STATS_SRT_LATENCY_MS}
      BACKEND_URL: ${BACKEND_URL}
      BACKEND_HOST_HEADER: ${BACKEND_HOST_HEADER}
      BACKEND_AUTH_LOGIN: ${BACKEND_AUTH_LOGIN}
      BACKEND_AUTH_PASSWORD: ${BACKEND_AUTH_PASSWORD}
      ADMIN_AUTH_LOGIN: ${ADMIN_AUTH_LOGIN}
      ADMIN_AUTH_PASSWORD: ${ADMIN_AUTH_PASSWORD}
    labels:
      - "traefik.enable=true"
      - "traefik.udp.routers.mediabridge-srt.entrypoints=srt-udp"
      - "traefik.udp.routers.mediabridge-srt.service=mediabridge-srt"
      - "traefik.udp.services.mediabridge-srt.loadbalancer.server.port=${LISTEN_PORT:-9000}"
    volumes:
      - ./config/allowlist.json:/config/allowlist.json:ro
    extra_hosts:
      - "host.docker.internal:host-gateway"
    ports:
      - "127.0.0.1:${HEALTH_PORT:-8080}:8080/tcp"
    restart: unless-stopped
