From 4021d856badaf16c9df81b1dea5f1f3b03962800 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Mon, 3 Jun 2024 12:43:17 -0700 Subject: [PATCH 1/3] fix(code-server): USE_CACHED should still install extensions (#252) --- code-server/run.sh | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/code-server/run.sh b/code-server/run.sh index 26a1c6e..c89502b 100755 --- a/code-server/run.sh +++ b/code-server/run.sh @@ -25,36 +25,37 @@ if [ ! -f ~/.local/share/code-server/User/settings.json ]; then echo "${SETTINGS}" > ~/.local/share/code-server/User/settings.json fi -# Check if code-server is already installed for offline or cached mode -if [ -f "$CODE_SERVER" ]; then - if [ "${OFFLINE}" = true ] || [ "${USE_CACHED}" = true ]; then +# Check if code-server is already installed for offline +if [ "${OFFLINE}" = true ]; then + if [ -f "$CODE_SERVER" ]; then echo "🥳 Found a copy of code-server" run_code_server exit 0 fi -fi -# Offline mode always expects a copy of code-server to be present -if [ "${OFFLINE}" = true ]; then + # Offline mode always expects a copy of code-server to be present echo "Failed to find a copy of code-server" exit 1 fi -printf "$${BOLD}Installing code-server!\n" +# If there is no cached install OR we don't want to use a cached install +if [ ! -f "$CODE_SERVER" ] || [ "${USE_CACHED}" != true ]; then + printf "$${BOLD}Installing code-server!\n" -ARGS=( - "--method=standalone" - "--prefix=${INSTALL_PREFIX}" -) -if [ -n "${VERSION}" ]; then - ARGS+=("--version=${VERSION}") -fi + ARGS=( + "--method=standalone" + "--prefix=${INSTALL_PREFIX}" + ) + if [ -n "${VERSION}" ]; then + ARGS+=("--version=${VERSION}") + fi -output=$(curl -fsSL https://code-server.dev/install.sh | sh -s -- "$${ARGS[@]}") -if [ $? -ne 0 ]; then - echo "Failed to install code-server: $output" - exit 1 + output=$(curl -fsSL https://code-server.dev/install.sh | sh -s -- "$${ARGS[@]}") + if [ $? -ne 0 ]; then + echo "Failed to install code-server: $output" + exit 1 + fi + printf "🥳 code-server has been installed in ${INSTALL_PREFIX}\n\n" fi -printf "🥳 code-server has been installed in ${INSTALL_PREFIX}\n\n" # Install each extension... IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}" From c652dbe32006eebbaef01b8777b49eb787a915f8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 22:49:24 +0300 Subject: [PATCH 2/3] chore: bump version to 1.0.15 in README.md files (#258) Co-authored-by: matifali --- code-server/README.md | 14 +++++++------- coder-login/README.md | 2 +- dotfiles/README.md | 12 ++++++------ git-config/README.md | 6 +++--- github-upload-public-key/README.md | 4 ++-- jfrog-oauth/README.md | 6 +++--- jfrog-token/README.md | 8 ++++---- vscode-desktop/README.md | 4 ++-- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/code-server/README.md b/code-server/README.md index 463fb22..e1ca7a2 100644 --- a/code-server/README.md +++ b/code-server/README.md @@ -14,7 +14,7 @@ Automatically install [code-server](https://github.com/coder/code-server) in a w ```tf module "code-server" { source = "registry.coder.com/modules/code-server/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id } ``` @@ -28,7 +28,7 @@ module "code-server" { ```tf module "code-server" { source = "registry.coder.com/modules/code-server/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id install_version = "4.8.3" } @@ -41,7 +41,7 @@ Install the Dracula theme from [OpenVSX](https://open-vsx.org/): ```tf module "code-server" { source = "registry.coder.com/modules/code-server/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id extensions = [ "dracula-theme.theme-dracula" @@ -58,7 +58,7 @@ Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarte ```tf module "code-server" { source = "registry.coder.com/modules/code-server/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id extensions = ["dracula-theme.theme-dracula"] settings = { @@ -74,7 +74,7 @@ Just run code-server in the background, don't fetch it from GitHub: ```tf module "code-server" { source = "registry.coder.com/modules/code-server/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id extensions = ["dracula-theme.theme-dracula", "ms-azuretools.vscode-docker"] } @@ -89,7 +89,7 @@ Run an existing copy of code-server if found, otherwise download from GitHub: ```tf module "code-server" { source = "registry.coder.com/modules/code-server/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id use_cached = true extensions = ["dracula-theme.theme-dracula", "ms-azuretools.vscode-docker"] @@ -101,7 +101,7 @@ Just run code-server in the background, don't fetch it from GitHub: ```tf module "code-server" { source = "registry.coder.com/modules/code-server/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id offline = true } diff --git a/coder-login/README.md b/coder-login/README.md index d68e088..c9bb333 100644 --- a/coder-login/README.md +++ b/coder-login/README.md @@ -14,7 +14,7 @@ Automatically logs the user into Coder when creating their workspace. ```tf module "coder-login" { source = "registry.coder.com/modules/coder-login/coder" - version = "1.0.2" + version = "1.0.15" agent_id = coder_agent.example.id } ``` diff --git a/dotfiles/README.md b/dotfiles/README.md index 4e3312f..41371ab 100644 --- a/dotfiles/README.md +++ b/dotfiles/README.md @@ -18,7 +18,7 @@ Under the hood, this module uses the [coder dotfiles](https://coder.com/docs/v2/ ```tf module "dotfiles" { source = "registry.coder.com/modules/dotfiles/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id } ``` @@ -30,7 +30,7 @@ module "dotfiles" { ```tf module "dotfiles" { source = "registry.coder.com/modules/dotfiles/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id } ``` @@ -40,7 +40,7 @@ module "dotfiles" { ```tf module "dotfiles" { source = "registry.coder.com/modules/dotfiles/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id user = "root" } @@ -51,13 +51,13 @@ module "dotfiles" { ```tf module "dotfiles" { source = "registry.coder.com/modules/dotfiles/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id } module "dotfiles-root" { source = "registry.coder.com/modules/dotfiles/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id user = "root" dotfiles_uri = module.dotfiles.dotfiles_uri @@ -71,7 +71,7 @@ You can set a default dotfiles repository for all users by setting the `default_ ```tf module "dotfiles" { source = "registry.coder.com/modules/dotfiles/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id default_dotfiles_uri = "https://github.com/coder/dotfiles" } diff --git a/git-config/README.md b/git-config/README.md index 8a0f3ad..90e8442 100644 --- a/git-config/README.md +++ b/git-config/README.md @@ -14,7 +14,7 @@ Runs a script that updates git credentials in the workspace to match the user's ```tf module "git-config" { source = "registry.coder.com/modules/git-config/coder" - version = "1.0.12" + version = "1.0.15" agent_id = coder_agent.example.id } ``` @@ -28,7 +28,7 @@ TODO: Add screenshot ```tf module "git-config" { source = "registry.coder.com/modules/git-config/coder" - version = "1.0.12" + version = "1.0.15" agent_id = coder_agent.example.id allow_email_change = true } @@ -41,7 +41,7 @@ TODO: Add screenshot ```tf module "git-config" { source = "registry.coder.com/modules/git-config/coder" - version = "1.0.12" + version = "1.0.15" agent_id = coder_agent.example.id allow_username_change = false allow_email_change = false diff --git a/github-upload-public-key/README.md b/github-upload-public-key/README.md index 2e1938a..17464f3 100644 --- a/github-upload-public-key/README.md +++ b/github-upload-public-key/README.md @@ -14,7 +14,7 @@ Templates that utilize Github External Auth can automatically ensure that the Co ```tf module "github-upload-public-key" { source = "registry.coder.com/modules/github-upload-public-key/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id } ``` @@ -46,7 +46,7 @@ data "coder_external_auth" "github" { module "github-upload-public-key" { source = "registry.coder.com/modules/github-upload-public-key/coder" - version = "1.0.14" + version = "1.0.15" agent_id = coder_agent.example.id external_auth_id = data.coder_external_auth.github.id } diff --git a/jfrog-oauth/README.md b/jfrog-oauth/README.md index 60b3bb7..b7f9d58 100644 --- a/jfrog-oauth/README.md +++ b/jfrog-oauth/README.md @@ -17,7 +17,7 @@ Install the JF CLI and authenticate package managers with Artifactory using OAut ```tf module "jfrog" { source = "registry.coder.com/modules/jfrog-oauth/coder" - version = "1.0.5" + version = "1.0.15" agent_id = coder_agent.example.id jfrog_url = "https://example.jfrog.io" username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username" @@ -44,7 +44,7 @@ Configure the Python pip package manager to fetch packages from Artifactory whil ```tf module "jfrog" { source = "registry.coder.com/modules/jfrog-oauth/coder" - version = "1.0.5" + version = "1.0.15" agent_id = coder_agent.example.id jfrog_url = "https://example.jfrog.io" username_field = "email" @@ -72,7 +72,7 @@ The [JFrog extension](https://open-vsx.org/extension/JFrog/jfrog-vscode-extensio ```tf module "jfrog" { source = "registry.coder.com/modules/jfrog-oauth/coder" - version = "1.0.5" + version = "1.0.15" agent_id = coder_agent.example.id jfrog_url = "https://example.jfrog.io" username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username" diff --git a/jfrog-token/README.md b/jfrog-token/README.md index 4a4089a..f903f90 100644 --- a/jfrog-token/README.md +++ b/jfrog-token/README.md @@ -15,7 +15,7 @@ Install the JF CLI and authenticate package managers with Artifactory using Arti ```tf module "jfrog" { source = "registry.coder.com/modules/jfrog-token/coder" - version = "1.0.10" + version = "1.0.15" agent_id = coder_agent.example.id jfrog_url = "https://XXXX.jfrog.io" artifactory_access_token = var.artifactory_access_token @@ -41,7 +41,7 @@ For detailed instructions, please see this [guide](https://coder.com/docs/v2/lat ```tf module "jfrog" { source = "registry.coder.com/modules/jfrog-token/coder" - version = "1.0.10" + version = "1.0.15" agent_id = coder_agent.example.id jfrog_url = "https://YYYY.jfrog.io" artifactory_access_token = var.artifactory_access_token # An admin access token @@ -74,7 +74,7 @@ The [JFrog extension](https://open-vsx.org/extension/JFrog/jfrog-vscode-extensio ```tf module "jfrog" { source = "registry.coder.com/modules/jfrog-token/coder" - version = "1.0.10" + version = "1.0.15" agent_id = coder_agent.example.id jfrog_url = "https://XXXX.jfrog.io" artifactory_access_token = var.artifactory_access_token @@ -94,7 +94,7 @@ data "coder_workspace" "me" {} module "jfrog" { source = "registry.coder.com/modules/jfrog-token/coder" - version = "1.0.10" + version = "1.0.15" agent_id = coder_agent.example.id jfrog_url = "https://XXXX.jfrog.io" artifactory_access_token = var.artifactory_access_token diff --git a/vscode-desktop/README.md b/vscode-desktop/README.md index e0d1ff2..bc8920d 100644 --- a/vscode-desktop/README.md +++ b/vscode-desktop/README.md @@ -16,7 +16,7 @@ Uses the [Coder Remote VS Code Extension](https://github.com/coder/vscode-coder) ```tf module "vscode" { source = "registry.coder.com/modules/vscode-desktop/coder" - version = "1.0.8" + version = "1.0.15" agent_id = coder_agent.example.id } ``` @@ -28,7 +28,7 @@ module "vscode" { ```tf module "vscode" { source = "registry.coder.com/modules/vscode-desktop/coder" - version = "1.0.8" + version = "1.0.15" agent_id = coder_agent.example.id folder = "/home/coder/project" } From 45456ab39426da6b084b1de2709203694497adec Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Mon, 17 Jun 2024 13:42:45 -0700 Subject: [PATCH 3/3] feat(code-server): add option to skip reinstalling extensions (#259) --- code-server/main.tf | 7 +++++++ code-server/run.sh | 26 ++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/code-server/main.tf b/code-server/main.tf index c186c14..30b705c 100644 --- a/code-server/main.tf +++ b/code-server/main.tf @@ -95,6 +95,12 @@ variable "use_cached" { default = false } +variable "use_cached_extensions" { + type = bool + description = "Uses cached copy of extensions, otherwise do a forced upgrade" + default = false +} + variable "extensions_dir" { type = string description = "Override the directory to store extensions in." @@ -122,6 +128,7 @@ resource "coder_script" "code-server" { SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""), OFFLINE : var.offline, USE_CACHED : var.use_cached, + USE_CACHED_EXTENSIONS : var.use_cached_extensions, EXTENSIONS_DIR : var.extensions_dir, FOLDER : var.folder, AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions, diff --git a/code-server/run.sh b/code-server/run.sh index c89502b..8e068b8 100755 --- a/code-server/run.sh +++ b/code-server/run.sh @@ -57,14 +57,33 @@ if [ ! -f "$CODE_SERVER" ] || [ "${USE_CACHED}" != true ]; then printf "🥳 code-server has been installed in ${INSTALL_PREFIX}\n\n" fi +# Get the list of installed extensions... +LIST_EXTENSIONS=$($CODE_SERVER --list-extensions $EXTENSION_ARG) +readarray -t EXTENSIONS_ARRAY <<< "$LIST_EXTENSIONS" +function extension_installed() { + if [ "${USE_CACHED_EXTENSIONS}" != true ]; then + return 1 + fi + for _extension in "$${EXTENSIONS_ARRAY[@]}"; do + if [ "$_extension" == "$1" ]; then + echo "Extension $1 was already installed." + return 0 + fi + done + return 1 +} + # Install each extension... IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}" for extension in "$${EXTENSIONLIST[@]}"; do if [ -z "$extension" ]; then continue fi + if extension_installed "$extension"; then + continue + fi printf "🧩 Installing extension $${CODE}$extension$${RESET}...\n" - output=$($CODE_SERVER "$EXTENSION_ARG" --install-extension "$extension") + output=$($CODE_SERVER "$EXTENSION_ARG" --force --install-extension "$extension") if [ $? -ne 0 ]; then echo "Failed to install extension: $extension: $output" exit 1 @@ -86,7 +105,10 @@ if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR" extensions=$(jq -r '.recommendations[]' "$WORKSPACE_DIR"/.vscode/extensions.json) for extension in $extensions; do - $CODE_SERVER "$EXTENSION_ARG" --install-extension "$extension" + if extension_installed "$extension"; then + continue + fi + $CODE_SERVER "$EXTENSION_ARG" --force --install-extension "$extension" done fi fi