From 1b147ae90dcb1e861751a808a68f68c449c128b6 Mon Sep 17 00:00:00 2001 From: framctr <35109437+framctr@users.noreply.github.com> Date: Mon, 21 Oct 2024 09:06:10 +0200 Subject: [PATCH] feat(jupyterlab): add support for `subdomain=false` (#316) Co-authored-by: Muhammad Atif Ali Co-authored-by: Asher --- jupyterlab/README.md | 2 +- jupyterlab/main.tf | 16 +++++++++++++--- jupyterlab/run.sh | 20 +++++++++++++++----- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/jupyterlab/README.md b/jupyterlab/README.md index ed73b56..52d5a50 100644 --- a/jupyterlab/README.md +++ b/jupyterlab/README.md @@ -16,7 +16,7 @@ A module that adds JupyterLab in your Coder template. ```tf module "jupyterlab" { source = "registry.coder.com/modules/jupyterlab/coder" - version = "1.0.19" + version = "1.0.22" agent_id = coder_agent.example.id } ``` diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf index d7928f0..d66edb1 100644 --- a/jupyterlab/main.tf +++ b/jupyterlab/main.tf @@ -9,6 +9,9 @@ terraform { } } +data "coder_workspace" "me" {} +data "coder_workspace_owner" "me" {} + # Add required variables for your modules and remove any unneeded variables variable "agent_id" { type = string @@ -36,6 +39,12 @@ variable "share" { } } +variable "subdomain" { + type = bool + description = "Determines whether JupyterLab will be accessed via its own subdomain or whether it will be accessed via a path on Coder." + default = true +} + variable "order" { type = number description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)." @@ -49,17 +58,18 @@ resource "coder_script" "jupyterlab" { script = templatefile("${path.module}/run.sh", { LOG_PATH : var.log_path, PORT : var.port + BASE_URL : var.subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab" }) run_on_start = true } resource "coder_app" "jupyterlab" { agent_id = var.agent_id - slug = "jupyterlab" + slug = "jupyterlab" # sync with the usage in URL display_name = "JupyterLab" - url = "http://localhost:${var.port}" + url = var.subdomain ? "http://localhost:${var.port}" : "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab" icon = "/icon/jupyter.svg" - subdomain = true + subdomain = var.subdomain share = var.share order = var.order } diff --git a/jupyterlab/run.sh b/jupyterlab/run.sh index 0245b06..aff21b7 100755 --- a/jupyterlab/run.sh +++ b/jupyterlab/run.sh @@ -1,5 +1,9 @@ #!/usr/bin/env sh +if [ -n "${BASE_URL}" ]; then + BASE_URL_FLAG="--ServerApp.base_url=${BASE_URL}" +fi + BOLD='\033[0;1m' printf "$${BOLD}Installing jupyterlab!\n" @@ -15,11 +19,17 @@ if ! command -v jupyterlab > /dev/null 2>&1; then fi # install jupyterlab pipx install -q jupyterlab - echo "🥳 jupyterlab has been installed\n\n" + printf "%s\n\n" "🥳 jupyterlab has been installed" else - echo "🥳 jupyterlab is already installed\n\n" + printf "%s\n\n" "🥳 jupyterlab is already installed" fi -echo "👷 Starting jupyterlab in background..." -echo "check logs at ${LOG_PATH}" -$HOME/.local/bin/jupyter-lab --ServerApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 & +printf "👷 Starting jupyterlab in background..." +printf "check logs at ${LOG_PATH}" +$HOME/.local/bin/jupyter-lab --no-browser \ + "$BASE_URL_FLAG" \ + --ServerApp.ip='*' \ + --ServerApp.port="${PORT}" \ + --ServerApp.token='' \ + --ServerApp.password='' \ + > "${LOG_PATH}" 2>&1 &