Refactor multiple modules for improved flexibility

- Transition modules to use slug and agent_name variables for custom configurations.
- Update Terraform resources to dynamically generate URLs and paths.
- Enhance form handling logic in Devolutions patch script.
This commit is contained in:
Muhammad Atif Ali
2024-10-22 10:43:37 +05:00
parent ce5a5b383a
commit 0b2bc1de9e
16 changed files with 441 additions and 279 deletions

View File

@@ -11,12 +11,36 @@ tags: [jupyter, helper, ide, web]
A module that adds JupyterLab in your Coder template.
![JupyterLab](../.images/jupyterlab.png)
```tf
module "jupyterlab" {
source = "registry.coder.com/modules/jupyterlab/coder"
version = "1.0.22"
version = "1.0.23"
agent_id = coder_agent.example.id
}
```
![JupyterLab](../.images/jupyterlab.png)
## Examples
### Serve on a subpath (no wildcard subdomain)
```tf
module "jupyterlab" {
source = "registry.coder.com/modules/jupyterlab/coder"
version = "1.0.23"
agent_id = coder_agent.example.id
subdomain = false
}
```
### Serve on a subpath with a specific agent name (multiple agents)
```tf
module "jupyterlab" {
source = "registry.coder.com/modules/jupyterlab/coder"
version = "1.0.23"
agent_id = coder_agent.example.id
agent_name = "main"
}
```

View File

@@ -41,7 +41,10 @@ variable "share" {
variable "subdomain" {
type = bool
description = "Determines whether JupyterLab will be accessed via its own subdomain or whether it will be accessed via a path on Coder."
description = <<-EOT
Determines whether the app will be accessed via it's own subdomain or whether it will be accessed via a path on Coder.
If wildcards have not been setup by the administrator then apps with "subdomain" set to true will not be accessible.
EOT
default = true
}
@@ -51,6 +54,18 @@ variable "order" {
default = null
}
variable "agent_name" {
type = string
description = "The name of the coder_agent resource. (Only required if subdomain is false and the template uses multiple agents.)"
default = null
}
variable "slug" {
type = string
description = "The slug of the coder_app resource."
default = "jupyterlab"
}
resource "coder_script" "jupyterlab" {
agent_id = var.agent_id
display_name = "jupyterlab"
@@ -58,18 +73,24 @@ resource "coder_script" "jupyterlab" {
script = templatefile("${path.module}/run.sh", {
LOG_PATH : var.log_path,
PORT : var.port
BASE_URL : var.subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab"
BASE_URL : local.server_base_path
})
run_on_start = true
}
resource "coder_app" "jupyterlab" {
agent_id = var.agent_id
slug = "jupyterlab" # sync with the usage in URL
slug = var.slug
display_name = "JupyterLab"
url = var.subdomain ? "http://localhost:${var.port}" : "http://localhost:${var.port}/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}/apps/jupyterlab"
url = local.url
icon = "/icon/jupyter.svg"
subdomain = var.subdomain
share = var.share
order = var.order
}
locals {
server_base_path = var.subdomain ? "" : format(var.agent_name != null ? "/@%s/%s.%s/apps/%s" : "/@%s/%s/apps/%s", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.agent_name, var.slug)
url = "http://localhost:${var.port}${local.server_base_path}"
healthcheck_url = "http://localhost:${var.port}${local.server_base_path}/api"
}