diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c0a9c0fa..60b1260b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,6 +47,7 @@ You can test a module locally by updating the source as follows ```tf module "example" { source = "git::https://github.com//.git//?ref=" + # You may need to remove the 'version' field, it is incompatible with some sources. } ``` diff --git a/vscode-web/README.md b/vscode-web/README.md index 821d5182..8b5fa688 100644 --- a/vscode-web/README.md +++ b/vscode-web/README.md @@ -14,7 +14,7 @@ Automatically install [Visual Studio Code Server](https://code.visualstudio.com/ ```tf module "vscode-web" { source = "registry.coder.com/modules/vscode-web/coder" - version = "1.0.20" + version = "1.0.22" agent_id = coder_agent.example.id accept_license = true } @@ -29,7 +29,7 @@ module "vscode-web" { ```tf module "vscode-web" { source = "registry.coder.com/modules/vscode-web/coder" - version = "1.0.20" + version = "1.0.22" agent_id = coder_agent.example.id install_prefix = "/home/coder/.vscode-web" folder = "/home/coder" @@ -42,7 +42,7 @@ module "vscode-web" { ```tf module "vscode-web" { source = "registry.coder.com/modules/vscode-web/coder" - version = "1.0.20" + version = "1.0.22" agent_id = coder_agent.example.id extensions = ["github.copilot", "ms-python.python", "ms-toolsai.jupyter"] accept_license = true @@ -56,7 +56,7 @@ Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarte ```tf module "vscode-web" { source = "registry.coder.com/modules/vscode-web/coder" - version = "1.0.20" + version = "1.0.22" agent_id = coder_agent.example.id extensions = ["dracula-theme.theme-dracula"] settings = { diff --git a/vscode-web/main.tf b/vscode-web/main.tf index 084f8306..207450e5 100644 --- a/vscode-web/main.tf +++ b/vscode-web/main.tf @@ -121,6 +121,18 @@ variable "auto_install_extensions" { default = false } +variable "subdomain" { + type = bool + 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 +} + +data "coder_workspace_owner" "me" {} +data "coder_workspace" "me" {} + resource "coder_script" "vscode-web" { agent_id = var.agent_id display_name = "VS Code Web" @@ -138,6 +150,7 @@ resource "coder_script" "vscode-web" { EXTENSIONS_DIR : var.extensions_dir, FOLDER : var.folder, AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions, + SERVER_BASE_PATH : local.server_base_path, }) run_on_start = true @@ -158,15 +171,21 @@ resource "coder_app" "vscode-web" { agent_id = var.agent_id slug = var.slug display_name = var.display_name - url = var.folder == "" ? "http://localhost:${var.port}" : "http://localhost:${var.port}?folder=${var.folder}" + url = local.url icon = "/icon/code.svg" - subdomain = true + subdomain = var.subdomain share = var.share order = var.order healthcheck { - url = "http://localhost:${var.port}/healthz" + url = local.healthcheck_url interval = 5 threshold = 6 } } + +locals { + server_base_path = var.subdomain ? "" : format("/@%s/%s/apps/%s/", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.slug) + url = var.folder == "" ? "http://localhost:${var.port}${local.server_base_path}" : "http://localhost:${var.port}${local.server_base_path}?folder=${var.folder}" + healthcheck_url = var.subdomain ? "http://localhost:${var.port}/healthz" : "http://localhost:${var.port}${local.server_base_path}/healthz" +} diff --git a/vscode-web/run.sh b/vscode-web/run.sh index ecfad68b..1738364e 100755 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -10,10 +10,16 @@ if [ -n "${EXTENSIONS_DIR}" ]; then EXTENSION_ARG="--extensions-dir=${EXTENSIONS_DIR}" fi +# Set extension directory +SERVER_BASE_PATH_ARG="" +if [ -n "${SERVER_BASE_PATH}" ]; then + SERVER_BASE_PATH_ARG="--server-base-path=${SERVER_BASE_PATH}" +fi + run_vscode_web() { - echo "👷 Running $VSCODE_WEB serve-local $EXTENSION_ARG --port ${PORT} --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} in the background..." + echo "👷 Running $VSCODE_WEB serve-local $EXTENSION_ARG $SERVER_BASE_PATH_ARG --port ${PORT} --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} in the background..." echo "Check logs at ${LOG_PATH}!" - "$VSCODE_WEB" serve-local "$EXTENSION_ARG" --port "${PORT}" --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 & + "$VSCODE_WEB" serve-local "$EXTENSION_ARG" "$SERVER_BASE_PATH_ARG" --port "${PORT}" --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 & } # Check if the settings file exists...