Skip to content

Commit 240643d

Browse files
feat: remove node installation from gemini (#374)
Closes # ## Description Standardising this across all modules: - remove default node & nvm installation <!-- Briefly describe what this PR does and why --> ## Type of Change - [ ] New module - [ ] Bug fix - [x] Feature/enhancement - [ ] Documentation - [ ] Other ## Module Information <!-- Delete this section if not applicable --> **Path:** `registry/coder-labs/modules/gemini` **New version:** `v2.0.0` **Breaking change:** [x] Yes [ ] No ## Testing & Validation - [x] Tests pass (`bun test`) - [x] Code formatted (`bun run fmt`) - [ ] Changes tested locally ## Related Issues <!-- Link related issues or write "None" if not applicable --> --------- Co-authored-by: DevCats <[email protected]>
1 parent 68f881e commit 240643d

File tree

4 files changed

+132
-144
lines changed

4 files changed

+132
-144
lines changed

registry/coder-labs/modules/gemini/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Run [Gemini CLI](https://github.com/google-gemini/gemini-cli) in your workspace
1313
```tf
1414
module "gemini" {
1515
source = "registry.coder.com/coder-labs/gemini/coder"
16-
version = "1.1.0"
16+
version = "2.0.0"
1717
agent_id = coder_agent.example.id
1818
folder = "/home/coder/project"
1919
}
@@ -30,7 +30,7 @@ module "gemini" {
3030

3131
## Prerequisites
3232

33-
- Node.js and npm will be installed automatically if not present
33+
- **Node.js and npm must be sourced/available before the gemini module installs** - ensure they are installed in your workspace image or via earlier provisioning steps
3434
- The [Coder Login](https://registry.coder.com/modules/coder/coder-login) module is required
3535

3636
## Examples
@@ -46,7 +46,7 @@ variable "gemini_api_key" {
4646
4747
module "gemini" {
4848
source = "registry.coder.com/coder-labs/gemini/coder"
49-
version = "1.1.0"
49+
version = "2.0.0"
5050
agent_id = coder_agent.example.id
5151
gemini_api_key = var.gemini_api_key
5252
folder = "/home/coder/project"
@@ -94,7 +94,7 @@ data "coder_parameter" "ai_prompt" {
9494
module "gemini" {
9595
count = data.coder_workspace.me.start_count
9696
source = "registry.coder.com/coder-labs/gemini/coder"
97-
version = "1.1.0"
97+
version = "2.0.0"
9898
agent_id = coder_agent.example.id
9999
gemini_api_key = var.gemini_api_key
100100
gemini_model = "gemini-2.5-flash"
@@ -118,7 +118,7 @@ For enterprise users who prefer Google's Vertex AI platform:
118118
```tf
119119
module "gemini" {
120120
source = "registry.coder.com/coder-labs/gemini/coder"
121-
version = "1.1.0"
121+
version = "2.0.0"
122122
agent_id = coder_agent.example.id
123123
gemini_api_key = var.gemini_api_key
124124
folder = "/home/coder/project"

registry/coder-labs/modules/gemini/main.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe("gemini", async () => {
153153
},
154154
});
155155
await execModuleScript(id);
156-
const resp = await readFileContainer(id, "/home/coder/.gemini-module/install.log");
156+
const resp = await readFileContainer(id, "/home/coder/.gemini-module/agentapi-start.log");
157157
expect(resp).toContain('GOOGLE_GENAI_USE_VERTEXAI=\'true\'');
158158
});
159159

@@ -166,7 +166,7 @@ describe("gemini", async () => {
166166
},
167167
});
168168
await execModuleScript(id);
169-
const resp = await readFileContainer(id, "/home/coder/.gemini-module/install.log");
169+
const resp = await readFileContainer(id, "/home/coder/.gemini-module/agentapi-start.log");
170170
expect(resp).toContain(model);
171171
});
172172

@@ -193,7 +193,7 @@ describe("gemini", async () => {
193193
},
194194
});
195195
await execModuleScript(id);
196-
const resp = await readFileContainer(id, "/home/coder/.gemini-module/install.log");
196+
const resp = await readFileContainer(id, "/home/coder/.gemini-module/agentapi-start.log");
197197
expect(resp).toContain(folder);
198198
});
199199

