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

Commit 45456ab

Browse files
feat(code-server): add option to skip reinstalling extensions (#259)
1 parent c652dbe commit 45456ab

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

code-server/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ variable "use_cached" {
9595
default = false
9696
}
9797

98+
variable "use_cached_extensions" {
99+
type = bool
100+
description = "Uses cached copy of extensions, otherwise do a forced upgrade"
101+
default = false
102+
}
103+
98104
variable "extensions_dir" {
99105
type = string
100106
description = "Override the directory to store extensions in."
@@ -122,6 +128,7 @@ resource "coder_script" "code-server" {
122128
SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""),
123129
OFFLINE : var.offline,
124130
USE_CACHED : var.use_cached,
131+
USE_CACHED_EXTENSIONS : var.use_cached_extensions,
125132
EXTENSIONS_DIR : var.extensions_dir,
126133
FOLDER : var.folder,
127134
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,

code-server/run.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,33 @@ if [ ! -f "$CODE_SERVER" ] || [ "${USE_CACHED}" != true ]; then
5757
printf "🥳 code-server has been installed in ${INSTALL_PREFIX}\n\n"
5858
fi
5959

60+
# Get the list of installed extensions...
61+
LIST_EXTENSIONS=$($CODE_SERVER --list-extensions $EXTENSION_ARG)
62+
readarray -t EXTENSIONS_ARRAY <<< "$LIST_EXTENSIONS"
63+
function extension_installed() {
64+
if [ "${USE_CACHED_EXTENSIONS}" != true ]; then
65+
return 1
66+
fi
67+
for _extension in "$${EXTENSIONS_ARRAY[@]}"; do
68+
if [ "$_extension" == "$1" ]; then
69+
echo "Extension $1 was already installed."
70+
return 0
71+
fi
72+
done
73+
return 1
74+
}
75+
6076
# Install each extension...
6177
IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}"
6278
for extension in "$${EXTENSIONLIST[@]}"; do
6379
if [ -z "$extension" ]; then
6480
continue
6581
fi
82+
if extension_installed "$extension"; then
83+
continue
84+
fi
6685
printf "🧩 Installing extension $${CODE}$extension$${RESET}...\n"
67-
output=$($CODE_SERVER "$EXTENSION_ARG" --install-extension "$extension")
86+
output=$($CODE_SERVER "$EXTENSION_ARG" --force --install-extension "$extension")
6887
if [ $? -ne 0 ]; then
6988
echo "Failed to install extension: $extension: $output"
7089
exit 1
@@ -86,7 +105,10 @@ if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then
86105
printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR"
87106
extensions=$(jq -r '.recommendations[]' "$WORKSPACE_DIR"/.vscode/extensions.json)
88107
for extension in $extensions; do
89-
$CODE_SERVER "$EXTENSION_ARG" --install-extension "$extension"
108+
if extension_installed "$extension"; then
109+
continue
110+
fi
111+
$CODE_SERVER "$EXTENSION_ARG" --force --install-extension "$extension"
90112
done
91113
fi
92114
fi

0 commit comments

Comments
 (0)