-
Notifications
You must be signed in to change notification settings - Fork 59
Add Gemini CLI Docker template for matifali namespace #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
registry/matifali/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
display_name: M Atif Ali | ||
bio: Software Engineer and AI enthusiast creating templates for enhanced development workflows | ||
github: matifali | ||
avatar: https://github.com/matifali.png | ||
linkedin: https://www.linkedin.com/in/ioatif | ||
status: community | ||
--- | ||
|
||
# M Atif Ali | ||
|
||
Software Engineer and AI enthusiast creating templates for enhanced development workflows with AI-powered tools. | ||
|
||
## Templates | ||
|
||
- [gemini-cli](./templates/gemini-cli/) - A Docker workspace template with Gemini CLI for AI-powered coding assistance |
125 changes: 125 additions & 0 deletions
registry/matifali/templates/gemini-cli/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
--- | ||
display_name: Gemini CLI | ||
description: A Docker workspace template with Gemini CLI for AI-powered coding assistance | ||
icon: ../../../../.icons/gemini.svg | ||
verified: false | ||
tags: [docker, gemini, ai, google, node] | ||
--- | ||
|
||
# Gemini CLI Template | ||
|
||
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. | ||
|
||
## Features | ||
|
||
- **Docker-based**: Lightweight Docker container with persistent storage | ||
- **Official Gemini Module**: Uses the verified `coder-labs/gemini` module v1.0.0 from Coder registry | ||
- **Node.js Environment**: Pre-configured Node.js development environment | ||
- **Code Server**: VS Code in the browser for development | ||
- **Secure API Key Management**: Parameter for Gemini API key | ||
- **Terminal Access**: Direct terminal access for manual Gemini CLI usage | ||
- **AgentAPI Integration**: Includes web UI and task automation capabilities | ||
|
||
## Prerequisites | ||
|
||
- Docker environment with Coder deployed | ||
- Gemini API key from Google AI Studio | ||
|
||
## Parameters | ||
|
||
### GEMINI_API_KEY (Required) | ||
|
||
- **Type**: String | ||
- **Description**: Your Gemini API key for accessing Google's AI models | ||
- **Mutable**: Yes | ||
|
||
Get your API key from [Google AI Studio](https://aistudio.google.com/app/apikey). | ||
|
||
## Usage | ||
|
||
### Interactive Mode | ||
|
||
1. Open the Terminal app in your workspace | ||
2. Run `gemini` to start an interactive session with Google's AI | ||
3. Ask questions or request coding assistance | ||
|
||
### Web UI Mode | ||
|
||
The module includes AgentAPI which provides a web interface for Gemini: | ||
|
||
1. Look for the Gemini app in your workspace | ||
2. Click to open the web-based interface | ||
3. Interact with Gemini through the browser | ||
|
||
### Example Commands | ||
|
||
```bash | ||
# Interactive chat with Gemini | ||
gemini | ||
|
||
# Generate code with a specific prompt | ||
echo "Create a simple Express.js server" | gemini | ||
|
||
# Get help with debugging | ||
echo "Explain this error: TypeError: Cannot read property 'length' of undefined" | gemini | ||
``` | ||
|
||
## What's Included | ||
|
||
- **Docker Container**: `codercom/enterprise-node:ubuntu` with Node.js pre-installed | ||
- **Gemini CLI**: Installed and configured via the official `coder-labs/gemini` module | ||
- **AgentAPI**: Web interface for Gemini interaction and task automation | ||
- **Code Server**: VS Code in the browser for development | ||
- **Terminal**: Direct shell access | ||
- **Persistent Storage**: Home directory persisted across workspace restarts | ||
|
||
## Module Details | ||
|
||
This template uses the official [`coder-labs/gemini`](https://registry.coder.com/modules/coder-labs/gemini) module v1.0.0 which provides: | ||
|
||
- Automatic Gemini CLI installation and configuration | ||
- AgentAPI web interface for browser-based interaction | ||
- Proper environment variable setup | ||
- Integration with Coder's agent system | ||
- Support for multiple Gemini AI models | ||
|
||
> **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. | ||
|
||
## Security | ||
|
||
- API keys are managed through Coder parameters | ||
- Container runs with appropriate user permissions | ||
- Network isolation through Docker | ||
|
||
## Resources | ||
|
||
- **Base Image**: `codercom/enterprise-node:ubuntu` | ||
- **Storage**: Persistent Docker volume for `/home/coder` | ||
- **Network**: Docker bridge with host gateway access | ||
|
||
## Troubleshooting | ||
|
||
### Gemini CLI Not Found | ||
|
||
The official module handles Gemini CLI installation automatically. If you encounter issues, check the startup logs in the agent. | ||
|
||
### API Key Issues | ||
|
||
Ensure your Gemini API key is valid and has the necessary permissions. You can test it manually by running: | ||
|
||
```bash | ||
export GEMINI_API_KEY="your-key-here" | ||
gemini "Hello, can you help me?" | ||
``` | ||
|
||
### Module Issues | ||
|
||
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. | ||
|
||
### Version Compatibility | ||
|
||
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. | ||
|
||
## Support | ||
|
||
For issues with this template, please contact the template maintainer or file an issue in the Coder registry repository. |
182 changes: 182 additions & 0 deletions
registry/matifali/templates/gemini-cli/main.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
} | ||
docker = { | ||
source = "kreuzwerker/docker" | ||
} | ||
} | ||
} | ||
|
||
locals { | ||
username = data.coder_workspace_owner.me.name | ||
} | ||
|
||
variable "docker_socket" { | ||
default = "" | ||
description = "(Optional) Docker socket URI" | ||
type = string | ||
} | ||
|
||
data "coder_parameter" "gemini_api_key" { | ||
type = "string" | ||
name = "GEMINI_API_KEY" | ||
display_name = "Gemini API Key" | ||
description = "Your Gemini API key for accessing Google's AI models" | ||
mutable = true | ||
option { | ||
name = "Enter your Gemini API key" | ||
value = "" | ||
} | ||
} | ||
|
||
provider "docker" { | ||
host = var.docker_socket != "" ? var.docker_socket : null | ||
} | ||
|
||
data "coder_provisioner" "me" {} | ||
data "coder_workspace" "me" {} | ||
data "coder_workspace_owner" "me" {} | ||
|
||
resource "coder_agent" "main" { | ||
arch = data.coder_provisioner.me.arch | ||
os = "linux" | ||
startup_script = <<-EOT | ||
set -e | ||
|
||
# Prepare user home with default files on first start. | ||
if [ ! -f ~/.init_done ]; then | ||
cp -rT /etc/skel ~ | ||
touch ~/.init_done | ||
fi | ||
|
||
# Install Gemini CLI if not already installed | ||
if ! command -v gemini &> /dev/null; then | ||
echo "Installing Gemini CLI..." | ||
sudo npm install -g @google/generative-ai-cli | ||
echo "Gemini CLI installed successfully" | ||
fi | ||
EOT | ||
|
||
env = { | ||
GIT_AUTHOR_NAME = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name) | ||
GIT_AUTHOR_EMAIL = "${data.coder_workspace_owner.me.email}" | ||
GIT_COMMITTER_NAME = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name) | ||
GIT_COMMITTER_EMAIL = "${data.coder_workspace_owner.me.email}" | ||
|
||
# Gemini CLI environment variables | ||
GEMINI_API_KEY = data.coder_parameter.gemini_api_key.value | ||
} | ||
|
||
metadata { | ||
display_name = "CPU Usage" | ||
key = "0_cpu_usage" | ||
script = "coder stat cpu" | ||
interval = 10 | ||
timeout = 1 | ||
} | ||
|
||
metadata { | ||
display_name = "RAM Usage" | ||
key = "1_ram_usage" | ||
script = "coder stat mem" | ||
interval = 10 | ||
timeout = 1 | ||
} | ||
|
||
metadata { | ||
display_name = "Home Disk" | ||
key = "3_home_disk" | ||
script = "coder stat disk --path $${HOME}" | ||
interval = 60 | ||
timeout = 1 | ||
} | ||
} | ||
|
||
module "gemini" { | ||
count = data.coder_workspace.me.start_count | ||
source = "registry.coder.com/coder-labs/gemini/coder" | ||
version = "1.0.0" | ||
agent_id = coder_agent.main.id | ||
gemini_api_key = data.coder_parameter.gemini_api_key.value | ||
folder = "/home/coder" | ||
} | ||
|
||
module "code-server" { | ||
count = data.coder_workspace.me.start_count | ||
source = "registry.coder.com/coder/code-server/coder" | ||
version = "~> 1.0" | ||
agent_id = coder_agent.main.id | ||
order = 1 | ||
} | ||
|
||
resource "coder_app" "terminal" { | ||
agent_id = coder_agent.main.id | ||
slug = "terminal" | ||
display_name = "Terminal" | ||
icon = "/icon/terminal.svg" | ||
command = "bash" | ||
share = "owner" | ||
} | ||
|
||
resource "docker_volume" "home_volume" { | ||
name = "coder-${data.coder_workspace.me.id}-home" | ||
lifecycle { | ||
ignore_changes = all | ||
} | ||
labels { | ||
label = "coder.owner" | ||
value = data.coder_workspace_owner.me.name | ||
} | ||
labels { | ||
label = "coder.owner_id" | ||
value = data.coder_workspace_owner.me.id | ||
} | ||
labels { | ||
label = "coder.workspace_id" | ||
value = data.coder_workspace.me.id | ||
} | ||
labels { | ||
label = "coder.workspace_name_at_creation" | ||
value = data.coder_workspace.me.name | ||
} | ||
} | ||
|
||
resource "docker_container" "workspace" { | ||
count = data.coder_workspace.me.start_count | ||
image = "codercom/enterprise-node:ubuntu" | ||
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}" | ||
hostname = data.coder_workspace.me.name | ||
entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")] | ||
env = [ | ||
"CODER_AGENT_TOKEN=${coder_agent.main.token}", | ||
"GEMINI_API_KEY=${data.coder_parameter.gemini_api_key.value}" | ||
] | ||
host { | ||
host = "host.docker.internal" | ||
ip = "host-gateway" | ||
} | ||
volumes { | ||
container_path = "/home/coder" | ||
volume_name = docker_volume.home_volume.name | ||
read_only = false | ||
} | ||
|
||
labels { | ||
label = "coder.owner" | ||
value = data.coder_workspace_owner.me.name | ||
} | ||
labels { | ||
label = "coder.owner_id" | ||
value = data.coder_workspace_owner.me.id | ||
} | ||
labels { | ||
label = "coder.workspace_id" | ||
value = data.coder_workspace.me.id | ||
} | ||
labels { | ||
label = "coder.workspace_name" | ||
value = data.coder_workspace.me.name | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.