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

Commit e1575da

Browse files
committed
feat(code-server): Machine Settings option
1 parent 3c81321 commit e1575da

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

code-server/main.tf

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
coder = {
66
source = "coder/coder"
7-
version = ">= 2.1"
7+
version = ">= 0.17"
88
}
99
}
1010
}
@@ -39,11 +39,17 @@ variable "slug" {
3939
}
4040

4141
variable "settings" {
42-
type = any
42+
type = map(string)
4343
description = "A map of settings to apply to code-server."
4444
default = {}
4545
}
4646

47+
variable "machine-settings" {
48+
type = map(string)
49+
description = "A map of template level machine settings to apply to code-server. This will be overwritten at each container start."
50+
default = {}
51+
}
52+
4753
variable "folder" {
4854
type = string
4955
description = "The folder to open in code-server."
@@ -122,20 +128,6 @@ variable "subdomain" {
122128
default = false
123129
}
124130

125-
variable "open_in" {
126-
type = string
127-
description = <<-EOT
128-
Determines where the app will be opened. Valid values are `"tab"` and `"slim-window" (default)`.
129-
`"tab"` opens in a new tab in the same browser window.
130-
`"slim-window"` opens a new browser window without navigation controls.
131-
EOT
132-
default = "slim-window"
133-
validation {
134-
condition = contains(["tab", "slim-window"], var.open_in)
135-
error_message = "The 'open_in' variable must be one of: 'tab', 'slim-window'."
136-
}
137-
}
138-
139131
resource "coder_script" "code-server" {
140132
agent_id = var.agent_id
141133
display_name = "code-server"
@@ -149,6 +141,7 @@ resource "coder_script" "code-server" {
149141
INSTALL_PREFIX : var.install_prefix,
150142
// This is necessary otherwise the quotes are stripped!
151143
SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""),
144+
MACHINE_SETTINGS : replace(jsonencode(var.machine-settings), "\"", "\\\""),
152145
OFFLINE : var.offline,
153146
USE_CACHED : var.use_cached,
154147
USE_CACHED_EXTENSIONS : var.use_cached_extensions,
@@ -180,7 +173,6 @@ resource "coder_app" "code-server" {
180173
subdomain = var.subdomain
181174
share = var.share
182175
order = var.order
183-
open_in = var.open_in
184176

185177
healthcheck {
186178
url = "http://localhost:${var.port}/healthz"

code-server/run.sh

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ if [ ! -f ~/.local/share/code-server/User/settings.json ]; then
2626
echo "${SETTINGS}" > ~/.local/share/code-server/User/settings.json
2727
fi
2828

29+
# Apply/overwrite template based settings
30+
echo "⚙️ Creating machine settings file..."
31+
mkdir -p ~/.local/share/code-server/Machine
32+
echo "${MACHINE_SETTINGS}" > ~/.local/share/code-server/Machine/settings.json
33+
2934
# Check if code-server is already installed for offline
3035
if [ "${OFFLINE}" = true ]; then
3136
if [ -f "$CODE_SERVER" ]; then
@@ -42,11 +47,6 @@ fi
4247
if [ ! -f "$CODE_SERVER" ] || [ "${USE_CACHED}" != true ]; then
4348
printf "$${BOLD}Installing code-server!\n"
4449

45-
# Clean up from other install (in case install prefix changed).
46-
if [ -n "$CODER_SCRIPT_BIN_DIR" ] && [ -e "$CODER_SCRIPT_BIN_DIR/code-server" ]; then
47-
rm "$CODER_SCRIPT_BIN_DIR/code-server"
48-
fi
49-
5050
ARGS=(
5151
"--method=standalone"
5252
"--prefix=${INSTALL_PREFIX}"
@@ -63,11 +63,6 @@ if [ ! -f "$CODE_SERVER" ] || [ "${USE_CACHED}" != true ]; then
6363
printf "🥳 code-server has been installed in ${INSTALL_PREFIX}\n\n"
6464
fi
6565

66-
# Make the code-server available in PATH.
67-
if [ -n "$CODER_SCRIPT_BIN_DIR" ] && [ ! -e "$CODER_SCRIPT_BIN_DIR/code-server" ]; then
68-
ln -s "$CODE_SERVER" "$CODER_SCRIPT_BIN_DIR/code-server"
69-
fi
70-
7166
# Get the list of installed extensions...
7267
LIST_EXTENSIONS=$($CODE_SERVER --list-extensions $EXTENSION_ARG)
7368
readarray -t EXTENSIONS_ARRAY <<< "$LIST_EXTENSIONS"
@@ -114,8 +109,7 @@ if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then
114109

115110
if [ -f "$WORKSPACE_DIR/.vscode/extensions.json" ]; then
116111
printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR"
117-
# Use sed to remove single-line comments before parsing with jq
118-
extensions=$(sed 's|//.*||g' "$WORKSPACE_DIR"/.vscode/extensions.json | jq -r '.recommendations[]')
112+
extensions=$(jq -r '.recommendations[]' "$WORKSPACE_DIR"/.vscode/extensions.json)
119113
for extension in $extensions; do
120114
if extension_installed "$extension"; then
121115
continue

0 commit comments

Comments
 (0)