Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 6936e8e

Browse files
authored
Merge branch 'main' into jupyterlab-subdomain-1
2 parents 9476274 + e09b7a1 commit 6936e8e

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

jupyterlab/main.tf

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ terraform {
99
}
1010
}
1111

12+
data "coder_workspace" "me" {}
13+
data "coder_workspace_owner" "me" {}
14+
1215
# Add required variables for your modules and remove any unneeded variables
1316
variable "agent_id" {
1417
type = string
@@ -36,6 +39,12 @@ variable "share" {
3639
}
3740
}
3841

42+
variable "subdomain" {
43+
type = bool
44+
description = "Determines whether JupyterLab will be accessed via it's own subdomain or whether it will be accessed via a path on Coder."
45+
default = true
46+
}
47+
3948
variable "order" {
4049
type = number
4150
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,26 @@ resource "coder_script" "jupyterlab" {
4958
script = templatefile("${path.module}/run.sh", {
5059
LOG_PATH : var.log_path,
5160
PORT : var.port
61+
BASE_URL : var.subdomain ? "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab" : ""
5262
})
5363
run_on_start = true
5464
}
5565

5666
resource "coder_app" "jupyterlab" {
5767
agent_id = var.agent_id
58-
slug = "jupyterlab"
68+
slug = "jupyterlab" # sync with with end of subdomain URL
5969
display_name = "JupyterLab"
60-
url = "http://localhost:${var.port}"
70+
url = var.subdomain ? "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab" : "http://localhost:${var.port}"
6171
icon = "/icon/jupyter.svg"
62-
subdomain = true
72+
subdomain = var.subdomain
6373
share = var.share
6474
order = var.order
65-
}
75+
76+
dynamic "healthcheck" {
77+
for_each = var.subdomain ? toset([true]) : toset([])
78+
content {
79+
url = "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab"
80+
interval = 6
81+
threshold = 10
82+
}
83+
}

jupyterlab/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
if [ -n "$BASE_URL" ]
44
then
5-
BASE_URL="ServerApp.base_url=${BASE_URL}"
5+
BASE_URL="--ServerApp.base_url=${BASE_URL}"
66
fi
77

88
BOLD='\033[0;1m'
@@ -28,7 +28,7 @@ fi
2828
echo "👷 Starting jupyterlab in background..."
2929
echo "check logs at ${LOG_PATH}"
3030
$HOME/.local/bin/jupyter-lab --no-browser \
31-
--ServerApp.base_url="${BASE_URL}" \
31+
"$BASE_URL" \
3232
--ServerApp.ip='*' \
3333
--ServerApp.port="${PORT}" \
3434
--ServerApp.token='' \

0 commit comments

Comments
 (0)