Skip to content

Commit a0b9b6e

Browse files
Add Gemini CLI Docker template for matifali namespace
This PR adds a new Coder Docker template for the Gemini CLI in the matifali namespace. Features: - Docker-based template using codercom/enterprise-node:ubuntu - Direct Gemini CLI installation via npm - GEMINI_API_KEY parameter for secure API key management - Pre-configured with Node.js, Code Server, and terminal access - Persistent Docker volume storage - Proper namespace README with bio, GitHub, avatar - Template validated with terraform init/validate/fmt - Follows Coder registry standards and formatting Co-authored-by: matifali <atif@coder.com>
1 parent 9e47369 commit a0b9b6e

File tree

4 files changed

+433
-0
lines changed

4 files changed

+433
-0
lines changed

registry/matifali/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
display_name: M Atif Ali
3+
bio: Software Engineer and AI enthusiast creating templates for enhanced development workflows
4+
github: matifali
5+
avatar: https://github.com/matifali.png
6+
linkedin: https://www.linkedin.com/in/ioatif
7+
status: community
8+
---
9+
10+
# M Atif Ali
11+
12+
Software Engineer and AI enthusiast creating templates for enhanced development workflows with AI-powered tools.
13+
14+
## Templates
15+
16+
- [gemini-cli](./templates/gemini-cli/) - A Docker workspace template with Gemini CLI for AI-powered coding assistance
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
display_name: Gemini CLI
3+
description: A Docker workspace template with Gemini CLI for AI-powered coding assistance
4+
icon: ../../../../.icons/gemini.svg
5+
verified: false
6+
tags: [docker, gemini, ai, google, node]
7+
---
8+
9+
# Gemini CLI Template
10+
11+
A Docker workspace template that integrates Google's Gemini CLI for AI-powered coding assistance using a custom module implementation.
12+
13+
> **Note**: This template uses a custom module implementation that provides the same interface as the [coder-labs/gemini](https://registry.coder.com/modules/coder-labs/gemini) module but works around current validation issues in the official module's dependencies.
14+
15+
## Features
16+
17+
- **Docker-based**: Lightweight Docker container with persistent storage
18+
- **Gemini CLI Module**: Custom module implementation with the same interface as the official module
19+
- **Node.js Environment**: Pre-configured Node.js development environment
20+
- **Code Server**: VS Code in the browser for development
21+
- **Secure API Key Management**: Parameter for Gemini API key
22+
- **Terminal Access**: Direct terminal access for manual Gemini CLI usage
23+
- **Gemini App**: Dedicated app for easy Gemini CLI access
24+
25+
## Prerequisites
26+
27+
- Docker environment with Coder deployed
28+
- Gemini API key from Google AI Studio
29+
30+
## Parameters
31+
32+
### GEMINI_API_KEY (Required)
33+
34+
- **Type**: String
35+
- **Description**: Your Gemini API key for accessing Google's AI models
36+
- **Mutable**: Yes
37+
38+
Get your API key from [Google AI Studio](https://aistudio.google.com/app/apikey).
39+
40+
## Usage
41+
42+
### Interactive Mode
43+
44+
1. Click on the "Gemini CLI" app in your workspace
45+
2. Or open the Terminal app and run `gemini`
46+
3. Ask questions or request coding assistance
47+
48+
### Example Commands
49+
50+
```bash
51+
# Interactive chat with Gemini
52+
gemini
53+
54+
# Generate code with a specific prompt
55+
echo "Create a simple Express.js server" | gemini
56+
57+
# Get help with debugging
58+
echo "Explain this error: TypeError: Cannot read property 'length' of undefined" | gemini
59+
```
60+
61+
## What's Included
62+
63+
- **Docker Container**: `codercom/enterprise-node:ubuntu` with Node.js pre-installed
64+
- **Gemini CLI**: Installed via npm during workspace startup
65+
- **Custom Module**: Local module that provides the same interface as the official coder-labs/gemini module
66+
- **Code Server**: VS Code in the browser for development
67+
- **Terminal**: Direct shell access
68+
- **Gemini App**: Dedicated workspace app for easy access
69+
- **Persistent Storage**: Home directory persisted across workspace restarts
70+
71+
## Module Implementation
72+
73+
This template includes a custom module (`./modules/gemini-fixed`) that:
74+
75+
- Provides the same interface as the official `coder-labs/gemini` module
76+
- Installs Gemini CLI directly via npm
77+
- Sets up proper environment variables
78+
- Creates a dedicated Coder app for easy access
79+
- Avoids the validation issues present in the official module's dependencies
80+
81+
## Security
82+
83+
- API keys are managed through Coder parameters
84+
- Container runs with appropriate user permissions
85+
- Network isolation through Docker
86+
87+
## Resources
88+
89+
- **Base Image**: `codercom/enterprise-node:ubuntu`
90+
- **Storage**: Persistent Docker volume for `/home/coder`
91+
- **Network**: Docker bridge with host gateway access
92+
93+
## Troubleshooting
94+
95+
### Gemini CLI Not Found
96+
97+
The custom module handles Gemini CLI installation automatically. If you encounter issues:
98+
99+
1. Check the startup logs in the Coder agent
100+
2. Ensure the workspace has internet access for npm installation
101+
3. Verify that Node.js and npm are available in the container
102+
103+
### API Key Issues
104+
105+
Ensure your Gemini API key is valid and has the necessary permissions. You can test it manually by running:
106+
107+
```bash
108+
export GEMINI_API_KEY="your-key-here"
109+
gemini "Hello, can you help me?"
110+
```
111+
112+
### Installation Issues
113+
114+
If Gemini CLI installation fails:
115+
116+
1. Check that the container has sudo permissions
117+
2. Verify internet connectivity
118+
3. Try manual installation: `sudo npm install -g @google/generative-ai-cli`
119+
120+
## Module Compatibility
121+
122+
This template uses a custom module that provides the same interface as the official `coder-labs/gemini` module. Once the validation issues in the official module are resolved, this template can be easily updated to use the official module instead.
123+
124+
## Support
125+
126+
For issues with this template, please contact the template maintainer or file an issue in the Coder registry repository.
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
docker = {
7+
source = "kreuzwerker/docker"
8+
}
9+
}
10+
}
11+
12+
locals {
13+
username = data.coder_workspace_owner.me.name
14+
}
15+
16+
variable "docker_socket" {
17+
default = ""
18+
description = "(Optional) Docker socket URI"
19+
type = string
20+
}
21+
22+
data "coder_parameter" "gemini_api_key" {
23+
type = "string"
24+
name = "GEMINI_API_KEY"
25+
description = "Your Gemini API key for accessing Google's AI models"
26+
mutable = true
27+
option {
28+
name = "Enter your Gemini API key"
29+
value = ""
30+
}
31+
}
32+
33+
provider "docker" {
34+
host = var.docker_socket != "" ? var.docker_socket : null
35+
}
36+
37+
data "coder_provisioner" "me" {}
38+
data "coder_workspace" "me" {}
39+
data "coder_workspace_owner" "me" {}
40+
41+
resource "coder_agent" "main" {
42+
arch = data.coder_provisioner.me.arch
43+
os = "linux"
44+
startup_script = <<-EOT
45+
set -e
46+
47+
# Prepare user home with default files on first start.
48+
if [ ! -f ~/.init_done ]; then
49+
cp -rT /etc/skel ~
50+
touch ~/.init_done
51+
fi
52+
53+
# Install Gemini CLI if not already installed
54+
if ! command -v gemini &> /dev/null; then
55+
echo "Installing Gemini CLI..."
56+
sudo npm install -g @google/generative-ai-cli
57+
echo "Gemini CLI installed successfully"
58+
fi
59+
EOT
60+
61+
env = {
62+
GIT_AUTHOR_NAME = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name)
63+
GIT_AUTHOR_EMAIL = "${data.coder_workspace_owner.me.email}"
64+
GIT_COMMITTER_NAME = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name)
65+
GIT_COMMITTER_EMAIL = "${data.coder_workspace_owner.me.email}"
66+
67+
# Gemini CLI environment variables
68+
GEMINI_API_KEY = data.coder_parameter.gemini_api_key.value
69+
}
70+
71+
metadata {
72+
display_name = "CPU Usage"
73+
key = "0_cpu_usage"
74+
script = "coder stat cpu"
75+
interval = 10
76+
timeout = 1
77+
}
78+
79+
metadata {
80+
display_name = "RAM Usage"
81+
key = "1_ram_usage"
82+
script = "coder stat mem"
83+
interval = 10
84+
timeout = 1
85+
}
86+
87+
metadata {
88+
display_name = "Home Disk"
89+
key = "3_home_disk"
90+
script = "coder stat disk --path $${HOME}"
91+
interval = 60
92+
timeout = 1
93+
}
94+
}
95+
96+
module "gemini" {
97+
count = data.coder_workspace.me.start_count
98+
source = "./modules/gemini-fixed"
99+
agent_id = coder_agent.main.id
100+
gemini_api_key = data.coder_parameter.gemini_api_key.value
101+
folder = "/home/coder"
102+
gemini_model = "gemini-2.5-flash"
103+
task_prompt = ""
104+
gemini_system_prompt = <<-EOT
105+
You are a helpful coding assistant powered by Google's Gemini AI.
106+
You can help with code generation, debugging, and task automation.
107+
Always explain your code changes clearly.
108+
EOT
109+
enable_yolo_mode = false
110+
}
111+
112+
module "code-server" {
113+
count = data.coder_workspace.me.start_count
114+
source = "registry.coder.com/coder/code-server/coder"
115+
version = "~> 1.0"
116+
agent_id = coder_agent.main.id
117+
order = 1
118+
}
119+
120+
resource "coder_app" "terminal" {
121+
agent_id = coder_agent.main.id
122+
slug = "terminal"
123+
display_name = "Terminal"
124+
icon = "/icon/terminal.svg"
125+
command = "bash"
126+
share = "owner"
127+
}
128+
129+
resource "docker_volume" "home_volume" {
130+
name = "coder-${data.coder_workspace.me.id}-home"
131+
lifecycle {
132+
ignore_changes = all
133+
}
134+
labels {
135+
label = "coder.owner"
136+
value = data.coder_workspace_owner.me.name
137+
}
138+
labels {
139+
label = "coder.owner_id"
140+
value = data.coder_workspace_owner.me.id
141+
}
142+
labels {
143+
label = "coder.workspace_id"
144+
value = data.coder_workspace.me.id
145+
}
146+
labels {
147+
label = "coder.workspace_name_at_creation"
148+
value = data.coder_workspace.me.name
149+
}
150+
}
151+
152+
resource "docker_container" "workspace" {
153+
count = data.coder_workspace.me.start_count
154+
image = "codercom/enterprise-node:ubuntu"
155+
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
156+
hostname = data.coder_workspace.me.name
157+
entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
158+
env = [
159+
"CODER_AGENT_TOKEN=${coder_agent.main.token}",
160+
"GEMINI_API_KEY=${data.coder_parameter.gemini_api_key.value}"
161+
]
162+
host {
163+
host = "host.docker.internal"
164+
ip = "host-gateway"
165+
}
166+
volumes {
167+
container_path = "/home/coder"
168+
volume_name = docker_volume.home_volume.name
169+
read_only = false
170+
}
171+
172+
labels {
173+
label = "coder.owner"
174+
value = data.coder_workspace_owner.me.name
175+
}
176+
labels {
177+
label = "coder.owner_id"
178+
value = data.coder_workspace_owner.me.id
179+
}
180+
labels {
181+
label = "coder.workspace_id"
182+
value = data.coder_workspace.me.id
183+
}
184+
labels {
185+
label = "coder.workspace_name"
186+
value = data.coder_workspace.me.name
187+
}
188+
}

0 commit comments

Comments
 (0)