job "wiki" {
  datacenters = ["alo"]

  group "servers" {
    volume "services" {
      type = "host"
      read_only = false
      source = "services"
    }
    volume "nix-store" {
      type = "host"
      read_only = true
      source = "nix-store"
    }
    volume "sw" {
      type = "host"
      read_only = true
      source = "sw"
    }

    network {
        port "captainslog" { }
        port "alo" { }
        port "pispace" { }
        port "grok" { }
    }

    task "captainslog" {
      driver = "exec"

      config {
        command = "/sw/bin/node"
        args = [
            "/data/services/wiki/node_modules/tiddlywiki/tiddlywiki.js",
            "/data/services/wiki/captainslog",
            "--listen",
            "host=0.0.0.0",
            "port=${NOMAD_PORT_captainslog}",
            "authenticated-user-header=X-Oidc-Username",
            "readers=ppetru,claude-code",
            "writers=ppetru,claude-code",
            "admin=ppetru",
        ]
      }

      user = "ppetru"

      volume_mount {
        volume = "services"
        destination = "/data/services"
      }
      volume_mount {
        volume = "nix-store"
        destination = "/nix/store"
      }
      volume_mount {
        volume = "sw"
        destination = "/sw"
      }

      service {
        name = "captainslog"
        port = "captainslog"
        tags = [
          "traefik.enable=true",
          "traefik.http.routers.captainslog.entryPoints=websecure",
          "traefik.http.routers.captainslog.middlewares=oidc-auth@file",
        ]
      }

      resources {
        cpu = 500
        memory = 256
      }
    }

    task "alo" {
      driver = "exec"

      config {
        command = "/sw/bin/node"
        args = [
            "/data/services/wiki/node_modules/tiddlywiki/tiddlywiki.js",
            "/data/services/wiki/alo",
            "--listen",
            "host=0.0.0.0",
            "port=${NOMAD_PORT_alo}",
            "authenticated-user-header=X-Oidc-Username",
            "readers=ppetru,ines,claude-code",
            "writers=ppetru,ines,claude-code",
            "admin=ppetru",
        ]
      }

      volume_mount {
        volume = "services"
        destination = "/data/services"
      }
      volume_mount {
        volume = "nix-store"
        destination = "/nix/store"
      }
      volume_mount {
        volume = "sw"
        destination = "/sw"
      }

      service {
        name = "alowiki"
        port = "alo"
        tags = [
          "traefik.enable=true",
          "traefik.http.routers.alowiki.rule=Host(`wiki.alo.land`)",
          "traefik.http.routers.alowiki.entryPoints=websecure",
          "traefik.http.routers.alowiki.middlewares=oidc-auth@file",
        ]
      }

      resources {
        cpu = 500
        memory = 256
      }
    }

    task "pispace" {
      driver = "exec"

      config {
        command = "/sw/bin/node"
        args = [
            "/data/services/wiki/node_modules/tiddlywiki/tiddlywiki.js",
            "/data/services/wiki/pispace",
            "--listen",
            "host=0.0.0.0",
            "port=${NOMAD_PORT_pispace}",
            "authenticated-user-header=X-Oidc-Username",
            "readers=ppetru,ines",
            "writers=ppetru,ines",
            "admin=ppetru",
        ]
      }

      volume_mount {
        volume = "services"
        destination = "/data/services"
      }
      volume_mount {
        volume = "nix-store"
        destination = "/nix/store"
      }
      volume_mount {
        volume = "sw"
        destination = "/sw"
      }

      service {
        name = "pispace"
        port = "pispace"
        tags = [
          "traefik.enable=true",
          "traefik.http.routers.pispace.rule=Host(`pi.paler.net`)",
          "traefik.http.routers.pispace.entryPoints=websecure",
          "traefik.http.routers.pispace.middlewares=oidc-auth@file",
        ]
      }

      resources {
        cpu = 500
        memory = 256
      }
    }

    task "grok" {
      driver = "exec"

      config {
        command = "/sw/bin/node"
        args = [
            "/data/services/wiki/node_modules/tiddlywiki/tiddlywiki.js",
            "/data/services/wiki/grok",
            "--listen",
            "host=0.0.0.0",
            "port=${NOMAD_PORT_grok}",
            "authenticated-user-header=X-Oidc-Username",
            "readers=ppetru",
            "writers=ppetru",
            "admin=ppetru",
        ]
      }

      volume_mount {
        volume = "services"
        destination = "/data/services"
      }
      volume_mount {
        volume = "nix-store"
        destination = "/nix/store"
      }
      volume_mount {
        volume = "sw"
        destination = "/sw"
      }

      service {
        name = "groktw"
        port = "grok"
        tags = [
          "traefik.enable=true",
          "traefik.http.routers.groktw.entryPoints=websecure",
          "traefik.http.routers.groktw.middlewares=oidc-auth@file",
        ]
      }

      resources {
        cpu = 500
        memory = 256
      }
    }
  }
}
