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

feat(code-server): install extensions from .vscode/extensions.json #231

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions code-server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ variable "extensions_dir" {
default = ""
}

variable "auto_install_extensions" {
type = bool
description = "Automatically install recommended extensions when code-server starts."
default = false
}

resource "coder_script" "code-server" {
agent_id = var.agent_id
display_name = "code-server"
Expand All @@ -117,6 +123,8 @@ resource "coder_script" "code-server" {
OFFLINE : var.offline,
USE_CACHED : var.use_cached,
EXTENSIONS_DIR : var.extensions_dir,
FOLDER : var.folder,
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
})
run_on_start = true

Expand Down
20 changes: 20 additions & 0 deletions code-server/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,24 @@ for extension in "$${EXTENSIONLIST[@]}"; do
fi
done

if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then
if ! command -v jq > /dev/null; then
echo "jq is required to install extensions from a workspace file."
Copy link
Member

@code-asher code-asher Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is overkill, but we could use the Node bundled with code-server.

extensions=$("$INSTALL_PREFIX/lib/node" -e "require(\"$WORKSPACE_DIR/.vscode/extensions.json\").recommendations.forEach((r) => console.log(r))")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I do like jq, but if we know the path to node and it should always be present, then it makes sense.

exit 0
fi

WORKSPACE_DIR="$HOME"
if [ -n "${FOLDER}" ]; then
WORKSPACE_DIR="${FOLDER}"
fi

if [ -f "$WORKSPACE_DIR/.vscode/extensions.json" ]; 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"
done
fi
fi

run_code_server