Lines changed: 90 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22

33
BOLD='\033[0;1m'
4-
4+
source "$HOME"/.bashrc
55
command_exists() {
6-
command -v "$1" >/dev/null 2>&1
6+
command -v "$1" > /dev/null 2>&1
77
}
88

99
set -o nounset
@@ -21,144 +21,132 @@ echo "--------------------------------"
2121

2222
set +o nounset
2323

24-
function install_node() {
25-
if ! command_exists npm; then
26-
printf "npm not found, checking for Node.js installation...\n"
27-
if ! command_exists node; then
28-
printf "Node.js not found, installing Node.js via NVM...\n"
29-
export NVM_DIR="$HOME/.nvm"
30-
if [ ! -d "$NVM_DIR" ]; then
31-
mkdir -p "$NVM_DIR"
32-
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
33-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
34-
else
35-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
36-
fi
37-
38-
nvm install --lts
39-
nvm use --lts
40-
nvm alias default node
41-
42-
printf "Node.js installed: %s\n" "$(node --version)"
43-
printf "npm installed: %s\n" "$(npm --version)"
44-
else
45-
printf "Node.js is installed but npm is not available. Please install npm manually.\n"
46-
exit 1
47-
fi
48-
fi
24+
function check_dependencies() {
25+
if ! command_exists node; then
26+
printf "Error: Node.js is not installed. Please install Node.js manually or use the pre_install_script to install it.\n"
27+
exit 1
28+
fi
29+
30+
if ! command_exists npm; then
31+
printf "Error: npm is not installed. Please install npm manually or use the pre_install_script to install it.\n"
32+
exit 1
33+
fi
34+
35+
printf "Node.js version: %s\n" "$(node --version)"
36+
printf "npm version: %s\n" "$(npm --version)"
4937
}
5038

5139
function install_gemini() {
5240
if [ "${ARG_INSTALL}" = "true" ]; then
53-
install_node
54-
55-
if ! command_exists nvm; then
56-
printf "which node: %s\n" "$(which node)"
57-
printf "which npm: %s\n" "$(which npm)"
58-
59-
mkdir -p "$HOME"/.npm-global
60-
npm config set prefix "$HOME/.npm-global"
61-
export PATH="$HOME/.npm-global/bin:$PATH"
62-
if ! grep -q "export PATH=$HOME/.npm-global/bin:\$PATH" ~/.bashrc; then
63-
echo "export PATH=$HOME/.npm-global/bin:\$PATH" >> ~/.bashrc
64-
fi
65-
fi
41+
check_dependencies
6642

6743
printf "%s Installing Gemini CLI\n" "${BOLD}"
6844

45+
NPM_GLOBAL_PREFIX="${HOME}/.npm-global"
46+
if [ ! -d "$NPM_GLOBAL_PREFIX" ]; then
47+
mkdir -p "$NPM_GLOBAL_PREFIX"
48+
fi
49+
50+
npm config set prefix "$NPM_GLOBAL_PREFIX"
51+
52+
export PATH="$NPM_GLOBAL_PREFIX/bin:$PATH"
53+
6954
if [ -n "$ARG_GEMINI_VERSION" ]; then
7055
npm install -g "@google/gemini-cli@$ARG_GEMINI_VERSION"
7156
else
7257
npm install -g "@google/gemini-cli"
7358
fi
59+
60+
if ! grep -q "export PATH=\"\$HOME/.npm-global/bin:\$PATH\"" "$HOME/.bashrc"; then
61+
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> "$HOME/.bashrc"
62+
fi
63+
7464
printf "%s Successfully installed Gemini CLI. Version: %s\n" "${BOLD}" "$(gemini --version)"
7565
fi
7666
}
7767

7868
function populate_settings_json() {
79-
if [ "${ARG_GEMINI_CONFIG}" != "" ]; then
80-
SETTINGS_PATH="$HOME/.gemini/settings.json"
81-
mkdir -p "$(dirname "$SETTINGS_PATH")"
82-
printf "Custom gemini_config is provided !\n"
83-
echo "${ARG_GEMINI_CONFIG}" > "$HOME/.gemini/settings.json"
84-
else
85-
printf "No custom gemini_config provided, using default settings.json.\n"
86-
append_extensions_to_settings_json
87-
fi
88-
}
89-
90-
function append_extensions_to_settings_json() {
69+
if [ "${ARG_GEMINI_CONFIG}" != "" ]; then
9170
SETTINGS_PATH="$HOME/.gemini/settings.json"
9271
mkdir -p "$(dirname "$SETTINGS_PATH")"
93-
printf "[append_extensions_to_settings_json] Starting extension merge process...\n"
94-
if [ -z "${BASE_EXTENSIONS:-}" ]; then
95-
printf "[append_extensions_to_settings_json] BASE_EXTENSIONS is empty, skipping merge.\n"
96-
return
97-
fi
98-
if [ ! -f "$SETTINGS_PATH" ]; then
99-
printf "%s does not exist. Creating with merged mcpServers structure.\n" "$SETTINGS_PATH"
100-
ADD_EXT_JSON='{}'
101-
if [ -n "${ADDITIONAL_EXTENSIONS:-}" ]; then
102-
ADD_EXT_JSON="$ADDITIONAL_EXTENSIONS"
103-
fi
104-
printf '{"mcpServers":%s}\n' "$(jq -s 'add' <(echo "$BASE_EXTENSIONS") <(echo "$ADD_EXT_JSON"))" > "$SETTINGS_PATH"
105-
fi
72+
printf "Custom gemini_config is provided !\n"
73+
echo "${ARG_GEMINI_CONFIG}" > "$HOME/.gemini/settings.json"
74+
else
75+
printf "No custom gemini_config provided, using default settings.json.\n"
76+
append_extensions_to_settings_json
77+
fi
78+
}
10679

107-
TMP_SETTINGS=$(mktemp)
80+
function append_extensions_to_settings_json() {
81+
SETTINGS_PATH="$HOME/.gemini/settings.json"
82+
mkdir -p "$(dirname "$SETTINGS_PATH")"
83+
printf "[append_extensions_to_settings_json] Starting extension merge process...\n"
84+
if [ -z "${BASE_EXTENSIONS:-}" ]; then
85+
printf "[append_extensions_to_settings_json] BASE_EXTENSIONS is empty, skipping merge.\n"
86+
return
87+
fi
88+
if [ ! -f "$SETTINGS_PATH" ]; then
89+
printf "%s does not exist. Creating with merged mcpServers structure.\n" "$SETTINGS_PATH"
10890
ADD_EXT_JSON='{}'
10991
if [ -n "${ADDITIONAL_EXTENSIONS:-}" ]; then
110-
printf "[append_extensions_to_settings_json] ADDITIONAL_EXTENSIONS is set.\n"
11192
ADD_EXT_JSON="$ADDITIONAL_EXTENSIONS"
112-
else
113-
printf "[append_extensions_to_settings_json] ADDITIONAL_EXTENSIONS is empty or not set.\n"
11493
fi
94+
printf '{"mcpServers":%s}\n' "$(jq -s 'add' <(echo "$BASE_EXTENSIONS") <(echo "$ADD_EXT_JSON"))" > "$SETTINGS_PATH"
95+
fi
96+
97+
TMP_SETTINGS=$(mktemp)
98+
ADD_EXT_JSON='{}'
99+
if [ -n "${ADDITIONAL_EXTENSIONS:-}" ]; then
100+
printf "[append_extensions_to_settings_json] ADDITIONAL_EXTENSIONS is set.\n"
101+
ADD_EXT_JSON="$ADDITIONAL_EXTENSIONS"
102+
else
103+
printf "[append_extensions_to_settings_json] ADDITIONAL_EXTENSIONS is empty or not set.\n"
104+
fi
115105

116-
printf "[append_extensions_to_settings_json] Merging BASE_EXTENSIONS and ADDITIONAL_EXTENSIONS into mcpServers...\n"
117-
jq --argjson base "$BASE_EXTENSIONS" --argjson add "$ADD_EXT_JSON" \
118-
'.mcpServers = (.mcpServers // {} + $base + $add)' \
119-
"$SETTINGS_PATH" > "$TMP_SETTINGS" && mv "$TMP_SETTINGS" "$SETTINGS_PATH"
106+
printf "[append_extensions_to_settings_json] Merging BASE_EXTENSIONS and ADDITIONAL_EXTENSIONS into mcpServers...\n"
107+
jq --argjson base "$BASE_EXTENSIONS" --argjson add "$ADD_EXT_JSON" \
108+
'.mcpServers = (.mcpServers // {} + $base + $add)' \
109+
"$SETTINGS_PATH" > "$TMP_SETTINGS" && mv "$TMP_SETTINGS" "$SETTINGS_PATH"
120110

121-
jq '.theme = "Default" | .selectedAuthType = "gemini-api-key"' "$SETTINGS_PATH" > "$TMP_SETTINGS" && mv "$TMP_SETTINGS" "$SETTINGS_PATH"
111+
jq '.theme = "Default" | .selectedAuthType = "gemini-api-key"' "$SETTINGS_PATH" > "$TMP_SETTINGS" && mv "$TMP_SETTINGS" "$SETTINGS_PATH"
122112

123-
printf "[append_extensions_to_settings_json] Merge complete.\n"
113+
printf "[append_extensions_to_settings_json] Merge complete.\n"
124114
}
125115

126116
function add_system_prompt_if_exists() {
127-
if [ -n "${GEMINI_SYSTEM_PROMPT:-}" ]; then
128-
if [ -d "${GEMINI_START_DIRECTORY}" ]; then
129-
printf "Directory '%s' exists. Changing to it.\\n" "${GEMINI_START_DIRECTORY}"
130-
cd "${GEMINI_START_DIRECTORY}" || {
131-
printf "Error: Could not change to directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
132-
exit 1
133-
}
134-
else
135-
printf "Directory '%s' does not exist. Creating and changing to it.\\n" "${GEMINI_START_DIRECTORY}"
136-
mkdir -p "${GEMINI_START_DIRECTORY}" || {
137-
printf "Error: Could not create directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
138-
exit 1
139-
}
140-
cd "${GEMINI_START_DIRECTORY}" || {
141-
printf "Error: Could not change to directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
142-
exit 1
143-
}
144-
fi
145-
touch GEMINI.md
146-
printf "Setting GEMINI.md\n"
147-
echo "${GEMINI_SYSTEM_PROMPT}" > GEMINI.md
117+
if [ -n "${GEMINI_SYSTEM_PROMPT:-}" ]; then
118+
if [ -d "${GEMINI_START_DIRECTORY}" ]; then
119+
printf "Directory '%s' exists. Changing to it.\\n" "${GEMINI_START_DIRECTORY}"
120+
cd "${GEMINI_START_DIRECTORY}" || {
121+
printf "Error: Could not change to directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
122+
exit 1
123+
}
148124
else
149-
printf "GEMINI.md is not set.\n"
125+
printf "Directory '%s' does not exist. Creating and changing to it.\\n" "${GEMINI_START_DIRECTORY}"
126+
mkdir -p "${GEMINI_START_DIRECTORY}" || {
127+
printf "Error: Could not create directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
128+
exit 1
129+
}
130+
cd "${GEMINI_START_DIRECTORY}" || {
131+
printf "Error: Could not change to directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
132+
exit 1
133+
}
150134
fi
135+
touch GEMINI.md
136+
printf "Setting GEMINI.md\n"
137+
echo "${GEMINI_SYSTEM_PROMPT}" > GEMINI.md
138+
else
139+
printf "GEMINI.md is not set.\n"
140+
fi
151141
}
152142

153143
function configure_mcp() {
154-
export CODER_MCP_APP_STATUS_SLUG="gemini"
155-
export CODER_MCP_AI_AGENTAPI_URL="http://localhost:3284"
156-
coder exp mcp configure gemini "${GEMINI_START_DIRECTORY}"
144+
export CODER_MCP_APP_STATUS_SLUG="gemini"
145+
export CODER_MCP_AI_AGENTAPI_URL="http://localhost:3284"
146+
coder exp mcp configure gemini "${GEMINI_START_DIRECTORY}"
157147
}
158148

159149
install_gemini
160-
gemini --version
161150
populate_settings_json
162151
add_system_prompt_if_exists
163152
configure_mcp
164-

0 commit comments

Comments
 (0)