add JupyterLab module (#39)

pull/44/head
Muhammad Atif Ali 2 years ago committed by GitHub
parent 2e829b19a4
commit 1bff483ad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

@ -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
}
```

@ -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"
}

@ -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}!"

@ -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

Loading…
Cancel
Save