Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de782f6

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 de782f6

File tree

3 files changed

+322
-0
lines changed

3 files changed

+322
-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: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 the official [coder-labs/gemini](https://registry.coder.com/modules/coder-labs/gemini) module.
12+
13+
## Features
14+
15+
- **Docker-based**: Lightweight Docker container with persistent storage
16+
- **Official Gemini Module**: Uses the verified `coder-labs/gemini` module v1.0.0 from Coder registry
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**: Parameter for Gemini API key
20+
- **Terminal Access**: Direct terminal access for manual Gemini CLI usage
21+
- **AgentAPI Integration**: Includes web UI and task automation capabilities
22+
23+
## Prerequisites
24+
25+
- Docker environment with Coder deployed
26+
- Gemini API key from Google AI Studio
27+
28+
## Parameters
29+
30+
### GEMINI_API_KEY (Required)
31+
32+
- **Type**: String
33+
- **Description**: Your Gemini API key for accessing Google's AI models
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+
### Web UI Mode
47+
48+
The module includes AgentAPI which provides a web interface for Gemini:
49+
50+
1. Look for the Gemini app in your workspace
51+
2. Click to open the web-based interface
52+
3. Interact with Gemini through the browser
53+
54+
### Example Commands
55+
56+
```bash
57+
# Interactive chat with Gemini
58+
gemini
59+
60+
# Generate code with a specific prompt
61+
echo "Create a simple Express.js server" | gemini
62+
63+
# Get help with debugging
64+
echo "Explain this error: TypeError: Cannot read property 'length' of undefined" | gemini
65+
```
66+
67+
## What's Included
68+
69+
- **Docker Container**: `codercom/enterprise-node:ubuntu` with Node.js pre-installed
70+
- **Gemini CLI**: Installed and configured via the official `coder-labs/gemini` module
71+
- **AgentAPI**: Web interface for Gemini interaction and task automation
72+
- **Code Server**: VS Code in the browser for development
73+
- **Terminal**: Direct shell access
74+
- **Persistent Storage**: Home directory persisted across workspace restarts
75+
76+
## Module Details
77+
78+
This template uses the official [`coder-labs/gemini`](https://registry.coder.com/modules/coder-labs/gemini) module v1.0.0 which provides:
79+
80+
- Automatic Gemini CLI installation and configuration
81+
- AgentAPI web interface for browser-based interaction
82+
- Proper environment variable setup
83+
- Integration with Coder's agent system
84+
- Support for multiple Gemini AI models
85+
86+
> **Note**: We use version 1.0.0 specifically because newer versions (1.1.0+) have validation issues in their agentapi dependency that prevent `terraform init` from working.
87+
88+
## Security
89+
90+
- API keys are managed through Coder parameters
91+
- Container runs with appropriate user permissions
92+
- Network isolation through Docker
93+
94+
## Resources
95+
96+
- **Base Image**: `codercom/enterprise-node:ubuntu`
97+
- **Storage**: Persistent Docker volume for `/home/coder`
98+
- **Network**: Docker bridge with host gateway access
99+
100+
## Troubleshooting
101+
102+
### Gemini CLI Not Found
103+
104+
The official module handles Gemini CLI installation automatically. If you encounter issues, check the startup logs in the agent.
105+
106+
### API Key Issues
107+
108+
Ensure your Gemini API key is valid and has the necessary permissions. You can test it manually by running:
109+
110+
```bash
111+
export GEMINI_API_KEY="your-key-here"
112+
gemini "Hello, can you help me?"
113+
```
114+
115+
### Module Issues
116+
117+
If you encounter issues with the `coder-labs/gemini` module, refer to the [module documentation](https://registry.coder.com/modules/coder-labs/gemini) for troubleshooting steps.
118+
119+
### Version Compatibility
120+
121+
This template uses gemini module v1.0.0 due to validation issues in newer versions. If these issues are resolved in future versions, the template can be updated to use the latest version.
122+
123+
## Support
124+
125+
For issues with this template, please contact the template maintainer or file an issue in the Coder registry repository.
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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 = "registry.coder.com/coder-labs/gemini/coder"
99+
version = "1.0.0"
100+
agent_id = coder_agent.main.id
101+
gemini_api_key = data.coder_parameter.gemini_api_key.value
102+
folder = "/home/coder"
103+
}
104+
105+
module "code-server" {
106+
count = data.coder_workspace.me.start_count
107+
source = "registry.coder.com/coder/code-server/coder"
108+
version = "~> 1.0"
109+
agent_id = coder_agent.main.id
110+
order = 1
111+
}
112+
113+
resource "coder_app" "terminal" {
114+
agent_id = coder_agent.main.id
115+
slug = "terminal"
116+
display_name = "Terminal"
117+
icon = "/icon/terminal.svg"
118+
command = "bash"
119+
share = "owner"
120+
}
121+
122+
resource "docker_volume" "home_volume" {
123+
name = "coder-${data.coder_workspace.me.id}-home"
124+
lifecycle {
125+
ignore_changes = all
126+
}
127+
labels {
128+
label = "coder.owner"
129+
value = data.coder_workspace_owner.me.name
130+
}
131+
labels {
132+
label = "coder.owner_id"
133+
value = data.coder_workspace_owner.me.id
134+
}
135+
labels {
136+
label = "coder.workspace_id"
137+
value = data.coder_workspace.me.id
138+
}
139+
labels {
140+
label = "coder.workspace_name_at_creation"
141+
value = data.coder_workspace.me.name
142+
}
143+
}
144+
145+
resource "docker_container" "workspace" {
146+
count = data.coder_workspace.me.start_count
147+
image = "codercom/enterprise-node:ubuntu"
148+
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
149+
hostname = data.coder_workspace.me.name
150+
entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
151+
env = [
152+
"CODER_AGENT_TOKEN=${coder_agent.main.token}",
153+
"GEMINI_API_KEY=${data.coder_parameter.gemini_api_key.value}"
154+
]
155+
host {
156+
host = "host.docker.internal"
157+
ip = "host-gateway"
158+
}
159+
volumes {
160+
container_path = "/home/coder"
161+
volume_name = docker_volume.home_volume.name
162+
read_only = false
163+
}
164+
165+
labels {
166+
label = "coder.owner"
167+
value = data.coder_workspace_owner.me.name
168+
}
169+
labels {
170+
label = "coder.owner_id"
171+
value = data.coder_workspace_owner.me.id
172+
}
173+
labels {
174+
label = "coder.workspace_id"
175+
value = data.coder_workspace.me.id
176+
}
177+
labels {
178+
label = "coder.workspace_name"
179+
value = data.coder_workspace.me.name
180+
}
181+
}

0 commit comments

Comments
 (0)