Skip to content

Commit 6e055d6

Browse files
katorlyclaude
andcommitted
feat: update module to match upstream changes
🤖Some parts of this change were assisted by AI. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 339f018 commit 6e055d6

6 files changed

Lines changed: 83 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.terraform*
2+
refs/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Combine [Coder code-server Module](https://registry.coder.com/modules/code-serve
3535
```tf
3636
module "dotfiles-after-code-server" {
3737
source = "katorlys-samples/dotfiles-after-code-server/coder"
38-
version = "0.1.0"
38+
version = "0.1.1"
3939
agent_id = coder_agent.example.id
4040
folder = "/home/coder"
4141
}

dotfiles_run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
25
DOTFILES_URI="${DOTFILES_URI}"
36
DOTFILES_USER="${DOTFILES_USER}"
47

8+
# shellcheck disable=SC2157
59
if [ -n "$${DOTFILES_URI// }" ]; then
610
if [ -z "$DOTFILES_USER" ]; then
711
DOTFILES_USER="$USER"

main.tf

Lines changed: 8 additions & 2 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 = ">= 0.17"
7+
version = ">= 2.5"
88
}
99
}
1010
}
@@ -16,7 +16,7 @@ data "coder_parameter" "dotfiles_uri" {
1616
display_name = "Dotfiles URL"
1717
order = var.coder_parameter_order
1818
default = var.default_dotfiles_uri
19-
description = "Enter a URL for a [dotfiles repository](https://dotfiles.github.io) to personalize your workspace"
19+
description = var.description
2020
mutable = true
2121
icon = "/icon/dotfiles.svg"
2222
}
@@ -39,12 +39,14 @@ resource "coder_script" "dotfiles-after-code-server" {
3939
INSTALL_PREFIX : var.install_prefix,
4040
// This is necessary otherwise the quotes are stripped!
4141
SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""),
42+
MACHINE_SETTINGS : replace(jsonencode(var.machine-settings), "\"", "\\\""),
4243
OFFLINE : var.offline,
4344
USE_CACHED : var.use_cached,
4445
USE_CACHED_EXTENSIONS : var.use_cached_extensions,
4546
EXTENSIONS_DIR : var.extensions_dir,
4647
FOLDER : var.folder,
4748
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
49+
ADDITIONAL_ARGS : var.additional_args,
4850
DOTFILES_URI : local.dotfiles_uri,
4951
DOTFILES_USER : local.user
5052
})
@@ -72,6 +74,8 @@ resource "coder_app" "code-server" {
7274
subdomain = var.subdomain
7375
share = var.share
7476
order = var.order
77+
group = var.group
78+
open_in = var.open_in
7579

7680
healthcheck {
7781
url = "http://localhost:${var.port}/healthz"
@@ -97,6 +101,8 @@ resource "coder_app" "dotfiles" {
97101
display_name = "Refresh Dotfiles"
98102
slug = "dotfiles"
99103
icon = "/icon/dotfiles.svg"
104+
order = var.order
105+
group = var.group
100106
command = templatefile("${path.module}/dotfiles_run.sh", {
101107
DOTFILES_URI : local.dotfiles_uri,
102108
DOTFILES_USER : local.user

run.sh

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,27 @@ fi
1616
function run_code_server() {
1717
echo "👷 Running code-server in the background..."
1818
echo "Check logs at ${LOG_PATH}!"
19-
$CODE_SERVER "$EXTENSION_ARG" --auth none --port "${PORT}" --app-name "${APP_NAME}" > "${LOG_PATH}" 2>&1 &
19+
$CODE_SERVER "$EXTENSION_ARG" --auth none --port "${PORT}" --app-name "${APP_NAME}" ${ADDITIONAL_ARGS} > "${LOG_PATH}" 2>&1 &
2020
}
2121

2222
# Check if the settings file exists...
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
@@ -42,6 +55,11 @@ fi
4255
if [ ! -f "$CODE_SERVER" ] || [ "${USE_CACHED}" != true ]; then
4356
printf "$${BOLD}Installing code-server!\n"
4457

58+
# Clean up from other install (in case install prefix changed).
59+
if [ -n "$CODER_SCRIPT_BIN_DIR" ] && [ -e "$CODER_SCRIPT_BIN_DIR/code-server" ]; then
60+
rm "$CODER_SCRIPT_BIN_DIR/code-server"
61+
fi
62+
4563
ARGS=(
4664
"--method=standalone"
4765
"--prefix=${INSTALL_PREFIX}"
@@ -58,13 +76,19 @@ if [ ! -f "$CODE_SERVER" ] || [ "${USE_CACHED}" != true ]; then
5876
printf "🥳 code-server has been installed in ${INSTALL_PREFIX}\n\n"
5977
fi
6078

79+
# Make the code-server available in PATH.
80+
if [ -n "$CODER_SCRIPT_BIN_DIR" ] && [ ! -e "$CODER_SCRIPT_BIN_DIR/code-server" ]; then
81+
ln -s "$CODE_SERVER" "$CODER_SCRIPT_BIN_DIR/code-server"
82+
fi
83+
6184
# Get the list of installed extensions...
6285
LIST_EXTENSIONS=$($CODE_SERVER --list-extensions $EXTENSION_ARG)
6386
readarray -t EXTENSIONS_ARRAY <<< "$LIST_EXTENSIONS"
6487
function extension_installed() {
6588
if [ "${USE_CACHED_EXTENSIONS}" != true ]; then
6689
return 1
6790
fi
91+
# shellcheck disable=SC2066
6892
for _extension in "$${EXTENSIONS_ARRAY[@]}"; do
6993
if [ "$_extension" == "$1" ]; then
7094
echo "Extension $1 was already installed."
@@ -76,6 +100,7 @@ function extension_installed() {
76100

77101
# Install each extension...
78102
IFS=',' read -r -a EXTENSIONLIST <<< "$${EXTENSIONS}"
103+
# shellcheck disable=SC2066
79104
for extension in "$${EXTENSIONLIST[@]}"; do
80105
if [ -z "$extension" ]; then
81106
continue
@@ -104,7 +129,8 @@ if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then
104129

105130
if [ -f "$WORKSPACE_DIR/.vscode/extensions.json" ]; then
106131
printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR"
107-
extensions=$(jq -r '.recommendations[]' "$WORKSPACE_DIR"/.vscode/extensions.json)
132+
# Use sed to remove single-line comments before parsing with jq
133+
extensions=$(sed 's|//.*||g' "$WORKSPACE_DIR"/.vscode/extensions.json | jq -r '.recommendations[]')
108134
for extension in $extensions; do
109135
if extension_installed "$extension"; then
110136
continue
@@ -121,6 +147,7 @@ run_code_server
121147
DOTFILES_URI="${DOTFILES_URI}"
122148
DOTFILES_USER="${DOTFILES_USER}"
123149

150+
# shellcheck disable=SC2157
124151
if [ -n "$${DOTFILES_URI// }" ]; then
125152
if [ -z "$DOTFILES_USER" ]; then
126153
DOTFILES_USER="$USER"

variables.tf

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ variable "slug" {
2828
}
2929

3030
variable "settings" {
31-
type = map(string)
31+
type = any
3232
description = "A map of settings to apply to code-server."
3333
default = {}
3434
}
3535

36+
variable "machine-settings" {
37+
type = any
38+
description = "A map of template level machine settings to apply to code-server. This will be overwritten at each container start."
39+
default = {}
40+
}
41+
3642
variable "folder" {
3743
type = string
3844
description = "The folder to open in code-server."
@@ -72,6 +78,12 @@ variable "order" {
7278
default = null
7379
}
7480

81+
variable "group" {
82+
type = string
83+
description = "The name of a group that this app belongs to."
84+
default = null
85+
}
86+
7587
variable "offline" {
7688
type = bool
7789
description = "Just run code-server in the background, don't fetch it from GitHub"
@@ -111,12 +123,38 @@ variable "subdomain" {
111123
default = false
112124
}
113125

126+
variable "open_in" {
127+
type = string
128+
description = <<-EOT
129+
Determines where the app will be opened. Valid values are "tab" and "slim-window" (default).
130+
"tab" opens in a new tab in the same browser window.
131+
"slim-window" opens a new browser window without navigation controls.
132+
EOT
133+
default = "slim-window"
134+
validation {
135+
condition = contains(["tab", "slim-window"], var.open_in)
136+
error_message = "The 'open_in' variable must be one of: 'tab', 'slim-window'."
137+
}
138+
}
139+
140+
variable "additional_args" {
141+
type = string
142+
description = "Additional command-line arguments to pass to code-server (e.g., '--disable-workspace-trust')."
143+
default = ""
144+
}
145+
114146
variable "default_dotfiles_uri" {
115147
type = string
116148
description = "The default dotfiles URI if the workspace user does not provide one"
117149
default = ""
118150
}
119151

152+
variable "description" {
153+
type = string
154+
description = "A custom description for the dotfiles parameter. This is shown in the UI - and allows you to customize the instructions you give to your users."
155+
default = "Enter a URL for a [dotfiles repository](https://dotfiles.github.io) to personalize your workspace"
156+
}
157+
120158
variable "dotfiles_uri" {
121159
type = string
122160
description = "The URL to a dotfiles repository. (optional, when set, the user isn't prompted for their dotfiles)"

0 commit comments

Comments
 (0)