# Media Services
# SABLIER SESSION DURATION: Set to 5m for testing. Increase to 30m for production in config-templates/traefik/dynamic/sablier.yml
# 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:
  # Jellyfin - Open-source media streaming server
  # NOTE: No Authelia - allows app access from Roku, Fire TV, mobile, etc.
  # Uses Sablier lazy loading - starts on-demand, stops after 5min inactivity
  jellyfin:
    image: jellyfin/jellyfin:10.8.13
    deploy:
      resources:
        limits:
          cpus: '2.0'
          memory: 2G
          pids: 2048
        reservations:
          cpus: '1.0'
          memory: 1G
    container_name: jellyfin
    restart: no
    networks:
      - homelab-network
      - traefik-network
    ports:
      - '8096:8096'
    volumes:
      - ./jellyfin/config:/config
      - ./jellyfin/cache:/cache
      - ${MEDIA_DIR}:/media:ro  # Large media files on separate drive
    environment:
      - PUID=${PUID}
      - PGID=${PUID}
      - TZ=${TZ}
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost:8096/']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s
    # Uncomment for hardware transcoding
    # devices:
    #   - /dev/dri:/dev/dri
    # TRAEFIK CONFIGURATION
    labels:
      # Service metadata
      - 'com.centurylinklabs.watchtower.enable=true'
      - 'homelab.category=media'
      - 'homelab.description=Open-source media streaming server'
      - 'traefik.enable=true'
      - 'traefik.docker.network=traefik-network'
      # Router configuration
      - 'traefik.http.routers.jellyfin.rule=Host(`jellyfin.${DOMAIN}`)'
      - 'traefik.http.routers.jellyfin.entrypoints=websecure'
      - 'traefik.http.routers.jellyfin.tls=true'
      - 'traefik.http.routers.jellyfin.tls.certresolver=letsencrypt'
      # Service configuration
      - 'traefik.http.services.jellyfin.loadbalancer.server.port=8096'
      # Sablier configuration
      - 'sablier.enable=true'
      - 'sablier.group=jasper-jellyfin'
      - 'sablier.start-on-demand=true'
      - 'sablier.theme=hacker-terminal'

  # Calibre-Web - Ebook reader and server
  calibre-web:
    image: lscr.io/linuxserver/calibre-web:latest
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 256M
          pids: 512
        reservations:
          cpus: '0.25'
          memory: 128M
    container_name: calibre-web
    restart: unless-stopped
    networks:
      - homelab-network
      - traefik-network
    ports:
      - '8083:8083'
    volumes:
      - ./calibre-web/config:/config
      - ${MEDIA_DIR}/books:/books
    environment:
      - PUID=${PUID}
      - PGID=${PUID}
      - TZ=${TZ}
      - DOCKER_MODS=linuxserver/mods:universal-calibre
    # TRAEFIK CONFIGURATION
    labels:
      # Service metadata
      - 'com.centurylinklabs.watchtower.enable=true'
      - 'homelab.category=media'
      - 'homelab.description=Ebook reader and library management'
      - 'traefik.enable=true'
      - 'traefik.docker.network=traefik-network'
      # Router configuration
      - 'traefik.http.routers.calibre.rule=Host(`calibre.${DOMAIN}`)'
      - 'traefik.http.routers.calibre.entrypoints=websecure'
      - 'traefik.http.routers.calibre.tls.certresolver=letsencrypt'
      - 'traefik.http.routers.calibre.middlewares=authelia@docker'
      # Service configuration
      - 'traefik.http.services.calibre.loadbalancer.server.port=8083'
      # Sablier configuration (disabled by default)
      - 'sablier.enable=true'
      - 'sablier.group=jasper-calibre-web'
      - 'sablier.start-on-demand=true'

x-dockge:
  urls:
    # Proxied URLs (through Traefik)
    - https://jellyfin.${DOMAIN}
    - http://192.168.4.4:8096
    - https://calibre.${DOMAIN}
    - http://192.168.4.4:8083

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