Skip to content

Commit d6eb23f

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 <[email protected]>
1 parent 9e47369 commit d6eb23f

File tree

3 files changed

+298
-0
lines changed

3 files changed

+298
-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: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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.
12+
13+
## Features
14+
15+
- **Docker-based**: Lightweight Docker container with persistent storage
16+
- **Gemini CLI Integration**: Direct installation of Google's Gemini CLI
17+
- **Node.js Environment**: Pre-configured Node.js development environment
18+
- **Code Server**: VS Code in the browser for development
19+
- **Secure API Key Management**: Masked input parameter for Gemini API key
20+
- **Terminal Access**: Direct terminal access for manual Gemini CLI usage
21+
22+
## Prerequisites
23+
24+
- Docker environment with Coder deployed
25+
- Gemini API key from Google AI Studio
26+
27+
## Parameters
28+
29+
### GEMINI_API_KEY (Required)
30+
31+
- **Type**: String (masked input)
32+
- **Description**: Your Gemini API key for accessing Google's AI models
33+
- **Sensitive**: Yes
34+
- **Mutable**: Yes
35+
36+
Get your API key from [Google AI Studio](https://aistudio.google.com/app/apikey).
37+
38+
## Usage
39+
40+
### Interactive Mode
41+
42+
1. Open the Terminal app in your workspace
43+
2. Run `gemini` to start an interactive session with Google's AI
44+
3. Ask questions or request coding assistance
45+
46+
### Example Commands
47+
48+
```bash
49+
# Interactive chat with Gemini
50+
gemini
51+
52+
# Generate code with a specific prompt
53+
echo "Create a simple Express.js server" | gemini
54+
55+
# Get help with debugging
56+
echo "Explain this error: TypeError: Cannot read property 'length' of undefined" | gemini
57+
```
58+
59+
## What's Included
60+
61+
- **Docker Container**: `codercom/enterprise-node:ubuntu` with Node.js pre-installed
62+
- **Gemini CLI**: Latest version installed via npm
63+
- **Code Server**: VS Code in the browser for development
64+
- **Terminal**: Direct shell access
65+
- **Persistent Storage**: Home directory persisted across workspace restarts
66+
67+
## Security
68+
69+
- API keys are stored securely and masked in the UI
70+
- Container runs with appropriate user permissions
71+
- Network isolation through Docker
72+
73+
## Resources
74+
75+
- **Base Image**: `codercom/enterprise-node:ubuntu`
76+
- **Storage**: Persistent Docker volume for `/home/coder`
77+
- **Network**: Docker bridge with host gateway access
78+
79+
## Troubleshooting
80+
81+
### Gemini CLI Not Found
82+
83+
The template automatically installs Gemini CLI via npm. If it's not available, check the startup logs in the agent.
84+
85+
### API Key Issues
86+
87+
Ensure your Gemini API key is valid and has the necessary permissions. You can test it manually by running:
88+
89+
```bash
90+
export GEMINI_API_KEY="your-key-here"
91+
gemini "Hello, can you help me?"
92+
```
93+
94+
### Node.js Issues
95+
96+
The template uses the `codercom/enterprise-node:ubuntu` image which includes Node.js. If you encounter issues, the startup script will attempt to install the latest LTS version.
97+
98+
## Support
99+
100+
For issues with this template, please contact the template maintainer or file an issue in the Coder registry repository.
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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 Node.js if not available
54+
if ! command -v node &> /dev/null; then
55+
echo "Installing Node.js..."
56+
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
57+
sudo apt-get install -y nodejs
58+
fi
59+
60+
# Install Gemini CLI
61+
if ! command -v gemini &> /dev/null; then
62+
echo "Installing Gemini CLI..."
63+
sudo npm install -g @google/generative-ai-cli
64+
fi
65+
66+
echo "Node.js version: $(node --version)"
67+
echo "npm version: $(npm --version)"
68+
echo "Gemini CLI installed successfully"
69+
EOT
70+
71+
env = {
72+
GIT_AUTHOR_NAME = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name)
73+
GIT_AUTHOR_EMAIL = "${data.coder_workspace_owner.me.email}"
74+
GIT_COMMITTER_NAME = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name)
75+
GIT_COMMITTER_EMAIL = "${data.coder_workspace_owner.me.email}"
76+
77+
# Gemini CLI environment variables
78+
GEMINI_API_KEY = data.coder_parameter.gemini_api_key.value
79+
}
80+
81+
metadata {
82+
display_name = "CPU Usage"
83+
key = "0_cpu_usage"
84+
script = "coder stat cpu"
85+
interval = 10
86+
timeout = 1
87+
}
88+
89+
metadata {
90+
display_name = "RAM Usage"
91+
key = "1_ram_usage"
92+
script = "coder stat mem"
93+
interval = 10
94+
timeout = 1
95+
}
96+
97+
metadata {
98+
display_name = "Home Disk"
99+
key = "3_home_disk"
100+
script = "coder stat disk --path $${HOME}"
101+
interval = 60
102+
timeout = 1
103+
}
104+
}
105+
106+
module "code-server" {
107+
count = data.coder_workspace.me.start_count
108+
source = "registry.coder.com/coder/code-server/coder"
109+
version = "~> 1.0"
110+
agent_id = coder_agent.main.id
111+
order = 1
112+
}
113+
114+
resource "coder_app" "terminal" {
115+
agent_id = coder_agent.main.id
116+
slug = "terminal"
117+
display_name = "Terminal"
118+
icon = "/icon/terminal.svg"
119+
command = "bash"
120+
share = "owner"
121+
}
122+
123+
resource "docker_volume" "home_volume" {
124+
name = "coder-${data.coder_workspace.me.id}-home"
125+
lifecycle {
126+
ignore_changes = all
127+
}
128+
labels {
129+
label = "coder.owner"
130+
value = data.coder_workspace_owner.me.name
131+
}
132+
labels {
133+
label = "coder.owner_id"
134+
value = data.coder_workspace_owner.me.id
135+
}
136+
labels {
137+
label = "coder.workspace_id"
138+
value = data.coder_workspace.me.id
139+
}
140+
labels {
141+
label = "coder.workspace_name_at_creation"
142+
value = data.coder_workspace.me.name
143+
}
144+
}
145+
146+
resource "docker_container" "workspace" {
147+
count = data.coder_workspace.me.start_count
148+
image = "codercom/enterprise-node:ubuntu"
149+
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
150+
hostname = data.coder_workspace.me.name
151+
entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
152+
env = [
153+
"CODER_AGENT_TOKEN=${coder_agent.main.token}",
154+
"GEMINI_API_KEY=${data.coder_parameter.gemini_api_key.value}"
155+
]
156+
host {
157+
host = "host.docker.internal"
158+
ip = "host-gateway"
159+
}
160+
volumes {
161+
container_path = "/home/coder"
162+
volume_name = docker_volume.home_volume.name
163+
read_only = false
164+
}
165+
166+
labels {
167+
label = "coder.owner"
168+
value = data.coder_workspace_owner.me.name
169+
}
170+
labels {
171+
label = "coder.owner_id"
172+
value = data.coder_workspace_owner.me.id
173+
}
174+
labels {
175+
label = "coder.workspace_id"
176+
value = data.coder_workspace.me.id
177+
}
178+
labels {
179+
label = "coder.workspace_name"
180+
value = data.coder_workspace.me.name
181+
}
182+
}

0 commit comments

Comments
 (0)