feat(code-server): add code-server offline support

pull/184/head
Michael Brewer 1 year ago
parent c3d1b4125e
commit dc00049030
No known key found for this signature in database
GPG Key ID: D7A137BA1254AFC7

@ -83,6 +83,12 @@ variable "order" {
default = null default = null
} }
variable "offline" {
type = bool
description = "Just run code-server in the background, don't fetch it from GitHub"
default = false
}
resource "coder_script" "code-server" { resource "coder_script" "code-server" {
agent_id = var.agent_id agent_id = var.agent_id
display_name = "code-server" display_name = "code-server"
@ -96,6 +102,7 @@ resource "coder_script" "code-server" {
INSTALL_PREFIX : var.install_prefix, INSTALL_PREFIX : var.install_prefix,
// This is necessary otherwise the quotes are stripped! // This is necessary otherwise the quotes are stripped!
SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""), SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""),
OFFLINE : var.offline,
}) })
run_on_start = true run_on_start = true
} }

@ -4,6 +4,20 @@ EXTENSIONS=("${EXTENSIONS}")
BOLD='\033[0;1m' BOLD='\033[0;1m'
CODE='\033[36;40;1m' CODE='\033[36;40;1m'
RESET='\033[0m' RESET='\033[0m'
CODE_SERVER="${INSTALL_PREFIX}/bin/code-server"
# Check if the settings file exists...
if [ ! -f ~/.local/share/code-server/User/settings.json ]; then
echo "⚙️ Creating settings file..."
mkdir -p ~/.local/share/code-server/User
echo "${SETTINGS}" > ~/.local/share/code-server/User/settings.json
fi
if [ "${OFFLINE}" = true ]; then
echo "👷 Running code-server in offline mode..."
$CODE_SERVER --auth none --port ${PORT} --app-name "${APP_NAME}" > ${LOG_PATH} 2>&1 &
exit 0
fi
printf "$${BOLD}Installing code-server!\n" printf "$${BOLD}Installing code-server!\n"
@ -22,8 +36,6 @@ if [ $? -ne 0 ]; then
fi fi
printf "🥳 code-server has been installed in ${INSTALL_PREFIX}\n\n" printf "🥳 code-server has been installed in ${INSTALL_PREFIX}\n\n"
CODE_SERVER="${INSTALL_PREFIX}/bin/code-server"
# Install each extension... # Install each extension...
IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}" IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}"
for extension in "$${EXTENSIONLIST[@]}"; do for extension in "$${EXTENSIONLIST[@]}"; do
@ -38,13 +50,6 @@ for extension in "$${EXTENSIONLIST[@]}"; do
fi fi
done done
# Check if the settings file exists...
if [ ! -f ~/.local/share/code-server/User/settings.json ]; then
echo "⚙️ Creating settings file..."
mkdir -p ~/.local/share/code-server/User
echo "${SETTINGS}" > ~/.local/share/code-server/User/settings.json
fi
echo "👷 Running code-server in the background..." echo "👷 Running code-server in the background..."
echo "Check logs at ${LOG_PATH}!" echo "Check logs at ${LOG_PATH}!"
$CODE_SERVER --auth none --port ${PORT} --app-name "${APP_NAME}" > ${LOG_PATH} 2>&1 & $CODE_SERVER --auth none --port ${PORT} --app-name "${APP_NAME}" > ${LOG_PATH} 2>&1 &

Loading…
Cancel
Save