job "tiddlywiki-mcp" {
  datacenters = ["alo"]

  meta {
    uuid = uuidv4()
  }

  group "servers" {
    network {
      port "captainslog" {
        static = 3500
      }
      port "alowiki" {
        static = 3501
      }
    }

    volume "services" {
      type = "host"
      source = "services"
      read_only = false
    }

    volume "nix-store" {
      type = "host"
      source = "nix-store"
      read_only = true
    }

    volume "sw" {
      type = "host"
      source = "sw"
      read_only = true
    }

    task "captainslog" {
      driver = "exec"

      config {
        command = "/sw/bin/node"
        args = ["/data/services/tiddlywiki-mcp/dist/index.js"]
      }

      env {
        MCP_TRANSPORT = "http"
        MCP_PORT = "${NOMAD_PORT_captainslog}"
        TIDDLYWIKI_URL = "captainslog.service.consul"
        OLLAMA_URL = "ollama.service.consul"
        AUTH_HEADER = "X-Oidc-Username"
        AUTH_USER = "claude-code"
        EMBEDDINGS_DB_PATH = "/data/services/tiddlywiki-mcp/embeddings-captainslog.db"
      }

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

      volume_mount {
        volume = "nix-store"
        destination = "/nix/store"
        read_only = true
      }

      volume_mount {
        volume = "sw"
        destination = "/sw"
        read_only = true
      }

      service {
        name = "tiddlywiki-mcp-captainslog"
        port = "captainslog"

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

      resources {
        memory = 256
      }

      user = "ppetru"
    }

    task "alowiki" {
      driver = "exec"

      config {
        command = "/sw/bin/node"
        args = ["/data/services/tiddlywiki-mcp/dist/index.js"]
      }

      env {
        MCP_TRANSPORT = "http"
        MCP_PORT = "${NOMAD_PORT_alowiki}"
        TIDDLYWIKI_URL = "alowiki.service.consul"
        OLLAMA_URL = "ollama.service.consul"
        AUTH_HEADER = "X-Oidc-Username"
        AUTH_USER = "claude-code"
        EMBEDDINGS_DB_PATH = "/data/services/tiddlywiki-mcp/embeddings-alowiki.db"
      }

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

      volume_mount {
        volume = "nix-store"
        destination = "/nix/store"
        read_only = true
      }

      volume_mount {
        volume = "sw"
        destination = "/sw"
        read_only = true
      }

      service {
        name = "tiddlywiki-mcp-alowiki"
        port = "alowiki"

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

      resources {
        memory = 256
      }

      user = "ppetru"
    }
  }
}
