Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jupyterlab): add support for subdomain=false #316

Merged
merged 20 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions jupyterlab/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
matifali marked this conversation as resolved.
Show resolved Hide resolved
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)."
Expand All @@ -49,17 +58,26 @@ 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" : ""
matifali marked this conversation as resolved.
Show resolved Hide resolved
matifali marked this conversation as resolved.
Show resolved Hide resolved
})
run_on_start = true
}

resource "coder_app" "jupyterlab" {
agent_id = var.agent_id
slug = "jupyterlab"
slug = "jupyterlab" # sync with with end of subdomain URL
framctr marked this conversation as resolved.
Show resolved Hide resolved
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}"
matifali marked this conversation as resolved.
Show resolved Hide resolved
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
}
}
matifali marked this conversation as resolved.
Show resolved Hide resolved
matifali marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 14 additions & 3 deletions jupyterlab/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env sh

if [ -n "$BASE_URL" ]
framctr marked this conversation as resolved.
Show resolved Hide resolved
then
BASE_URL="--ServerApp.base_url=${BASE_URL}"
fi

BOLD='\033[0;1m'

printf "$${BOLD}Installing jupyterlab!\n"
Expand All @@ -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"
matifali marked this conversation as resolved.
Show resolved Hide resolved
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}"
framctr marked this conversation as resolved.
Show resolved Hide resolved
$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 &
Loading