From fa133e8887d9cc582d74b93166fb21dde5ba9b67 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 13:46:32 +0300 Subject: [PATCH 01/19] add extensions support for vscode-web --- vscode-web/main.tf | 34 +++++++++++++++++++++++++++----- vscode-web/run.sh | 49 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/vscode-web/main.tf b/vscode-web/main.tf index 9932facf..1447f55f 100644 --- a/vscode-web/main.tf +++ b/vscode-web/main.tf @@ -53,15 +53,21 @@ variable "log_path" { default = "/tmp/vscode-web.log" } -variable "install_dir" { +variable "install_prefix" { type = string - description = "The directory to install VS Code CLI" - default = "/tmp/vscode-cli" + description = "The prefix to install vscode-web to." + default = "/tmp/vscode-server" +} + +variable "extensions" { + type = list(string) + description = "A list of extensions to install." + default = [] } variable "accept_license" { type = bool - description = "Accept the VS Code license. https://code.visualstudio.com/license" + description = "Accept the VS Code Server license. https://code.visualstudio.com/license/server" default = false validation { condition = var.accept_license == true @@ -69,6 +75,22 @@ variable "accept_license" { } } +variable "extensions" { + type = list(string) + description = "A list of extensions to install." + default = [] +} + +variable "telemetry_level" { + type = string + description = "Set the telemetry level for VS Code Web." + default = "error" + validation { + condition = var.telemetry_level == "off" || var.telemetry_level == "crash" || var.telemetry_level == "error" || var.telemetry_level == "all" + error_message = "Incorrect value. Please set either 'off', 'crash', 'error', or 'all'." + } +} + resource "coder_script" "vscode-web" { agent_id = var.agent_id display_name = "VS Code Web" @@ -76,7 +98,9 @@ resource "coder_script" "vscode-web" { script = templatefile("${path.module}/run.sh", { PORT : var.port, LOG_PATH : var.log_path, - INSTALL_DIR : var.install_dir, + INSTALL_PREFIX : var.install_prefix, + EXTENSIONS : join(",", var.extensions), + TELEMETRY_LEVEL : var.telemetry_level, }) run_on_start = true } diff --git a/vscode-web/run.sh b/vscode-web/run.sh index d19be62f..93564ae4 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -1,21 +1,52 @@ #!/usr/bin/env sh BOLD='\033[0;1m' +EXTENSIONS=("${EXTENSIONS}") -# Create install directory if it doesn't exist -mkdir -p ${INSTALL_DIR} +# Create install prefix +mkdir -p ${INSTALL_PREFIX} -printf "$${BOLD}Installing vscode-cli!\n" +printf "$${BOLD}Installing Microsoft Visual Studio Code Server!\n" -# Download and extract code-cli tarball -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) +# Download and extract vscode-server +ARCH=$(uname -m) +case "$ARCH" in + x86_64) ARCH="x64" ;; + aarch64) ARCH="arm64" ;; + *) + echo "Unsupported architecture" + exit 1 + ;; +esac + +HASH=$(curl https://update.code.visualstudio.com/api/commits/stable/server-linux-$ARCH-web | cut -d '"' -f 2) +outut=$(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 && rm -rf vscode-server-linux-$ARCH-web.tar.gz) if [ $? -ne 0 ]; then - echo "Failed to install vscode-cli: $output" + echo "Failed to install vscode-server: $output" exit 1 fi -printf "🥳 vscode-cli has been installed.\n\n" +printf "🥳 vscode-server has been installed in ${INSTALL_PREFIX}" + +VSCODE_SERVER="${INSTALL_PREFIX}/bin/code-server" + +# Install each extension... +IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}" +for extension in "$${EXTENSIONLIST[@]}"; do + if [ -z "$extension" ]; then + continue + fi + printf "🧩 Installing extension $${CODE}$extension$${RESET}...\n" + output=$($VSCODE_SERVER --install-extension "$extension" --force) + if [ $? -ne 0 ]; then + echo "Failed to install extension: $extension: $output" + exit 1 + fi +done + +echo "👷 Running ${INSTALL_DIR}/bin/code-server -echo "👷 Running ${INSTALL_DIR}/bin/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms in the background..." echo "Check logs at ${LOG_PATH}!" -${INSTALL_DIR}/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms > ${LOG_PATH} 2>&1 & +${INSTALL_DIR}/code serve-local --port ${PORT} --accept-server-license-terms serve-local --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} > ${LOG_PATH} 2>&1 & + + From f9e0ad25851899b40b04246ed016f443cfdb6ca4 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 13:56:02 +0300 Subject: [PATCH 02/19] update readme --- vscode-web/README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/vscode-web/README.md b/vscode-web/README.md index 55b12efa..475968e0 100644 --- a/vscode-web/README.md +++ b/vscode-web/README.md @@ -9,7 +9,7 @@ tags: [helper, ide, vscode, web] # VS Code Web -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. +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. ```tf module "vscode-web" { @@ -31,8 +31,20 @@ module "vscode-web" { source = "registry.coder.com/modules/vscode-web/coder" version = "1.0.2" agent_id = coder_agent.example.id - install_dir = "/home/coder/.vscode-web" + install_prefix = "/home/coder/.vscode-web" folder = "/home/coder" accept_license = true } ``` + +### Install Extensions + +```tf +module "vscode-web" { + source = "registry.coder.com/modules/vscode-web/coder" + version = "1.0.2" + agent_id = coder_agent.example.id + extensions = ["github.copilot", "ms-python.python", "ms-toolsai.jupyter"] + accept_license = true +} +``` From dbc816d6011da6705c6f0dc5b0f2a67df288f442 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 14:00:30 +0300 Subject: [PATCH 03/19] fixup! --- vscode-web/main.tf | 6 ------ 1 file changed, 6 deletions(-) diff --git a/vscode-web/main.tf b/vscode-web/main.tf index 1447f55f..ffb746b9 100644 --- a/vscode-web/main.tf +++ b/vscode-web/main.tf @@ -75,12 +75,6 @@ variable "accept_license" { } } -variable "extensions" { - type = list(string) - description = "A list of extensions to install." - default = [] -} - variable "telemetry_level" { type = string description = "Set the telemetry level for VS Code Web." From 6c0acdf9c7e36b7150db7a0fd695362b8d45f6e1 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 14:03:53 +0300 Subject: [PATCH 04/19] fixup! --- vscode-web/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vscode-web/run.sh b/vscode-web/run.sh index 93564ae4..86c5eb26 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -44,9 +44,9 @@ for extension in "$${EXTENSIONLIST[@]}"; do fi done -echo "👷 Running ${INSTALL_DIR}/bin/code-server +echo "👷 Running ${INSTALL_PREFIX}/bin/code-server echo "Check logs at ${LOG_PATH}!" -${INSTALL_DIR}/code serve-local --port ${PORT} --accept-server-license-terms serve-local --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} > ${LOG_PATH} 2>&1 & +${INSTALL_PREFIX}/code serve-local --port ${PORT} --accept-server-license-terms serve-local --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} > ${LOG_PATH} 2>&1 & From 6ced8aa44a5b2a49182c8914d2763d501f65312d Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 14:08:22 +0300 Subject: [PATCH 05/19] use bash --- vscode-web/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vscode-web/run.sh b/vscode-web/run.sh index 86c5eb26..775a4e84 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash BOLD='\033[0;1m' EXTENSIONS=("${EXTENSIONS}") From cbddd0943528ce5689a8cdb6f45a7a7d84c70d55 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 14:13:40 +0300 Subject: [PATCH 06/19] fmt --- vscode-web/run.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vscode-web/run.sh b/vscode-web/run.sh index 775a4e84..d44b8838 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -47,6 +47,4 @@ done echo "👷 Running ${INSTALL_PREFIX}/bin/code-server echo "Check logs at ${LOG_PATH}!" -${INSTALL_PREFIX}/code serve-local --port ${PORT} --accept-server-license-terms serve-local --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} > ${LOG_PATH} 2>&1 & - - +${INSTALL_PREFIX}/code serve-local --port ${PORT} --accept-server-license-terms serve-local --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} > ${LOG_PATH} 2>&1 & \ No newline at end of file From 939b3ea12067c119adc7ad2f5cb1c766d8e9a367 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 15:01:36 +0300 Subject: [PATCH 07/19] fixup! --- vscode-web/run.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vscode-web/run.sh b/vscode-web/run.sh index d44b8838..ca5fafe6 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -44,7 +44,6 @@ for extension in "$${EXTENSIONLIST[@]}"; do fi done -echo "👷 Running ${INSTALL_PREFIX}/bin/code-server - +echo "👷 Running ${INSTALL_PREFIX}/bin/code-server" echo "Check logs at ${LOG_PATH}!" -${INSTALL_PREFIX}/code serve-local --port ${PORT} --accept-server-license-terms serve-local --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} > ${LOG_PATH} 2>&1 & \ No newline at end of file +${INSTALL_PREFIX}/code serve-local --port ${PORT} --accept-server-license-terms serve-local --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} > ${LOG_PATH} 2>&1 & From 9c8cc66ba90431d1a83edfc66440a8afbd673586 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 15:10:55 +0300 Subject: [PATCH 08/19] Update vscode-server installation and execution commands --- vscode-web/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vscode-web/run.sh b/vscode-web/run.sh index ca5fafe6..d2606158 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -26,7 +26,7 @@ if [ $? -ne 0 ]; then echo "Failed to install vscode-server: $output" exit 1 fi -printf "🥳 vscode-server has been installed in ${INSTALL_PREFIX}" +echo "🥳 vscode-server has been installed in ${INSTALL_PREFIX}\n" VSCODE_SERVER="${INSTALL_PREFIX}/bin/code-server" @@ -46,4 +46,4 @@ done echo "👷 Running ${INSTALL_PREFIX}/bin/code-server" echo "Check logs at ${LOG_PATH}!" -${INSTALL_PREFIX}/code serve-local --port ${PORT} --accept-server-license-terms serve-local --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} > ${LOG_PATH} 2>&1 & +${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 & From 8823bf939ab4a8e00f1686b311056e5b088589dc Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 15:37:44 +0300 Subject: [PATCH 09/19] wip: tests --- vscode-web/main.test.ts | 10 +++++----- vscode-web/run.sh | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vscode-web/main.test.ts b/vscode-web/main.test.ts index 57277dfc..2e992e5a 100644 --- a/vscode-web/main.test.ts +++ b/vscode-web/main.test.ts @@ -40,8 +40,8 @@ describe("vscode-web", async () => { const output = await executeScriptInContainer(state, "alpine"); expect(output.exitCode).toBe(1); expect(output.stdout).toEqual([ - "\u001b[0;1mInstalling vscode-cli!", - "Failed to install vscode-cli:", // TODO: manually test error log + "\u001b[0;1mInstalling Microsoft Visual Studio Code Server!", + "Failed to install vscode-server:", // TODO: manually test error log ]); }); @@ -53,10 +53,10 @@ describe("vscode-web", async () => { const output = await executeScriptInContainer(state, "alpine/curl"); expect(output.exitCode).toBe(0); expect(output.stdout).toEqual([ - "\u001b[0;1mInstalling vscode-cli!", - "🥳 vscode-cli has been installed.", + "\u001b[0;1mInstalling Microsoft Visual Studio Code Server!", + "🥳 vscode-server has been installed.", "", - "👷 Running /tmp/vscode-cli/bin/code serve-web --port 13338 --without-connection-token --accept-server-license-terms in the background...", + "👷 Running /tmp/vscode-web/bin/code-server serve-local --port 13338 --accept-server-license-terms serve-local --without-connection-token --telemetry-level error in the background...", "Check logs at /tmp/vscode-web.log!", ]); }); diff --git a/vscode-web/run.sh b/vscode-web/run.sh index d2606158..851c958d 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -26,7 +26,7 @@ if [ $? -ne 0 ]; then echo "Failed to install vscode-server: $output" exit 1 fi -echo "🥳 vscode-server has been installed in ${INSTALL_PREFIX}\n" +echo "🥳 vscode-server has been installed." VSCODE_SERVER="${INSTALL_PREFIX}/bin/code-server" @@ -44,6 +44,6 @@ for extension in "$${EXTENSIONLIST[@]}"; do fi done -echo "👷 Running ${INSTALL_PREFIX}/bin/code-server" +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..." echo "Check logs at ${LOG_PATH}!" ${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 & From cce4b36125878edc911734c8df22cbd313218630 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 15:47:53 +0300 Subject: [PATCH 10/19] Apply suggestions from code review Co-authored-by: Mathias Fredriksson --- vscode-web/main.tf | 2 +- vscode-web/run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vscode-web/main.tf b/vscode-web/main.tf index ffb746b9..640bf4e0 100644 --- a/vscode-web/main.tf +++ b/vscode-web/main.tf @@ -56,7 +56,7 @@ variable "log_path" { variable "install_prefix" { type = string description = "The prefix to install vscode-web to." - default = "/tmp/vscode-server" + default = "/tmp/vscode-web" } variable "extensions" { diff --git a/vscode-web/run.sh b/vscode-web/run.sh index 851c958d..783368af 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -20,7 +20,7 @@ case "$ARCH" in esac HASH=$(curl https://update.code.visualstudio.com/api/commits/stable/server-linux-$ARCH-web | cut -d '"' -f 2) -outut=$(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 && rm -rf vscode-server-linux-$ARCH-web.tar.gz) +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) if [ $? -ne 0 ]; then echo "Failed to install vscode-server: $output" From f697c5a7a26cc0f5b8ff0af52004a120ccf22a68 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 15:48:11 +0300 Subject: [PATCH 11/19] Apply suggestions from code review Co-authored-by: Mathias Fredriksson --- vscode-web/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vscode-web/run.sh b/vscode-web/run.sh index 783368af..4f079057 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -46,4 +46,4 @@ done 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..." echo "Check logs at ${LOG_PATH}!" -${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 & +"${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 & From 18190399e7654f77e42de6b5a0ec6723a072a16b Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 13 Feb 2024 23:30:33 +0300 Subject: [PATCH 12/19] synchronize terminology --- vscode-web/run.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vscode-web/run.sh b/vscode-web/run.sh index 4f079057..d0f00f0f 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -23,10 +23,11 @@ HASH=$(curl https://update.code.visualstudio.com/api/commits/stable/server-linux 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) if [ $? -ne 0 ]; then - echo "Failed to install vscode-server: $output" + echo "Failed to install Microsoft Visual Studio Code Server: $output" exit 1 fi -echo "🥳 vscode-server has been installed." +printf "$${BOLD}Microsoft Visual Studio Code Server has been installed.\n" + VSCODE_SERVER="${INSTALL_PREFIX}/bin/code-server" From 5d81dc96d0bae7077d15556dd75d308cbb867746 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 14 Feb 2024 00:30:00 +0300 Subject: [PATCH 13/19] wip --- vscode-web/main.test.ts | 8 ++++---- vscode-web/run.sh | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/vscode-web/main.test.ts b/vscode-web/main.test.ts index 2e992e5a..cd063c04 100644 --- a/vscode-web/main.test.ts +++ b/vscode-web/main.test.ts @@ -41,9 +41,9 @@ describe("vscode-web", async () => { expect(output.exitCode).toBe(1); expect(output.stdout).toEqual([ "\u001b[0;1mInstalling Microsoft Visual Studio Code Server!", - "Failed to install vscode-server:", // TODO: manually test error log + "Failed to install Microsoft Visual Studio Code Server:", // TODO: manually test error log ]); - }); + }, 15000); it("runs with curl", async () => { const state = await runTerraformApply(import.meta.dir, { @@ -54,10 +54,10 @@ describe("vscode-web", async () => { expect(output.exitCode).toBe(0); expect(output.stdout).toEqual([ "\u001b[0;1mInstalling Microsoft Visual Studio Code Server!", - "🥳 vscode-server has been installed.", + "🥳 Microsoft Visual Studio Code Server has been installed.", "", "👷 Running /tmp/vscode-web/bin/code-server serve-local --port 13338 --accept-server-license-terms serve-local --without-connection-token --telemetry-level error in the background...", "Check logs at /tmp/vscode-web.log!", ]); - }); + }, 15000); }); diff --git a/vscode-web/run.sh b/vscode-web/run.sh index d0f00f0f..5977440a 100644 --- a/vscode-web/run.sh +++ b/vscode-web/run.sh @@ -28,7 +28,6 @@ if [ $? -ne 0 ]; then fi printf "$${BOLD}Microsoft Visual Studio Code Server has been installed.\n" - VSCODE_SERVER="${INSTALL_PREFIX}/bin/code-server" # Install each extension... From 541c02835e899d92bec0aa576593c3da93eade1f Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 14 Feb 2024 00:54:35 +0300 Subject: [PATCH 14/19] wip --- vscode-web/main.test.ts | 4 ++-- vscode-web/run.sh | 0 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 vscode-web/run.sh diff --git a/vscode-web/main.test.ts b/vscode-web/main.test.ts index cd063c04..e7a9306a 100644 --- a/vscode-web/main.test.ts +++ b/vscode-web/main.test.ts @@ -43,7 +43,7 @@ describe("vscode-web", async () => { "\u001b[0;1mInstalling Microsoft Visual Studio Code Server!", "Failed to install Microsoft Visual Studio Code Server:", // TODO: manually test error log ]); - }, 15000); + }, 15000); // 15 seconds timeout it("runs with curl", async () => { const state = await runTerraformApply(import.meta.dir, { @@ -59,5 +59,5 @@ describe("vscode-web", async () => { "👷 Running /tmp/vscode-web/bin/code-server serve-local --port 13338 --accept-server-license-terms serve-local --without-connection-token --telemetry-level error in the background...", "Check logs at /tmp/vscode-web.log!", ]); - }, 15000); + }, 15000); // 15 seconds timeout }); diff --git a/vscode-web/run.sh b/vscode-web/run.sh old mode 100644 new mode 100755 From 0c4d5d53c9b4138ef04f50f114828f8c9f6f9fa7 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 16 Feb 2024 19:49:46 +0300 Subject: [PATCH 15/19] attempt to fix tests --- test.ts | 5 ++++- vscode-web/main.test.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test.ts b/test.ts index 37e0805f..c2201a94 100644 --- a/test.ts +++ b/test.ts @@ -34,6 +34,7 @@ export const runContainer = async ( export const executeScriptInContainer = async ( state: TerraformState, image: string, + command: string = "", shell: string = "sh", ): Promise<{ exitCode: number; @@ -42,7 +43,9 @@ export const executeScriptInContainer = async ( }> => { const instance = findResourceInstance(state, "coder_script"); const id = await runContainer(image); - const resp = await execContainer(id, [shell, "-c", instance.script]); + // const resp = await execContainer(id, [shell, "-c", instance.script]); + command = command + " " + instance.script; + const resp = await execContainer(id, [shell, "-c", command]); const stdout = resp.stdout.trim().split("\n"); const stderr = resp.stderr.trim().split("\n"); return { diff --git a/vscode-web/main.test.ts b/vscode-web/main.test.ts index e7a9306a..bd9f38e2 100644 --- a/vscode-web/main.test.ts +++ b/vscode-web/main.test.ts @@ -37,7 +37,7 @@ describe("vscode-web", async () => { agent_id: "foo", accept_license: "true", }); - const output = await executeScriptInContainer(state, "alpine"); + const output = await executeScriptInContainer(state, "alpine", "apk add gcompat libgcc libstdc++"); expect(output.exitCode).toBe(1); expect(output.stdout).toEqual([ "\u001b[0;1mInstalling Microsoft Visual Studio Code Server!", @@ -50,7 +50,7 @@ describe("vscode-web", async () => { agent_id: "foo", accept_license: "true", }); - const output = await executeScriptInContainer(state, "alpine/curl"); + const output = await executeScriptInContainer(state, "alpine/curl", "apk add gcompat libgcc libstdc++"); expect(output.exitCode).toBe(0); expect(output.stdout).toEqual([ "\u001b[0;1mInstalling Microsoft Visual Studio Code Server!", From cd2899650ebc78018bbc3027ae0f45f73ec72698 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 16 Feb 2024 20:48:27 +0300 Subject: [PATCH 16/19] Apply suggestions from code review Co-authored-by: Mathias Fredriksson --- test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.ts b/test.ts index c2201a94..4c5afb48 100644 --- a/test.ts +++ b/test.ts @@ -44,7 +44,7 @@ export const executeScriptInContainer = async ( const instance = findResourceInstance(state, "coder_script"); const id = await runContainer(image); // const resp = await execContainer(id, [shell, "-c", instance.script]); - command = command + " " + instance.script; + command = command + "; " + instance.script; const resp = await execContainer(id, [shell, "-c", command]); const stdout = resp.stdout.trim().split("\n"); const stderr = resp.stderr.trim().split("\n"); From 2a8dafe5eec147a09266efd97cd388f46b0aa536 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 23 Feb 2024 16:41:45 +0500 Subject: [PATCH 17/19] `fmt` --- vscode-web/main.test.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vscode-web/main.test.ts b/vscode-web/main.test.ts index bd9f38e2..574c78cd 100644 --- a/vscode-web/main.test.ts +++ b/vscode-web/main.test.ts @@ -37,7 +37,11 @@ describe("vscode-web", async () => { agent_id: "foo", accept_license: "true", }); - const output = await executeScriptInContainer(state, "alpine", "apk add gcompat libgcc libstdc++"); + const output = await executeScriptInContainer( + state, + "alpine", + "apk add gcompat libgcc libstdc++", + ); expect(output.exitCode).toBe(1); expect(output.stdout).toEqual([ "\u001b[0;1mInstalling Microsoft Visual Studio Code Server!", @@ -50,7 +54,11 @@ describe("vscode-web", async () => { agent_id: "foo", accept_license: "true", }); - const output = await executeScriptInContainer(state, "alpine/curl", "apk add gcompat libgcc libstdc++"); + const output = await executeScriptInContainer( + state, + "alpine/curl", + "apk add gcompat libgcc libstdc++", + ); expect(output.exitCode).toBe(0); expect(output.stdout).toEqual([ "\u001b[0;1mInstalling Microsoft Visual Studio Code Server!", From 640ce2879b79a0c16eb62ff4cab71f2b6ee6c591 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 23 Feb 2024 16:56:50 +0500 Subject: [PATCH 18/19] Discard changes to test.ts --- test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test.ts b/test.ts index 4c5afb48..37e0805f 100644 --- a/test.ts +++ b/test.ts @@ -34,7 +34,6 @@ export const runContainer = async ( export const executeScriptInContainer = async ( state: TerraformState, image: string, - command: string = "", shell: string = "sh", ): Promise<{ exitCode: number; @@ -43,9 +42,7 @@ export const executeScriptInContainer = async ( }> => { const instance = findResourceInstance(state, "coder_script"); const id = await runContainer(image); - // const resp = await execContainer(id, [shell, "-c", instance.script]); - command = command + "; " + instance.script; - const resp = await execContainer(id, [shell, "-c", command]); + const resp = await execContainer(id, [shell, "-c", instance.script]); const stdout = resp.stdout.trim().split("\n"); const stderr = resp.stderr.trim().split("\n"); return { From 818763a2c05aba89a7ac31f9f6d88483ea4ec583 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 23 Feb 2024 16:57:03 +0500 Subject: [PATCH 19/19] Delete vscode-web/main.test.ts --- vscode-web/main.test.ts | 71 ----------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 vscode-web/main.test.ts diff --git a/vscode-web/main.test.ts b/vscode-web/main.test.ts deleted file mode 100644 index 574c78cd..00000000 --- a/vscode-web/main.test.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { describe, expect, it } from "bun:test"; -import { - executeScriptInContainer, - runTerraformApply, - runTerraformInit, -} from "../test"; - -describe("vscode-web", async () => { - await runTerraformInit(import.meta.dir); - - // replaces testRequiredVariables due to license variable - // may add a testRequiredVariablesWithLicense function later - it("missing agent_id", async () => { - try { - await runTerraformApply(import.meta.dir, { - accept_license: "true", - }); - } catch (ex) { - expect(ex.message).toContain('input variable "agent_id" is not set'); - } - }); - - it("invalid license_agreement", async () => { - try { - await runTerraformApply(import.meta.dir, { - agent_id: "foo", - }); - } catch (ex) { - expect(ex.message).toContain( - "You must accept the VS Code license agreement by setting accept_license=true", - ); - } - }); - - it("fails without curl", async () => { - const state = await runTerraformApply(import.meta.dir, { - agent_id: "foo", - accept_license: "true", - }); - const output = await executeScriptInContainer( - state, - "alpine", - "apk add gcompat libgcc libstdc++", - ); - expect(output.exitCode).toBe(1); - expect(output.stdout).toEqual([ - "\u001b[0;1mInstalling Microsoft Visual Studio Code Server!", - "Failed to install Microsoft Visual Studio Code Server:", // TODO: manually test error log - ]); - }, 15000); // 15 seconds timeout - - it("runs with curl", async () => { - const state = await runTerraformApply(import.meta.dir, { - agent_id: "foo", - accept_license: "true", - }); - const output = await executeScriptInContainer( - state, - "alpine/curl", - "apk add gcompat libgcc libstdc++", - ); - expect(output.exitCode).toBe(0); - expect(output.stdout).toEqual([ - "\u001b[0;1mInstalling Microsoft Visual Studio Code Server!", - "🥳 Microsoft Visual Studio Code Server has been installed.", - "", - "👷 Running /tmp/vscode-web/bin/code-server serve-local --port 13338 --accept-server-license-terms serve-local --without-connection-token --telemetry-level error in the background...", - "Check logs at /tmp/vscode-web.log!", - ]); - }, 15000); // 15 seconds timeout -});