diff --git a/.images/jupyterlab.webp b/.images/jupyterlab.webp new file mode 100644 index 0000000..d87f7c0 Binary files /dev/null and b/.images/jupyterlab.webp differ diff --git a/.sample/run.sh b/.sample/run.sh old mode 100644 new mode 100755 diff --git a/jupyterlab/README.md b/jupyterlab/README.md new file mode 100644 index 0000000..ca3f979 --- /dev/null +++ b/jupyterlab/README.md @@ -0,0 +1,21 @@ +--- +display_name: JupyterLab +description: A module that adds JupyterLab in your Coder template. +icon: ../.icons/jupyter.svg +maintainer_github: coder +verified: true +tags: [jupyter, helper] +--- + +# JupyterLab + +A module that adds JupyterLab in your Coder template. + +![JupyterLab](../.images/jupyterlab.webp) + +```hcl +module "jupyterlab" { + source = "https://registry.coder.com/modules/jupyterlab" + agent_id = coder_agent.example.id +} +``` diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf new file mode 100644 index 0000000..e95c0a2 --- /dev/null +++ b/jupyterlab/main.tf @@ -0,0 +1,54 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + coder = { + source = "coder/coder" + version = ">= 0.12" + } + } +} + +locals { + icon_url = "/icon/jupyter.svg" +} + +# Add required variables for your modules and remove any unneeded variables +variable "agent_id" { + type = string + description = "The ID of a Coder agent." +} + +variable "log_path" { + type = string + description = "The path to log jupyterlab to." + default = "/tmp/jupyterlab.log" +} + +variable "port" { + type = number + description = "The port to run jupyterlab on." + default = 19999 +} + +resource "coder_script" "jupyterlab" { + agent_id = var.agent_id + display_name = "jupyterlab" + icon = local.icon_url + script = templatefile("${path.module}/run.sh", { + LOG_PATH : var.log_path, + PORT : var.port + }) + run_on_start = true + run_on_stopt = false +} + +resource "coder_app" "jupyterlab" { + agent_id = var.agent_id + slug = "jupyterlab" + display_name = "JupyterLab" + url = "http://localhost:${var.port}" + icon = local.icon_url + subdomain = true + share = "owner" +} diff --git a/jupyterlab/run.sh b/jupyterlab/run.sh new file mode 100755 index 0000000..a3a484a --- /dev/null +++ b/jupyterlab/run.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env sh + +echo "Instalalting ${MODULE_NAME}..." + +# check if jupyterlab is installed +if ! command -v jupyterlab &> /dev/null then + # install jupyterlab + # check if python3 pip is installed + if ! command -v pip3 &> /dev/null then + echo "pip3 is not installed" + echo "Please install pip3 and try again" + exit 1 + fi + pip3 install jupyterlab + echo "jupyterlab installed!" +fi + +echo "Starting ${MODULE_NAME}..." + +$HOME/.local/bin/jupyter lab --no-browser --LabApp.token='' --LabApp.password='' >${LOG_PATH} 2>&1 & + +echo "Started ${MODULE_NAME}!" diff --git a/new.sh b/new.sh index 06fcc6c..ea80ffe 100755 --- a/new.sh +++ b/new.sh @@ -35,3 +35,6 @@ else sed -i "s/MODULE_NAME/${MODULE_NAME}/g" main.tf sed -i "s/MODULE_NAME/${MODULE_NAME}/g" README.md fi + +# Make run.sh executable +chmod +x run.sh