job "transfer" {
  group "transfer" {
    network {
      port "http" {
        to = 80
      }
    }

    service {
      name = "transfer"
      port = "http"

      tags = [
        "traefik.enable=true",
        "traefik.http.routers.transfer.middlewares=auth@file",
      ]

      check {
        type     = "http"
        path     = "/"
        interval = "10s"
        timeout  = "2s"
      }
    }

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

      mount_options {
        mount_flags = ["uid=911", "gid=1000"] # linuxserver.io container services run as uid 911
      }
    }

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

      mount_options {
        mount_flags = ["uid=911", "gid=1000"] # linuxserver.io container services run as uid 911
      }
    }

    task "filebrowser" {
      driver = "docker"

      config {
        # Use the s6 tag for the linuxserver.io based image
        image = "filebrowser/filebrowser:s6"

        ports = ["http"]

        volumes = [
          "local/config/settings.json:/config/settings.json",
        ]
      }

      volume_mount {
        volume      = "appdata"
        destination = "/database"
        read_only   = false
      }

      volume_mount {
        volume      = "unraid_transfer"
        destination = "/srv"
        read_only   = false
      }

      resources {
        cpu    = 500
        memory = 256
      }

      template {
        data = <<EOF
{
  "port": 80,
  "baseURL": "",
  "address": "",
  "log": "stdout",
  "database": "/database/filebrowser.db",
  "root": "/srv"
}
EOF

        destination = "local/config/settings.json"
      }
    }
  }
}
