version: '3.9'

services:
  jellyfin:
    image: jellyfin/jellyfin:latest
    environment:
      - JELLYFIN_PublishedServerUrl=jellyfin.pressmess.duckdns.org
    volumes:
      # Use safe local storage for config and cache (avoiding MergerFS for databases)
      - /srv/dev-disk-by-uuid-0f772f0b-917d-4337-a3c5-5cc5d3badac9/jellyfin-config:/config
      - /srv/dev-disk-by-uuid-0f772f0b-917d-4337-a3c5-5cc5d3badac9/jellyfin-cache:/cache
      # Media stays on MergerFS (read-only, no database access)
      - /srv/mergerfs/DataPool/Movies:/media/movies:ro
      - /srv/mergerfs/DataPool/tv_shows:/media/tv_shows:ro
    ports:
      - "8096:8096"
    networks:
      - caddy-public
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8096/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 90s
    deploy:
      resources:
        limits:
          memory: 4G
          cpus: '2.0'
        reservations:
          memory: 1G
          cpus: '0.5'
      placement:
        constraints:
          - node.role == manager
      labels:
        - caddy.enable=true
        - caddy.http.routers.jellyfin.rule=Host(`jellyfin.pressmess.duckdns.org`)
        - caddy.http.routers.jellyfin.entrypoints=websecure
        - caddy.http.routers.jellyfin.tls=true
        - caddy.http.services.jellyfin.loadbalancer.server.port=8096
      replicas: 1

networks:
  caddy-public:
    external: true
