Skip to content

Commit 1b147ae

Browse files
framctrmatifalicode-asher
authored
feat(jupyterlab): add support for subdomain=false (#316)
Co-authored-by: Muhammad Atif Ali <[email protected]> Co-authored-by: Asher <[email protected]>
1 parent 7992d9d commit 1b147ae

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

jupyterlab/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A module that adds JupyterLab in your Coder template.
1616
```tf
1717
module "jupyterlab" {
1818
source = "registry.coder.com/modules/jupyterlab/coder"
19-
version = "1.0.19"
19+
version = "1.0.22"
2020
agent_id = coder_agent.example.id
2121
}
2222
```

jupyterlab/main.tf

+13-3
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 its 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,18 @@ 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 ? "" : "/@${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 the usage in URL
5969
display_name = "JupyterLab"
60-
url = "http://localhost:${var.port}"
70+
url = var.subdomain ? "http://localhost:${var.port}" : "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab"
6171
icon = "/icon/jupyter.svg"
62-
subdomain = true
72+
subdomain = var.subdomain
6373
share = var.share
6474
order = var.order
6575
}

jupyterlab/run.sh

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env sh
22

3+
if [ -n "${BASE_URL}" ]; then
4+
BASE_URL_FLAG="--ServerApp.base_url=${BASE_URL}"
5+
fi
6+
37
BOLD='\033[0;1m'
48

59
printf "$${BOLD}Installing jupyterlab!\n"
@@ -15,11 +19,17 @@ if ! command -v jupyterlab > /dev/null 2>&1; then
1519
fi
1620
# install jupyterlab
1721
pipx install -q jupyterlab
18-
echo "🥳 jupyterlab has been installed\n\n"
22+
printf "%s\n\n" "🥳 jupyterlab has been installed"
1923
else
20-
echo "🥳 jupyterlab is already installed\n\n"
24+
printf "%s\n\n" "🥳 jupyterlab is already installed"
2125
fi
2226

23-
echo "👷 Starting jupyterlab in background..."
24-
echo "check logs at ${LOG_PATH}"
25-
$HOME/.local/bin/jupyter-lab --ServerApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 &
27+
printf "👷 Starting jupyterlab in background..."
28+
printf "check logs at ${LOG_PATH}"
29+
$HOME/.local/bin/jupyter-lab --no-browser \
30+
"$BASE_URL_FLAG" \
31+
--ServerApp.ip='*' \
32+
--ServerApp.port="${PORT}" \
33+
--ServerApp.token='' \
34+
--ServerApp.password='' \
35+
> "${LOG_PATH}" 2>&1 &

0 commit comments

Comments
 (0)