Skip to content

Commit b59b176

Browse files
committed
feat: remove node installation from gemini
- format shell script
1 parent b206a68 commit b59b176

File tree

3 files changed

+128
-140
lines changed

3 files changed

+128
-140
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.1.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.1.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.1.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.1.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/scripts/install.sh

Lines changed: 89 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
BOLD='\033[0;1m'
44

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-

registry/coder-labs/modules/gemini/scripts/start.sh

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -o pipefail
55
source "$HOME"/.bashrc
66

77
command_exists() {
8-
command -v "$1" >/dev/null 2>&1
8+
command -v "$1" > /dev/null 2>&1
99
}
1010

1111
if [ -f "$HOME/.nvm/nvm.sh" ]; then
@@ -20,55 +20,55 @@ MODULE_DIR="$HOME/.gemini-module"
2020
mkdir -p "$MODULE_DIR"
2121

2222
if command_exists gemini; then
23-
printf "Gemini is installed\n"
23+
printf "Gemini is installed\n"
2424
else
25-
printf "Error: Gemini is not installed. Please enable install_gemini or install it manually :)\n"
26-
exit 1
25+
printf "Error: Gemini is not installed. Please enable install_gemini or install it manually :)\n"
26+
exit 1
2727
fi
2828

2929
if [ -d "${GEMINI_START_DIRECTORY}" ]; then
30-
printf "Directory '%s' exists. Changing to it.\\n" "${GEMINI_START_DIRECTORY}"
31-
cd "${GEMINI_START_DIRECTORY}" || {
32-
printf "Error: Could not change to directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
33-
exit 1
34-
}
30+
printf "Directory '%s' exists. Changing to it.\\n" "${GEMINI_START_DIRECTORY}"
31+
cd "${GEMINI_START_DIRECTORY}" || {
32+
printf "Error: Could not change to directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
33+
exit 1
34+
}
3535
else
36-
printf "Directory '%s' does not exist. Creating and changing to it.\\n" "${GEMINI_START_DIRECTORY}"
37-
mkdir -p "${GEMINI_START_DIRECTORY}" || {
38-
printf "Error: Could not create directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
39-
exit 1
40-
}
41-
cd "${GEMINI_START_DIRECTORY}" || {
42-
printf "Error: Could not change to directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
43-
exit 1
44-
}
36+
printf "Directory '%s' does not exist. Creating and changing to it.\\n" "${GEMINI_START_DIRECTORY}"
37+
mkdir -p "${GEMINI_START_DIRECTORY}" || {
38+
printf "Error: Could not create directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
39+
exit 1
40+
}
41+
cd "${GEMINI_START_DIRECTORY}" || {
42+
printf "Error: Could not change to directory '%s'.\\n" "${GEMINI_START_DIRECTORY}"
43+
exit 1
44+
}
4545
fi
4646

4747
if [ -n "$GEMINI_TASK_PROMPT" ]; then
48-
printf "Running automated task: %s\n" "$GEMINI_TASK_PROMPT"
49-
PROMPT="Every step of the way, report tasks to Coder with proper descriptions and statuses. Your task at hand: $GEMINI_TASK_PROMPT"
50-
PROMPT_FILE="$MODULE_DIR/prompt.txt"
51-
echo -n "$PROMPT" >"$PROMPT_FILE"
52-
GEMINI_ARGS=(--prompt-interactive "$PROMPT")
48+
printf "Running automated task: %s\n" "$GEMINI_TASK_PROMPT"
49+
PROMPT="Every step of the way, report tasks to Coder with proper descriptions and statuses. Your task at hand: $GEMINI_TASK_PROMPT"
50+
PROMPT_FILE="$MODULE_DIR/prompt.txt"
51+
echo -n "$PROMPT" > "$PROMPT_FILE"
52+
GEMINI_ARGS=(--prompt-interactive "$PROMPT")
5353
else
54-
printf "Starting Gemini CLI in interactive mode.\n"
55-
GEMINI_ARGS=()
54+
printf "Starting Gemini CLI in interactive mode.\n"
55+
GEMINI_ARGS=()
5656
fi
5757

5858
if [ -n "$GEMINI_YOLO_MODE" ] && [ "$GEMINI_YOLO_MODE" = "true" ]; then
59-
printf "YOLO mode enabled - will auto-approve all tool calls\n"
60-
GEMINI_ARGS+=(--yolo)
59+
printf "YOLO mode enabled - will auto-approve all tool calls\n"
60+
GEMINI_ARGS+=(--yolo)
6161
fi
6262

6363
if [ -n "$GEMINI_API_KEY" ] || [ -n "$GOOGLE_API_KEY" ]; then
64-
if [ -n "$GOOGLE_GENAI_USE_VERTEXAI" ] && [ "$GOOGLE_GENAI_USE_VERTEXAI" = "true" ]; then
65-
printf "Using Vertex AI with API key\n"
66-
else
67-
printf "Using direct Gemini API with API key\n"
68-
fi
64+
if [ -n "$GOOGLE_GENAI_USE_VERTEXAI" ] && [ "$GOOGLE_GENAI_USE_VERTEXAI" = "true" ]; then
65+
printf "Using Vertex AI with API key\n"
66+
else
67+
printf "Using direct Gemini API with API key\n"
68+
fi
6969
else
70-
printf "No API key provided (neither GEMINI_API_KEY nor GOOGLE_API_KEY)\n"
70+
printf "No API key provided (neither GEMINI_API_KEY nor GOOGLE_API_KEY)\n"
7171
fi
7272

7373
agentapi server --term-width 67 --term-height 1190 -- \
74-
bash -c "$(printf '%q ' gemini "${GEMINI_ARGS[@]}")"
74+
bash -c "$(printf '%q ' gemini "${GEMINI_ARGS[@]}")"

0 commit comments

Comments
 (0)