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 01/13] 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 d7928f0d..2995087b 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 9476274d924d5880eb4569c7f7fd73a7c184e17d Mon Sep 17 00:00:00 2001 From: framctr <35109437+framctr@users.noreply.github.com> Date: Tue, 8 Oct 2024 08:48:17 +0200 Subject: [PATCH 02/13] Update run.sh in jupyterlab module with subdomain support --- jupyterlab/run.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/jupyterlab/run.sh b/jupyterlab/run.sh index 0245b069..951a0175 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 \ + --ServerApp.base_url="${BASE_URL}" \ + --ServerApp.ip='*' \ + --ServerApp.port="${PORT}" \ + --ServerApp.token='' \ + --ServerApp.password='' \ + > "${LOG_PATH}" 2>&1 & 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 03/13] 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 d7928f0d..8b6b5fae 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 0245b069..59d2272b 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 From acbf564df6ddd0463431c761a25ac6a6cdcb23ac Mon Sep 17 00:00:00 2001 From: framctr <35109437+framctr@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:56:47 +0000 Subject: [PATCH 04/13] Fixes to Subpath on Jupyter module #313 --- jupyterlab/main.tf | 2 +- jupyterlab/run.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf index 25a9f3de..239c5aa1 100644 --- a/jupyterlab/main.tf +++ b/jupyterlab/main.tf @@ -65,7 +65,7 @@ resource "coder_script" "jupyterlab" { resource "coder_app" "jupyterlab" { agent_id = var.agent_id - slug = "jupyterlab" # sync with with end of subdomain URL + slug = "jupyterlab" # sync with the usage in URL display_name = "JupyterLab" 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" diff --git a/jupyterlab/run.sh b/jupyterlab/run.sh index db9ab513..1cae1db6 100755 --- a/jupyterlab/run.sh +++ b/jupyterlab/run.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -if [ -n "$BASE_URL" ] +if [ -n "${BASE_URL}" ] then BASE_URL="--ServerApp.base_url=${BASE_URL}" fi @@ -25,8 +25,8 @@ else printf "%s\n\n" "🥳 jupyterlab is already installed" fi -echo "👷 Starting jupyterlab in background..." -echo "check logs at ${LOG_PATH}" +printf "👷 Starting jupyterlab in background..." +printf "check logs at ${LOG_PATH}" $HOME/.local/bin/jupyter-lab --no-browser \ "$BASE_URL" \ --ServerApp.ip='*' \ From e21a5bc56e03ab78ba75b9f31af68f66a13fced7 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 15 Oct 2024 22:54:00 +0500 Subject: [PATCH 05/13] Update jupyterlab/main.tf --- jupyterlab/main.tf | 9 --------- 1 file changed, 9 deletions(-) diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf index 239c5aa1..d50ed023 100644 --- a/jupyterlab/main.tf +++ b/jupyterlab/main.tf @@ -72,12 +72,3 @@ resource "coder_app" "jupyterlab" { 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 e42b57cd0f94367b7958b18a8465a0c3232f66a1 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 15 Oct 2024 22:56:16 +0500 Subject: [PATCH 06/13] Update main.tf --- jupyterlab/main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf index d50ed023..08c93a06 100644 --- a/jupyterlab/main.tf +++ b/jupyterlab/main.tf @@ -72,3 +72,4 @@ resource "coder_app" "jupyterlab" { subdomain = var.subdomain share = var.share order = var.order +} From d152fb5fab9b487e2e701f1e76a1e8d8e23be959 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 15 Oct 2024 22:57:19 +0500 Subject: [PATCH 07/13] Update jupyterlab/main.tf --- jupyterlab/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf index 08c93a06..88933ff8 100644 --- a/jupyterlab/main.tf +++ b/jupyterlab/main.tf @@ -67,7 +67,7 @@ resource "coder_app" "jupyterlab" { agent_id = var.agent_id slug = "jupyterlab" # sync with the usage in URL display_name = "JupyterLab" - url = var.subdomain ? "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab" : "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 = var.subdomain share = var.share From 329f9eb407da259071cad329891804741ae8de60 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 15 Oct 2024 23:05:14 +0500 Subject: [PATCH 08/13] bun:fmt --- jupyterlab/run.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/jupyterlab/run.sh b/jupyterlab/run.sh index 1cae1db6..e901a2d6 100755 --- a/jupyterlab/run.sh +++ b/jupyterlab/run.sh @@ -1,8 +1,7 @@ #!/usr/bin/env sh -if [ -n "${BASE_URL}" ] -then - BASE_URL="--ServerApp.base_url=${BASE_URL}" +if [ -n "${BASE_URL}" ]; then + BASE_URL="--ServerApp.base_url=${BASE_URL}" fi BOLD='\033[0;1m' @@ -28,9 +27,9 @@ fi printf "👷 Starting jupyterlab in background..." printf "check logs at ${LOG_PATH}" $HOME/.local/bin/jupyter-lab --no-browser \ - "$BASE_URL" \ - --ServerApp.ip='*' \ - --ServerApp.port="${PORT}" \ - --ServerApp.token='' \ - --ServerApp.password='' \ - > "${LOG_PATH}" 2>&1 & + "$BASE_URL" \ + --ServerApp.ip='*' \ + --ServerApp.port="${PORT}" \ + --ServerApp.token='' \ + --ServerApp.password='' \ + > "${LOG_PATH}" 2>&1 & From e960fdc4122372892f2ff5111f4a161653fcd817 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 15 Oct 2024 23:06:50 +0500 Subject: [PATCH 09/13] bump version --- jupyterlab/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyterlab/README.md b/jupyterlab/README.md index ed73b56e..f8d39b70 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.20" agent_id = coder_agent.example.id } ``` From c5c569e9138b174dbc3a544980af1a43531e5001 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 21 Oct 2024 08:05:32 +0500 Subject: [PATCH 10/13] Update jupyterlab/main.tf Co-authored-by: Asher --- jupyterlab/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf index 88933ff8..e893f539 100644 --- a/jupyterlab/main.tf +++ b/jupyterlab/main.tf @@ -58,7 +58,7 @@ 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" : "" + BASE_URL : var.subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab"" }) run_on_start = true } From 0dcba9b08c6b99541fbd265dc008b0e839e822c7 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 21 Oct 2024 08:06:58 +0500 Subject: [PATCH 11/13] Update jupyterlab/main.tf Co-authored-by: Asher --- jupyterlab/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf index e893f539..27f514b7 100644 --- a/jupyterlab/main.tf +++ b/jupyterlab/main.tf @@ -41,7 +41,7 @@ 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." + description = "Determines whether JupyterLab will be accessed via its own subdomain or whether it will be accessed via a path on Coder." default = true } From 3d1898417e88158622b7f3ef02880a48a1582cd7 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 21 Oct 2024 09:08:38 +0500 Subject: [PATCH 12/13] rename FLAG Signed-off-by: Muhammad Atif Ali --- jupyterlab/main.tf | 2 +- jupyterlab/run.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf index 27f514b7..d66edb1c 100644 --- a/jupyterlab/main.tf +++ b/jupyterlab/main.tf @@ -58,7 +58,7 @@ 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"" + BASE_URL : var.subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab" }) run_on_start = true } diff --git a/jupyterlab/run.sh b/jupyterlab/run.sh index e901a2d6..aff21b72 100755 --- a/jupyterlab/run.sh +++ b/jupyterlab/run.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh if [ -n "${BASE_URL}" ]; then - BASE_URL="--ServerApp.base_url=${BASE_URL}" + BASE_URL_FLAG="--ServerApp.base_url=${BASE_URL}" fi BOLD='\033[0;1m' @@ -27,7 +27,7 @@ fi printf "👷 Starting jupyterlab in background..." printf "check logs at ${LOG_PATH}" $HOME/.local/bin/jupyter-lab --no-browser \ - "$BASE_URL" \ + "$BASE_URL_FLAG" \ --ServerApp.ip='*' \ --ServerApp.port="${PORT}" \ --ServerApp.token='' \ From 8fc7ed55f7965883b0401e1aec13741f36b1eeaa Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 21 Oct 2024 11:07:34 +0500 Subject: [PATCH 13/13] Update README.md --- jupyterlab/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyterlab/README.md b/jupyterlab/README.md index f8d39b70..52d5a502 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.20" + version = "1.0.22" agent_id = coder_agent.example.id } ```