From e22a7188e1125188b4c3862c95bf68df3c36e686 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Mon, 25 Sep 2023 17:25:24 +0300 Subject: [PATCH] directly install vscode-server --- {vscode-web => vscode-server}/README.md | 12 +++++++----- {vscode-web => vscode-server}/main.tf | 21 +++++++++++++++------ vscode-server/run.sh | 17 +++++++++++++++++ vscode-web/run.sh | 23 ----------------------- 4 files changed, 39 insertions(+), 34 deletions(-) rename {vscode-web => vscode-server}/README.md (63%) rename {vscode-web => vscode-server}/main.tf (74%) create mode 100644 vscode-server/run.sh delete mode 100644 vscode-web/run.sh diff --git a/vscode-web/README.md b/vscode-server/README.md similarity index 63% rename from vscode-web/README.md rename to vscode-server/README.md index c737302..399290b 100644 --- a/vscode-web/README.md +++ b/vscode-server/README.md @@ -1,25 +1,26 @@ --- -display_name: vscode-web +display_name: vscode-server description: VS Code Web - Visual Studio Code in the browser icon: ../.icons/code.svg -maintainer_github: coder +maintainer_github: matifali verified: true tags: [helper, ide, vscode, web] --- # VS Code Web -Automatically install [VS Code](https://code.visualstudio.com) in a workspace, 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, create an app to access it via the dashboard. ## Examples -1. Install VS Code Web with default settings: +1. Install VS Code Server with default settings: ```hcl module "vscode-web" { source = "https://registry.coder.com/modules/vscode-web" agent_id = coder_agent.example.id accept_license = true + telemetry = "off" } ``` @@ -29,8 +30,9 @@ Automatically install [VS Code](https://code.visualstudio.com) in a workspace, c module "vscode-web" { source = "https://registry.coder.com/modules/vscode-web" agent_id = coder_agent.example.id - install_dir = "/home/coder/.coder/apps/vscode" + install_dir = "/home/coder/.vscode-server" folder = "/home/coder" accept_license = true + telemetry = "off" } ``` diff --git a/vscode-web/main.tf b/vscode-server/main.tf similarity index 74% rename from vscode-web/main.tf rename to vscode-server/main.tf index ae2bceb..5444995 100644 --- a/vscode-web/main.tf +++ b/vscode-server/main.tf @@ -22,20 +22,29 @@ variable "port" { variable "folder" { type = string - description = "The folder to open in VS Code Web." + description = "The folder to open in vscode-server." default = "" } variable "log_path" { type = string description = "The path to log." - default = "/tmp/vscode-web.log" + default = "/tmp/vscode-server.log" +} + +variable "telemetry" { + type = string + description = "Telemetry options for vscode-server. Valid values are 'off', 'crash', 'error' or 'all'." + default = "crash" + validation { + condition = var.telemetry == "off" || var.telemetry == "crash" || var.telemetry == "error" || var.telemetry == "all" + } } variable "install_dir" { type = string - description = "The directory to install VS Code" - default = "~/.vscodeweb" + description = "The directory to install VS Code Server" + default = "/tmp/vscode-server" } variable "accept_license" { @@ -56,7 +65,7 @@ variable "custom_version" { resource "coder_script" "vscode-web" { agent_id = var.agent_id - display_name = "VS Code Web" + display_name = "vscode-server" icon = "/icon/code.svg" script = templatefile("${path.module}/run.sh", { PORT : var.port, @@ -70,7 +79,7 @@ resource "coder_script" "vscode-web" { resource "coder_app" "vscode-web" { agent_id = var.agent_id slug = "vscode-web" - display_name = "VS Code Web" + display_name = "vscode-server" url = "http://localhost:${var.port}/?folder=${var.folder}" icon = "/icon/code.svg" subdomain = true diff --git a/vscode-server/run.sh b/vscode-server/run.sh new file mode 100644 index 0000000..04a6368 --- /dev/null +++ b/vscode-server/run.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +BOLD='\033[0;1m' + +printf "$${BOLD} Installing vscode-server!\n" +# Download and extract vsode-server tarball +HASH=$(curl https://update.code.visualstudio.com/api/commits/stable/server-linux-x64-web | cut -d '"' -f 2) +output=$(wget -O- https://az764295.vo.msecnd.net/stable/$HASH/vscode-server-linux-x64-web.tar.gz | tar -xz -C ${INSTALL_DIR} --strip-components=1 >/dev/null 2>&1) +if [ $? -ne 0 ]; then + echo "Failed to install vscode-server: $output" + exit 1 +fi +printf "🥳 vscode-server has been installed.\n\n" + +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}/bin/code-server serve-local --port ${PORT} --without-connection-token --accept-server-license-terms >${LOG_PATH} 2>&1 & diff --git a/vscode-web/run.sh b/vscode-web/run.sh deleted file mode 100644 index 868a582..0000000 --- a/vscode-web/run.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env sh - -BOLD='\033[0;1m' - -# Check if VS Code is installed -if [ ! -d "${INSTALL_DIR}" ]; then - printf "$${BOLD} Installing VS Code!\n" - # Download and extract VS Code tarball - output=$(curl -L "https://update.code.visualstudio.com/latest/linux-x64/stable" -o /tmp/code.tar.gz && - mkdir -p ${INSTALL_DIR} && - tar -xzf /tmp/code.tar.gz -C ${INSTALL_DIR} --strip-components=1) - if [ $? -ne 0 ]; then - echo "Failed to install VS Code: $output" - exit 1 - fi - printf "🥳 VS code has been installed.\n\n" -else - printf "🥳 VS code is already installed.\n\n" -fi - -echo "👷 Running code serve-web in the background..." -echo "Check logs at ${LOG_PATH}!" -${INSTALL_DIR}/bin/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms >${LOG_PATH} 2>&1 &