coder / modules

A collection of Terraform Modules to extend Coder templates.
https://registry.coder.com
Apache License 2.0
33 stars 33 forks source link

Subpath on Jupyterlab module #313

Closed framctr closed 1 month ago

framctr commented 1 month ago

Hi, I'm able to use Jupyter on subpath in the following way:

data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}

resource "coder_agent" "main" {
  os   = "linux"
  arch = "amd64"

  metadata {
    display_name = "CPU Usage"
    key          = "0_cpu_usage"
    script       = "coder stat cpu"
    interval     = 10
    timeout      = 1
  }

  metadata {
    display_name = "RAM Usage"
    key          = "1_ram_usage"
    script       = "coder stat mem"
    interval     = 10
    timeout      = 1
  }

  metadata {
    display_name = "Home Disk"
    key          = "3_home_disk"
    script       = "coder stat disk --path $${HOME}"
    interval     = 60
    timeout      = 1
  }
}

resource "coder_script" "jupyterlab" {
  agent_id     = coder_agent.main.id
  display_name = "Jupyter"
  icon         = "/icon/jupyter.svg"
  script = templatefile("${path.module}/run.sh",
    {
      LOG_PATH        = "/tmp/jupyterlab.log"
      PORT            = 8888
      WORKSPACE_OWNER = data.coder_workspace_owner.me.name
      WORKSPACE_NAME  = data.coder_workspace.me.name
    }
  )
  run_on_start = true
}

resource "coder_app" "jupyter" {
  agent_id     = coder_agent.main.id
  display_name = "JupyterLab"
  icon         = "/icon/jupyter.svg"
  url          = "http://localhost:8888/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyter"
  slug         = "jupyter" # keep in sync with end of URL
  subdomain    = false
  share        = "owner"

  healthcheck {
    url       = "http://localhost:8888/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyter"
    interval  = 6
    threshold = 10
  }
}

And in the run.sh I pass also --ServerApp.base_url=/@"${WORKSPACE_OWNER}"/"${WORKSPACE_NAME}"/apps/jupyter to the jupyter-lab command.

Do you think this change could be added to the jupyter module?

I see from issue coder/registry.coder.com#31 that you would like to provide a filtering for modules that support the subpath argument. In case you see any issue with the previous addition, it could be possible to add a disclaimer.

matifali commented 1 month ago

Thank you, @framctr, for the issue and detailed steps. We welcome you to submit. aPR to add this functionality to the existing module.