8000 feat(code-server): add machine settings option (#88) · coder/registry@84f3cb5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84f3cb5

Browse files
authored
feat(code-server): add machine settings option (#88)
Should resolve #27 The goal is to provide a method for template owners to configure default `Machine Settings` that can be overridden by developers via `User Settings` and repositories via `Workspace Settings`. This option allows template owners to push new settings options with a template release that would not be ignored because the setting file already exists. This also formats the `settings.json` file if `jq` is installed. Eventually, I would imagine the current `settings` option will be depreciated in favor of this option.
1 parent 6718a28 commit 84f3cb5

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

registry/coder/modules/code-server/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ variable "settings" {
4444
default = {}
4545
}
4646

47+
variable "machine-settings" {
48+
type = any
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."
@@ -149,6 +155,7 @@ resource "coder_script" "code-server" {
149155
INSTALL_PREFIX : var.install_prefix,
150156
// This is necessary otherwise the quotes are stripped!
151157
SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""),
158+
MACHINE_SETTINGS : replace(jsonencode(var.machine-settings), "\"", "\\\""),
152159
OFFLINE : var.offline,
153160
USE_CACHED : var.use_cached,
154161
USE_CACHED_EXTENSIONS : var.use_cached_extensions,

registry/coder/modules/code-server/run.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,20 @@ function run_code_server() {
2323
if [ ! -f ~/.local/share/code-server/User/settings.json ]; then
2424
echo "⚙️ Creating settings file..."
2525
mkdir -p ~/.local/share/code-server/User
26-
echo "${SETTINGS}" > ~/.local/share/code-server/User/settings.json
26+
if command -v jq &> /dev/null; then
27+
echo "${SETTINGS}" | jq '.' > ~/.local/share/code-server/User/settings.json
28+
else
29+
echo "${SETTINGS}" > ~/.local/share/code-server/User/settings.json
30+
fi
31+
fi
32+
33+
# Apply/overwrite template based settings
34+
echo "⚙️ Creating machine settings file..."
35+
mkdir -p ~/.local/share/code-server/Machine
36+
if command -v jq &> /dev/null; then
37+
echo "${MACHINE_SETTINGS}" | jq '.' > ~/.local/share/code-server/Machine/settings.json
38+
else
39+
echo "${MACHINE_SETTINGS}" > ~/.local/share/code-server/Machine/settings.json
2740
fi
2841

2942
# Check if code-server is already installed for offline

0 commit comments

Comments
 (0)
0