job "jellyfin" {
  group "jellyfin" {
    count = 1

    network {
      port "http" {
        to = 8096
      }
    }

    task "jellyfin" {
      driver = "docker"

      config {
        image = "lscr.io/linuxserver/jellyfin:latest"
        ports = ["http"]
      }

      service {
        name = "jellyfin"
        port = "http"

        tags = [
          "traefik.enable=true",
          "traefik.http.routers.jellyfin.middlewares=auth@file",
          "traefik.http.routers.jellyfin-token.rule=Host(`c3ll7nbevl5j4j8rcnfxnr95q48fuayz-jellyfin.othrayte.one`)",
        ]

        check {
          name     = "alive"
          type     = "tcp"
          port     = "http"
          interval = "10s"
          timeout  = "2s"
        }
      }

      env {
        PUID = 1000
        PGID = 1000
        TZ   = "Australia/Melbourne"

        JELLYFIN_PublishedServerUrl = "https://jellyfin.othrayte.one"
      }

      volume_mount {
        volume      = "unraid_appdata_jellyfin"
        destination = "/config"
        read_only   = false
      }

      volume_mount {
        volume      = "unraid_media_jellyfin"
        destination = "/data"
        read_only   = false
      }

      resources {
        cpu    = 500
        memory = 2048
      }
    }

    volume "unraid_appdata_jellyfin" {
      type            = "csi"
      read_only       = false
      source          = "unraid_appdata_jellyfin"
      access_mode     = "single-node-writer"
      attachment_mode = "file-system"

      mount_options {
        mount_flags = ["uid=1000", "gid=1000"]
      }
    }

    volume "unraid_media_jellyfin" {
      type            = "csi"
      read_only       = false
      source          = "unraid_media_jellyfin"
      access_mode     = "single-node-writer"
      attachment_mode = "file-system"

      mount_options {
        mount_flags = ["nobrl", "uid=1000", "gid=1000"]
      }
    }
  }
}
