From 66cf2e54557afa812e92f7665fdbd915b216e4a3 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Sun, 24 Sep 2023 17:07:35 +0300 Subject: [PATCH] boilerplate --- jupyterlab/README.md | 64 +++++++++++++++++++++++++++ jupyterlab/main.tf | 101 +++++++++++++++++++++++++++++++++++++++++++ jupyterlab/run.sh | 17 ++++++++ 3 files changed, 182 insertions(+) create mode 100644 jupyterlab/README.md create mode 100644 jupyterlab/main.tf create mode 100644 jupyterlab/run.sh diff --git a/jupyterlab/README.md b/jupyterlab/README.md new file mode 100644 index 0000000..5e64e6f --- /dev/null +++ b/jupyterlab/README.md @@ -0,0 +1,64 @@ +--- +display_name: jupyterlab +description: Describe what this module does +icon: ../.icons/.svg +maintainer_github: GITHUB_USERNAME +verified: false +tags: [community] +--- + +# jupyterlab + +<-- Describes what this module does --> + +<-- Add a screencast or screenshot here --> + +```hcl +module "jupyterlab" { + source = "https://registry.coder.com/modules/jupyterlab" +} +``` + +## Examples + +### Example 1 + +Install the Dracula theme from [OpenVSX](https://open-vsx.org/): + +```hcl +module "jupyterlab" { + source = "https://registry.coder.com/modules/jupyterlab" + agent_id = coder_agent.example.id + extensions = [ + "dracula-theme.theme-dracula" + ] +} +``` + +Enter the `.` into the extensions array and code-server will automatically install on start. + +### Example 2 + +Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarted/settings#_settingsjson) file: + +```hcl +module "jupyterlab" { + source = "https://registry.coder.com/modules/jupyterlab" + agent_id = coder_agent.example.id + extensions = [ "dracula-theme.theme-dracula" ] + settings = { + "workbench.colorTheme" = "Dracula" + } +} +``` + +### Example 3 + +Run code-server in the background, don't fetch it from GitHub: + +```hcl +module "jupyterlab" { + source = "https://registry.coder.com/modules/jupyterlab" + agent_id = coder_agent.example.id + offline = true +} diff --git a/jupyterlab/main.tf b/jupyterlab/main.tf new file mode 100644 index 0000000..cfd2a59 --- /dev/null +++ b/jupyterlab/main.tf @@ -0,0 +1,101 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + coder = { + source = "coder/coder" + version = ">= 0.12" + } + } +} + +locals { + # A built-in icon like "/icon/code.svg" or a full URL of icon + icon_url = "https://raw.githubusercontent.com/coder/coder/main/site/static/icon/code.svg" + # a map of all possible values + options = { + "Option 1" = { + "name" = "Option 1", + "value" = "1" + "icon" = "/emojis/1.png" + } + "Option 2" = { + "name" = "Option 2", + "value" = "2" + "icon" = "/emojis/2.png" + } + } +} + +# 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 +} + +variable "mutable" { + type = bool + description = "Whether the parameter is mutable." + default = true +} +# Add other variables here + + +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, + }) + 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 = loocal.icon_url + subdomain = false + share = "owner" + + # Remove if the app does not have a healthcheck endpoint + healthcheck { + url = "http://localhost:${var.port}/healthz" + interval = 5 + threshold = 6 + } +} + +data "coder_parameter" "jupyterlab" { + type = "list(string)" + name = "jupyterlab" + display_name = "jupyterlab" + icon = local.icon_url + mutable = var.mutable + default = local.options["Option 1"]["value"] + + dynamic "option" { + for_each = local.options + content { + icon = option.value.icon + name = option.value.name + value = option.value.value + } + } +} + diff --git a/jupyterlab/run.sh b/jupyterlab/run.sh new file mode 100644 index 0000000..88af7ad --- /dev/null +++ b/jupyterlab/run.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +echo "Instalalting ${MODULE_NAME}..." +# Add code here +# Use varibles from the templatefile function in main.tf +# e.g. LOG_PATH, PORT, etc. + +echo "Installation comlete!" + +echo "Starting ${MODULE_NAME}..." +# Start the app in here +# 1. Use & to run it in background +# 2. redirct stdout and stderr to log files + +./app >${LOG_PATH} 2>&1 & + +echo "Sample app started!"