-
Notifications
You must be signed in to change notification settings - Fork 58
feat(vscode-web): add offline, use_cached, extensions_dir and auto_install_extensions #235
Changes from all commits
f908e45
23ff3ca
27a1def
dcc1f66
d509b81
1d9585c
5685613
b78593c
c6857f7
cc614e7
b8ebdc9
1462d66
a367517
9bb4b82
b74a61c
b00b47c
0605dce
3c0c133
4c016da
2d43c2c
ffe9114
2d15e4b
10f9f15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { describe, expect, it } from "bun:test"; | ||
import { runTerraformApply, runTerraformInit } from "../test"; | ||
|
||
describe("vscode-web", async () => { | ||
await runTerraformInit(import.meta.dir); | ||
|
||
it("accept_license should be set to true", () => { | ||
const t = async () => { | ||
await runTerraformApply(import.meta.dir, { | ||
agent_id: "foo", | ||
accept_license: "false", | ||
}); | ||
}; | ||
expect(t).toThrow("Invalid value for variable"); | ||
}); | ||
|
||
it("use_cached and offline can not be used together", () => { | ||
const t = async () => { | ||
await runTerraformApply(import.meta.dir, { | ||
agent_id: "foo", | ||
accept_license: "true", | ||
use_cached: "true", | ||
offline: "true", | ||
}); | ||
}; | ||
expect(t).toThrow("Offline and Use Cached can not be used together"); | ||
}); | ||
|
||
it("offline and extensions can not be used together", () => { | ||
const t = async () => { | ||
await runTerraformApply(import.meta.dir, { | ||
agent_id: "foo", | ||
accept_license: "true", | ||
offline: "true", | ||
extensions: '["1", "2"]', | ||
}); | ||
}; | ||
expect(t).toThrow("Offline mode does not allow extensions to be installed"); | ||
}); | ||
|
||
// More tests depend on shebang refactors | ||
}); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,40 @@ | |||||
|
||||||
BOLD='\033[0;1m' | ||||||
EXTENSIONS=("${EXTENSIONS}") | ||||||
VSCODE_WEB="${INSTALL_PREFIX}/bin/code-server" | ||||||
|
||||||
# Set extension directory | ||||||
EXTENSION_ARG="" | ||||||
if [ -n "${EXTENSIONS_DIR}" ]; then | ||||||
EXTENSION_ARG="--extensions-dir=${EXTENSIONS_DIR}" | ||||||
fi | ||||||
|
||||||
run_vscode_web() { | ||||||
echo "👷 Running $VSCODE_WEB serve-local $EXTENSION_ARG --port ${PORT} --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} in the background..." | ||||||
echo "Check logs at ${LOG_PATH}!" | ||||||
"$VSCODE_WEB" serve-local "$EXTENSION_ARG" --port "${PORT}" --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 & | ||||||
} | ||||||
|
||||||
# Check if the settings file exists... | ||||||
if [ ! -f ~/.vscode-server/data/Machine/settings.json ]; then | ||||||
echo "⚙️ Creating settings file..." | ||||||
mkdir -p ~/.vscode-server/data/Machine | ||||||
echo "${SETTINGS}" > ~/.vscode-server/data/Machine/settings.json | ||||||
fi | ||||||
|
||||||
# Check if vscode-server is already installed for offline or cached mode | ||||||
if [ -f "$VSCODE_WEB" ]; then | ||||||
if [ "${OFFLINE}" = true ] || [ "${USE_CACHED}" = true ]; then | ||||||
michaelbrewer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
echo "🥳 Found a copy of VS Code Web" | ||||||
run_vscode_web | ||||||
exit 0 | ||||||
fi | ||||||
fi | ||||||
# Offline mode always expects a copy of vscode-server to be present | ||||||
if [ "${OFFLINE}" = true ]; then | ||||||
echo "Failed to find a copy of VS Code Web" | ||||||
exit 1 | ||||||
fi | ||||||
|
||||||
# Create install prefix | ||||||
mkdir -p ${INSTALL_PREFIX} | ||||||
|
@@ -26,9 +60,7 @@ if [ $? -ne 0 ]; then | |||||
echo "Failed to install Microsoft Visual Studio Code Server: $output" | ||||||
exit 1 | ||||||
fi | ||||||
printf "$${BOLD}Microsoft Visual Studio Code Server has been installed.\n" | ||||||
|
||||||
VSCODE_SERVER="${INSTALL_PREFIX}/bin/code-server" | ||||||
printf "$${BOLD}VS Code Web has been installed.\n" | ||||||
|
||||||
# Install each extension... | ||||||
IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}" | ||||||
|
@@ -37,20 +69,31 @@ for extension in "$${EXTENSIONLIST[@]}"; do | |||||
continue | ||||||
fi | ||||||
printf "🧩 Installing extension $${CODE}$extension$${RESET}...\n" | ||||||
output=$($VSCODE_SERVER --install-extension "$extension" --force) | ||||||
output=$($VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force) | ||||||
if [ $? -ne 0 ]; then | ||||||
echo "Failed to install extension: $extension: $output" | ||||||
exit 1 | ||||||
fi | ||||||
done | ||||||
|
||||||
# Check if the settings file exists... | ||||||
if [ ! -f ~/.vscode-server/data/Machine/settings.json ]; then | ||||||
echo "⚙️ Creating settings file..." | ||||||
mkdir -p ~/.vscode-server/data/Machine | ||||||
echo "${SETTINGS}" > ~/.vscode-server/data/Machine/settings.json | ||||||
if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then | ||||||
if ! command -v jq > /dev/null; then | ||||||
echo "jq is required to install extensions from a workspace file." | ||||||
exit 0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just occurred to me, should this be considered a failure?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure. From a user perspective it would be nice to continue without an error and print a warning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess there is where monitoring works when errors happen in a large deployment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't prevent the workspace from starting but does show a warning on the page that the script was not successful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh gotcha yeah There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine. If we don't fine jw we should just skip installing extensions and continue with the rest of the script. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have mixed feelings about it, because enabling autoinstall without On the other hand, it does seem annoying as a user that I cannot launch VS Code just because someone forgot to install stderr gets highlighted in the terminal, right? Maybe we output to stderr and then keep going. Also if we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will try the node to in another PR. |
||||||
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) | ||||||
michaelbrewer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
for extension in $extensions; do | ||||||
$VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force | ||||||
done | ||||||
fi | ||||||
fi | ||||||
|
||||||
echo "👷 Running ${INSTALL_PREFIX}/bin/code-server serve-local --port ${PORT} --host 127.0.0.1 --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}" --host 127.0.0.1 --accept-server-license-terms serve-local --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 & | ||||||
run_vscode_web |
Uh oh!
There was an error while loading. Please reload this page.