# Transcoder Services
# RESTART POLICY GUIDE:
# - unless-stopped: Core infrastructure services that should always run
# - no: Services with Sablier lazy loading (start on-demand)
# - See individual service comments for specific reasoning

services:  
  # Tdarr Server - Distributed transcoding server
  tdarr-server:
    image: ghcr.io/haveagitgat/tdarr:latest
    container_name: tdarr-server
    restart: no
    networks:
      - homelab-network
      - traefik-network
    ports:
      - 8265:8265 # Web UI port
      - 8266:8266 # Server port
    volumes:
      - ./tdarr/server:/app/server
      - ./tdarr/configs:/app/configs
      - ./tdarr/logs:/app/logs
      - ${MEDIA_DIR}:/media
      - ${TDARR_TRANSCODE_DIR}:/temp # Transcode cache on separate drive
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
      - serverIP=0.0.0.0
      - serverPort=8266
      - webUIPort=8265
    labels:
      # TRAEFIK CONFIGURATION
      # ==========================================
      # Service metadata
      - 'homelab.category=media'
      - 'homelab.description=Distributed transcoding server'
      - 'com.centurylinklabs.watchtower.enable=true'
      # Traefik reverse proxy (comment/uncomment to disable/enable)
      # If Traefik is on a remote server: these labels are NOT USED; 
      #   configure external yml files in /traefik/dynamic folder instead.
      - 'traefik.enable=true'
      - 'traefik.docker.network=traefik-network'
      - 'traefik.http.routers.tdarr.rule=Host(`tdarr.${DOMAIN}`)'
      - 'traefik.http.routers.tdarr.entrypoints=websecure'
      - 'traefik.http.routers.tdarr.tls.certresolver=letsencrypt'
      - 'traefik.http.routers.tdarr.middlewares=authelia@docker'
      - 'traefik.http.services.tdarr.loadbalancer.server.port=8265'
      - 'sablier.enable=true'
      - 'sablier.group=jasper-tdarr'
      - 'sablier.start-on-demand=true'

  # Tdarr Node - Transcoding worker
  # No web UI - controlled by server
  tdarr-node:
    image: ghcr.io/haveagitgat/tdarr_node:latest
    container_name: tdarr-node
    restart: unless-stopped
    networks:
      - homelab-network
    volumes:
      - ./tdarr/configs:/app/configs
      - ./tdarr/logs:/app/logs
      - ${MEDIA_DIR}:/media
      - ${TDARR_TRANSCODE_DIR}:/temp
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
      - nodeID=MainNode
      - nodeIP=0.0.0.0
      - nodePort=8267
      - serverIP=tdarr-server
      - serverPort=8266
    labels:
      - homelab.category=media
      - homelab.description=Tdarr transcoding worker node
      - 'sablier.enable=true'
      - 'sablier.group=jasper-tdarr'
      - 'sablier.start-on-demand=true'

  # Unmanic - Another transcoding option
  unmanic:
    image: josh5/unmanic:latest
    container_name: unmanic
    restart: no
    networks:
      - homelab-network
      - traefik-network
    ports:
      - '8889:8888'
    volumes:
      - ./unmanic/config:/config
      - ${MEDIA_DIR}:/library
      - ${UNMANIC_TRANSCODE_DIR}:/tmp/unmanic # Transcode cache on separate drive
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
    labels:
      # TRAEFIK CONFIGURATION
      # ==========================================
      # Service metadata
      - 'homelab.category=media'
      - 'homelab.description=Library optimization and transcoding'
      - 'com.centurylinklabs.watchtower.enable=true'
      # Traefik reverse proxy (comment/uncomment to disable/enable)
      # If Traefik is on a remote server: these labels are NOT USED; 
      #   configure external yml files in /traefik/dynamic folder instead.
      - 'traefik.enable=true'
      - 'traefik.docker.network=traefik-network'
      - 'traefik.http.routers.unmanic.rule=Host(`unmanic.${DOMAIN}`)'
      - 'traefik.http.routers.unmanic.entrypoints=websecure'
      - 'traefik.http.routers.unmanic.tls.certresolver=letsencrypt'
      - 'traefik.http.routers.unmanic.middlewares=authelia@docker'
      - 'traefik.http.services.unmanic.loadbalancer.server.port=8889'
      - 'sablier.enable=true'
      - 'sablier.group=jasper-unmanic'
      - 'sablier.start-on-demand=true'

networks:
  homelab-network:
    external: true
  traefik-network:
    external: true

x-dockge:
  urls:
    - https://tdarr.${DOMAIN}
    - http://192.168.4.4:8265
    - https://unmanic.${DOMAIN}
    - http://192.168.4.4:8888