feat: Add support to the vscode-web module for loading workspaces at startup (#349)
This commit is contained in:
parent
29e5307121
commit
a69accbad5
@ -14,7 +14,7 @@ Automatically install [Visual Studio Code Server](https://code.visualstudio.com/
|
|||||||
module "vscode-web" {
|
module "vscode-web" {
|
||||||
count = data.coder_workspace.me.start_count
|
count = data.coder_workspace.me.start_count
|
||||||
source = "registry.coder.com/coder/vscode-web/coder"
|
source = "registry.coder.com/coder/vscode-web/coder"
|
||||||
version = "1.3.1"
|
version = "1.4.0"
|
||||||
agent_id = coder_agent.example.id
|
agent_id = coder_agent.example.id
|
||||||
accept_license = true
|
accept_license = true
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ module "vscode-web" {
|
|||||||
module "vscode-web" {
|
module "vscode-web" {
|
||||||
count = data.coder_workspace.me.start_count
|
count = data.coder_workspace.me.start_count
|
||||||
source = "registry.coder.com/coder/vscode-web/coder"
|
source = "registry.coder.com/coder/vscode-web/coder"
|
||||||
version = "1.3.1"
|
version = "1.4.0"
|
||||||
agent_id = coder_agent.example.id
|
agent_id = coder_agent.example.id
|
||||||
install_prefix = "/home/coder/.vscode-web"
|
install_prefix = "/home/coder/.vscode-web"
|
||||||
folder = "/home/coder"
|
folder = "/home/coder"
|
||||||
@ -44,7 +44,7 @@ module "vscode-web" {
|
|||||||
module "vscode-web" {
|
module "vscode-web" {
|
||||||
count = data.coder_workspace.me.start_count
|
count = data.coder_workspace.me.start_count
|
||||||
source = "registry.coder.com/coder/vscode-web/coder"
|
source = "registry.coder.com/coder/vscode-web/coder"
|
||||||
version = "1.3.1"
|
version = "1.4.0"
|
||||||
agent_id = coder_agent.example.id
|
agent_id = coder_agent.example.id
|
||||||
extensions = ["github.copilot", "ms-python.python", "ms-toolsai.jupyter"]
|
extensions = ["github.copilot", "ms-python.python", "ms-toolsai.jupyter"]
|
||||||
accept_license = true
|
accept_license = true
|
||||||
@ -59,7 +59,7 @@ Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarte
|
|||||||
module "vscode-web" {
|
module "vscode-web" {
|
||||||
count = data.coder_workspace.me.start_count
|
count = data.coder_workspace.me.start_count
|
||||||
source = "registry.coder.com/coder/vscode-web/coder"
|
source = "registry.coder.com/coder/vscode-web/coder"
|
||||||
version = "1.3.1"
|
version = "1.4.0"
|
||||||
agent_id = coder_agent.example.id
|
agent_id = coder_agent.example.id
|
||||||
extensions = ["dracula-theme.theme-dracula"]
|
extensions = ["dracula-theme.theme-dracula"]
|
||||||
settings = {
|
settings = {
|
||||||
@ -77,9 +77,24 @@ By default, this module installs the latest. To pin a specific version, retrieve
|
|||||||
module "vscode-web" {
|
module "vscode-web" {
|
||||||
count = data.coder_workspace.me.start_count
|
count = data.coder_workspace.me.start_count
|
||||||
source = "registry.coder.com/coder/vscode-web/coder"
|
source = "registry.coder.com/coder/vscode-web/coder"
|
||||||
version = "1.3.1"
|
version = "1.4.0"
|
||||||
agent_id = coder_agent.example.id
|
agent_id = coder_agent.example.id
|
||||||
commit_id = "e54c774e0add60467559eb0d1e229c6452cf8447"
|
commit_id = "e54c774e0add60467559eb0d1e229c6452cf8447"
|
||||||
accept_license = true
|
accept_license = true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Open an existing workspace on startup
|
||||||
|
|
||||||
|
To open an existing workspace on startup the `workspace` parameter can be used to represent a path on disk to a `code-workspace` file.
|
||||||
|
Note: Either `workspace` or `folder` can be used, but not both simultaneously. The `code-workspace` file must already be present on disk.
|
||||||
|
|
||||||
|
```tf
|
||||||
|
module "vscode-web" {
|
||||||
|
count = data.coder_workspace.me.start_count
|
||||||
|
source = "registry.coder.com/coder/vscode-web/coder"
|
||||||
|
version = "1.4.0"
|
||||||
|
agent_id = coder_agent.example.id
|
||||||
|
workspace = "/home/coder/coder.code-workspace"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
@ -158,6 +158,12 @@ variable "platform" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "workspace" {
|
||||||
|
type = string
|
||||||
|
description = "Path to a .code-workspace file to open in vscode-web."
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
||||||
data "coder_workspace_owner" "me" {}
|
data "coder_workspace_owner" "me" {}
|
||||||
data "coder_workspace" "me" {}
|
data "coder_workspace" "me" {}
|
||||||
|
|
||||||
@ -178,6 +184,7 @@ resource "coder_script" "vscode-web" {
|
|||||||
DISABLE_TRUST : var.disable_trust,
|
DISABLE_TRUST : var.disable_trust,
|
||||||
EXTENSIONS_DIR : var.extensions_dir,
|
EXTENSIONS_DIR : var.extensions_dir,
|
||||||
FOLDER : var.folder,
|
FOLDER : var.folder,
|
||||||
|
WORKSPACE : var.workspace,
|
||||||
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
|
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
|
||||||
SERVER_BASE_PATH : local.server_base_path,
|
SERVER_BASE_PATH : local.server_base_path,
|
||||||
COMMIT_ID : var.commit_id,
|
COMMIT_ID : var.commit_id,
|
||||||
@ -195,6 +202,11 @@ resource "coder_script" "vscode-web" {
|
|||||||
condition = !var.offline || !var.use_cached
|
condition = !var.offline || !var.use_cached
|
||||||
error_message = "Offline and Use Cached can not be used together"
|
error_message = "Offline and Use Cached can not be used together"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
precondition {
|
||||||
|
condition = (var.workspace == "" || var.folder == "")
|
||||||
|
error_message = "Set only one of `workspace` or `folder`."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,6 +230,12 @@ resource "coder_app" "vscode-web" {
|
|||||||
|
|
||||||
locals {
|
locals {
|
||||||
server_base_path = var.subdomain ? "" : format("/@%s/%s/apps/%s/", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.slug)
|
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}"
|
url = (
|
||||||
healthcheck_url = var.subdomain ? "http://localhost:${var.port}/healthz" : "http://localhost:${var.port}${local.server_base_path}/healthz"
|
var.workspace != "" ?
|
||||||
|
"http://localhost:${var.port}${local.server_base_path}?workspace=${urlencode(var.workspace)}" :
|
||||||
|
var.folder != "" ?
|
||||||
|
"http://localhost:${var.port}${local.server_base_path}?folder=${urlencode(var.folder)}" :
|
||||||
|
"http://localhost:${var.port}${local.server_base_path}"
|
||||||
|
)
|
||||||
|
healthcheck_url = var.subdomain ? "http://localhost:${var.port}/healthz" : "http://localhost:${var.port}${local.server_base_path}/healthz"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,18 +109,27 @@ if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then
|
|||||||
if ! command -v jq > /dev/null; then
|
if ! command -v jq > /dev/null; then
|
||||||
echo "jq is required to install extensions from a workspace file."
|
echo "jq is required to install extensions from a workspace file."
|
||||||
else
|
else
|
||||||
WORKSPACE_DIR="$HOME"
|
# Prefer WORKSPACE if set and points to a file
|
||||||
if [ -n "${FOLDER}" ]; then
|
if [ -n "${WORKSPACE}" ] && [ -f "${WORKSPACE}" ]; then
|
||||||
WORKSPACE_DIR="${FOLDER}"
|
printf "🧩 Installing extensions from %s...\n" "${WORKSPACE}"
|
||||||
fi
|
# Strip single-line comments then parse .extensions.recommendations[]
|
||||||
|
extensions=$(sed 's|//.*||g' "${WORKSPACE}" | jq -r '(.extensions.recommendations // [])[]')
|
||||||
if [ -f "$WORKSPACE_DIR/.vscode/extensions.json" ]; then
|
|
||||||
printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR"
|
|
||||||
# Use sed to remove single-line comments before parsing with jq
|
|
||||||
extensions=$(sed 's|//.*||g' "$WORKSPACE_DIR"/.vscode/extensions.json | jq -r '.recommendations[]')
|
|
||||||
for extension in $extensions; do
|
for extension in $extensions; do
|
||||||
$VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force
|
$VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force
|
||||||
done
|
done
|
||||||
|
else
|
||||||
|
# Fallback to folder-based .vscode/extensions.json (existing behavior)
|
||||||
|
WORKSPACE_DIR="$HOME"
|
||||||
|
if [ -n "${FOLDER}" ]; then
|
||||||
|
WORKSPACE_DIR="${FOLDER}"
|
||||||
|
fi
|
||||||
|
if [ -f "$WORKSPACE_DIR/.vscode/extensions.json" ]; then
|
||||||
|
printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR"
|
||||||
|
extensions=$(sed 's|//.*||g' "$WORKSPACE_DIR/.vscode/extensions.json" | jq -r '.recommendations[]')
|
||||||
|
for extension in $extensions; do
|
||||||
|
$VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force
|
||||||
|
done
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user