From aa294c3356967cd952259d8991e8d382781f5ca5 Mon Sep 17 00:00:00 2001 From: framctr <35109437+framctr@users.noreply.github.com> Date: Tue, 8 Oct 2024 08:44:14 +0200 Subject: [PATCH 1/2] Add support for subdomain to main.tf in jupyterlab module --- jupyterlab/main.tf | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf index d7928f0..2995087 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,15 @@ variable "share" { } } +variable "subdomain" { + type = bool + default = true + validation { + condition = var.share == "owner" || var.share == "authenticated" || var.share == "public" + error_message = "Incorrect value. Please set either 'owner', 'authenticated', or 'public'." + } +} + 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 +61,27 @@ resource "coder_script" "jupyterlab" { script = templatefile("${path.module}/run.sh", { LOG_PATH : var.log_path, PORT : var.port + BASE_URL : var.subdomain ? "http://localhost:${var.port}/@${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 with end of subdomain URL display_name = "JupyterLab" - url = "http://localhost:${var.port}" + url = var.subdomain ? "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab" : "http://localhost:${var.port}" icon = "/icon/jupyter.svg" - subdomain = true + subdomain = var.subdomain share = var.share order = var.order + + dynamic "healthcheck" { + for_each = var.subdomain ? toset([true]) : toset([]) + content { + url = "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab" + interval = 6 + threshold = 10 + } + } } From 13b60da6bcc4fe2995cc9f623abb41e80119cae3 Mon Sep 17 00:00:00 2001 From: framctr <35109437+framctr@users.noreply.github.com> Date: Tue, 8 Oct 2024 06:59:19 +0000 Subject: [PATCH 2/2] Add support for subdomain in jupyterlab module --- jupyterlab/main.tf | 27 +++++++++++++++++++++++---- jupyterlab/run.sh | 17 ++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf index d7928f0..8b6b5fa 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 it's 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,27 @@ resource "coder_script" "jupyterlab" { script = templatefile("${path.module}/run.sh", { LOG_PATH : var.log_path, PORT : var.port + BASE_URL : var.subdomain ? "http://localhost:${var.port}/@${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 with end of subdomain URL display_name = "JupyterLab" - url = "http://localhost:${var.port}" + url = var.subdomain ? "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab" : "http://localhost:${var.port}" icon = "/icon/jupyter.svg" - subdomain = true + subdomain = var.subdomain share = var.share order = var.order -} + + dynamic "healthcheck" { + for_each = var.subdomain ? toset([true]) : toset([]) + content { + url = "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab" + interval = 6 + threshold = 10 + } + } +} \ No newline at end of file diff --git a/jupyterlab/run.sh b/jupyterlab/run.sh index 0245b06..59d2272 100755 --- a/jupyterlab/run.sh +++ b/jupyterlab/run.sh @@ -1,5 +1,10 @@ #!/usr/bin/env sh +if [ -n "$BASE_URL" ] +then + BASE_URL="--ServerApp.base_url=${BASE_URL}" +fi + BOLD='\033[0;1m' printf "$${BOLD}Installing jupyterlab!\n" @@ -15,11 +20,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 & +$HOME/.local/bin/jupyter-lab --no-browser \ + "$BASE_URL" \ + --ServerApp.ip='*' \ + --ServerApp.port="${PORT}" \ + --ServerApp.token='' \ + --ServerApp.password='' \ + > "${LOG_PATH}" 2>&1 & \ No newline at end of file