Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 4b04d18

Browse files
matifalimafredri
andauthored
Add extensions support for vscode-web (#154)
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
1 parent ee53ca0 commit 4b04d18

File tree

4 files changed

+75
-80
lines changed

4 files changed

+75
-80
lines changed

vscode-web/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ tags: [helper, ide, vscode, web]
99

1010
# VS Code Web
1111

12-
Automatically install [Visual Studio Code Server](https://code.visualstudio.com/docs/remote/vscode-server) in a workspace using the [VS Code CLI](https://code.visualstudio.com/docs/editor/command-line) and create an app to access it via the dashboard.
12+
Automatically install [Visual Studio Code Server](https://code.visualstudio.com/docs/remote/vscode-server) in a workspace and create an app to access it via the dashboard.
1313

1414
```tf
1515
module "vscode-web" {
@@ -31,8 +31,20 @@ module "vscode-web" {
3131
source = "registry.coder.com/modules/vscode-web/coder"
3232
version = "1.0.3"
3333
agent_id = coder_agent.example.id
34-
install_dir = "/home/coder/.vscode-web"
34+
install_prefix = "/home/coder/.vscode-web"
3535
folder = "/home/coder"
3636
accept_license = true
3737
}
3838
```
39+
40+
### Install Extensions
41+
42+
```tf
43+
module "vscode-web" {
44+
source = "registry.coder.com/modules/vscode-web/coder"
45+
version = "1.0.2"
46+
agent_id = coder_agent.example.id
47+
extensions = ["github.copilot", "ms-python.python", "ms-toolsai.jupyter"]
48+
accept_license = true
49+
}
50+
```

vscode-web/main.test.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

vscode-web/main.tf

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,48 @@ variable "log_path" {
5353
default = "/tmp/vscode-web.log"
5454
}
5555

56-
variable "install_dir" {
56+
variable "install_prefix" {
5757
type = string
58-
description = "The directory to install VS Code CLI"
59-
default = "/tmp/vscode-cli"
58+
description = "The prefix to install vscode-web to."
59+
default = "/tmp/vscode-web"
60+
}
61+
62+
variable "extensions" {
63+
type = list(string)
64+
description = "A list of extensions to install."
65+
default = []
6066
}
6167

6268
variable "accept_license" {
6369
type = bool
64-
description = "Accept the VS Code license. https://code.visualstudio.com/license"
70+
description = "Accept the VS Code Server license. https://code.visualstudio.com/license/server"
6571
default = false
6672
validation {
6773
condition = var.accept_license == true
6874
error_message = "You must accept the VS Code license agreement by setting accept_license=true."
6975
}
7076
}
7177

78+
variable "telemetry_level" {
79+
type = string
80+
description = "Set the telemetry level for VS Code Web."
81+
default = "error"
82+
validation {
83+
condition = var.telemetry_level == "off" || var.telemetry_level == "crash" || var.telemetry_level == "error" || var.telemetry_level == "all"
84+
error_message = "Incorrect value. Please set either 'off', 'crash', 'error', or 'all'."
85+
}
86+
}
87+
7288
resource "coder_script" "vscode-web" {
7389
agent_id = var.agent_id
7490
display_name = "VS Code Web"
7591
icon = "/icon/code.svg"
7692
script = templatefile("${path.module}/run.sh", {
7793
PORT : var.port,
7894
LOG_PATH : var.log_path,
79-
INSTALL_DIR : var.install_dir,
95+
INSTALL_PREFIX : var.install_prefix,
96+
EXTENSIONS : join(",", var.extensions),
97+
TELEMETRY_LEVEL : var.telemetry_level,
8098
})
8199
run_on_start = true
82100
}

vscode-web/run.sh

100644100755
Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,49 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22

33
BOLD='\033[0;1m'
4+
EXTENSIONS=("${EXTENSIONS}")
45

5-
# Create install directory if it doesn't exist
6-
mkdir -p ${INSTALL_DIR}
6+
# Create install prefix
7+
mkdir -p ${INSTALL_PREFIX}
78

8-
printf "$${BOLD}Installing vscode-cli!\n"
9+
printf "$${BOLD}Installing Microsoft Visual Studio Code Server!\n"
910

10-
# Download and extract code-cli tarball
11-
output=$(curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz && tar -xf vscode_cli.tar.gz -C ${INSTALL_DIR} && rm vscode_cli.tar.gz)
11+
# Download and extract vscode-server
12+
ARCH=$(uname -m)
13+
case "$ARCH" in
14+
x86_64) ARCH="x64" ;;
15+
aarch64) ARCH="arm64" ;;
16+
*)
17+
echo "Unsupported architecture"
18+
exit 1
19+
;;
20+
esac
21+
22+
HASH=$(curl https://update.code.visualstudio.com/api/commits/stable/server-linux-$ARCH-web | cut -d '"' -f 2)
23+
output=$(curl -sL https://vscode.download.prss.microsoft.com/dbazure/download/stable/$HASH/vscode-server-linux-$ARCH-web.tar.gz | tar -xz -C ${INSTALL_PREFIX} --strip-components 1)
1224

1325
if [ $? -ne 0 ]; then
14-
echo "Failed to install vscode-cli: $output"
26+
echo "Failed to install Microsoft Visual Studio Code Server: $output"
1527
exit 1
1628
fi
17-
printf "🥳 vscode-cli has been installed.\n\n"
29+
printf "$${BOLD}Microsoft Visual Studio Code Server has been installed.\n"
30+
31+
VSCODE_SERVER="${INSTALL_PREFIX}/bin/code-server"
32+
33+
# Install each extension...
34+
IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}"
35+
for extension in "$${EXTENSIONLIST[@]}"; do
36+
if [ -z "$extension" ]; then
37+
continue
38+
fi
39+
printf "🧩 Installing extension $${CODE}$extension$${RESET}...\n"
40+
output=$($VSCODE_SERVER --install-extension "$extension" --force)
41+
if [ $? -ne 0 ]; then
42+
echo "Failed to install extension: $extension: $output"
43+
exit 1
44+
fi
45+
done
1846

19-
echo "👷 Running ${INSTALL_DIR}/bin/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms in the background..."
47+
echo "👷 Running ${INSTALL_PREFIX}/bin/code-server serve-local --port ${PORT} --accept-server-license-terms serve-local --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} in the background..."
2048
echo "Check logs at ${LOG_PATH}!"
21-
${INSTALL_DIR}/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms > ${LOG_PATH} 2>&1 &
49+
"${INSTALL_PREFIX}/bin/code-server" serve-local --port "${PORT}" --accept-server-license-terms serve-local --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 &

0 commit comments

Comments
 (0)