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

Skip to content

Commit 10ce4a0

Browse files
committed
add example dockerfile main.tf
1 parent d60c25a commit 10ce4a0

File tree

3 files changed

+261
-23
lines changed

3 files changed

+261
-23
lines changed

docs/ai-coder/claude-integration.md

+49-23
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,24 @@ The easiest way to get started with Claude in Coder is to add the
3333
1. Add the Claude Code module to your template's `main.tf` file:
3434

3535
```hcl
36+
# Add Claude Code module for integration
3637
module "claude-code" {
3738
source = "registry.coder.com/modules/claude-code/coder"
3839
version = "1.2.1"
3940
40-
agent = var.agent # This connects the module to your agent
41-
experiment_use_screen = true # Enable reporting to Coder dashboard
42-
experiment_report_tasks = true # Show tasks in Coder UI
41+
# Required - connects to your workspace agent
42+
agent_id = coder_agent.main.id
43+
44+
# Enable dashboard integration
45+
experiment_use_screen = true
46+
experiment_report_tasks = true
47+
}
48+
49+
# Set environment variables for Claude configuration
50+
resource "coder_env" "claude_api_key" {
51+
agent_id = coder_agent.main.id
52+
name = "CLAUDE_API_KEY"
53+
value = var.anthropic_api_key
4354
}
4455
```
4556

@@ -54,14 +65,7 @@ The easiest way to get started with Claude in Coder is to add the
5465
}
5566
```
5667

57-
1. Add another section to pass the API key to the module:
58-
59-
```hcl
60-
module "claude-code" {
61-
# ... existing settings from above
62-
anthropic_api_key = var.anthropic_api_key
63-
}
64-
```
68+
1. With the `coder_env` resource above, your API key is already properly configured. No additional code is needed.
6569

6670
1. Push your template:
6771

@@ -119,24 +123,46 @@ module "claude-code" {
119123

120124
## Customize your Claude setup
121125

122-
You can customize Claude's behavior with additional options:
126+
You can customize Claude's behavior with additional environment variables:
123127

124128
```hcl
125-
module "claude-code" {
126-
# ... basic settings from above
127-
# full list at https://coder.com/docs/ai-coder/claude-integration#environment-variables-reference
129+
# Set environment variables to customize Claude behavior
128130
129-
# Choose a specific Claude model
130-
model = "claude-3-7-sonnet-20240229"
131+
# Authentication
132+
resource "coder_env" "claude_api_key" {
133+
agent_id = coder_agent.main.id
134+
name = "CLAUDE_API_KEY"
135+
value = var.anthropic_api_key
136+
}
131137
132-
# Give Claude specific instructions
133-
custom_system_prompt = "You are a Python expert focused on writing clean, efficient code."
138+
# Choose a specific Claude model (use Sonnet for best performance)
139+
resource "coder_env" "claude_model" {
140+
agent_id = coder_agent.main.id
141+
name = "CLAUDE_MODEL"
142+
value = "claude-3-sonnet-20240229"
143+
}
134144
135-
# Add special capabilities through MCP
136-
additional_tools = ["playwright-mcp", "desktop-commander"]
145+
# Custom instructions
146+
resource "coder_env" "claude_system_prompt" {
147+
agent_id = coder_agent.main.id
148+
name = "CODER_MCP_CLAUDE_SYSTEM_PROMPT"
149+
value = "You are a Python expert focused on writing clean, efficient code."
150+
}
137151
138-
# Set resource limits
139-
timeout_seconds = 300 # Maximum time for a single request
152+
# Add special capabilities through MCP
153+
resource "coder_env" "claude_mcp_instructions" {
154+
agent_id = coder_agent.main.id
155+
name = "CODER_MCP_INSTRUCTIONS"
156+
value = "Use playwright-mcp and desktop-commander tools when available"
157+
}
158+
159+
# Claude Code module with dashboard integration
160+
module "claude-code" {
161+
# ... basic settings from above
162+
source = "registry.coder.com/modules/claude-code/coder"
163+
agent_id = coder_agent.main.id
164+
experiment_use_screen = true
165+
experiment_report_tasks = true
140166
}
141167
```
142168

docs/ai-coder/examples/Dockerfile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM codercom/enterprise-base:ubuntu
2+
3+
# Install dependencies needed for Claude Code and VS Code
4+
# Using NodeSource to get a more recent version of Node.js
5+
RUN apt-get update && \
6+
apt-get install -y \
7+
curl \
8+
git \
9+
jq \
10+
screen \
11+
sudo \
12+
wget \
13+
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
14+
&& apt-get install -y nodejs \
15+
&& echo "Node.js version: $(node -v)" \
16+
&& echo "npm version: $(npm -v)" \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
# Create global npm directories with proper permissions
20+
RUN mkdir -p /usr/local/lib/node_modules && \
21+
chmod 777 /usr/local/lib/node_modules
22+
23+
# Claude Code CLI is installed via npm
24+
# Install the npm package directly for immediate availability
25+
RUN npm install -g @anthropic-ai/claude-code
26+
27+
# Set up user for Coder
28+
ARG USER=coder
29+
RUN useradd --groups sudo --create-home --shell /bin/bash ${USER} \
30+
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
31+
&& chmod 0440 /etc/sudoers.d/${USER}
32+
33+
USER ${USER}
34+
WORKDIR /home/${USER}
35+
36+
# Configure Claude for dashboard reporting
37+
ENV CODER_MCP_APP_STATUS_SLUG=claude
+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
docker = {
7+
source = "kreuzwerker/docker"
8+
}
9+
}
10+
}
11+
12+
provider "docker" {}
13+
provider "coder" {}
14+
15+
data "coder_workspace" "me" {}
16+
data "coder_workspace_owner" "me" {}
17+
18+
locals {
19+
username = data.coder_workspace_owner.me.name
20+
}
21+
22+
# Parameter for users to enter prompts directly from the workspace creation page
23+
data "coder_parameter" "ai_prompt" {
24+
type = "string"
25+
name = "AI Prompt"
26+
default = ""
27+
description = "Write a prompt for Claude Code"
28+
mutable = true
29+
ephemeral = true
30+
}
31+
32+
resource "coder_agent" "main" {
33+
arch = "amd64"
34+
os = "linux"
35+
dir = "/home/${local.username}"
36+
37+
startup_script = <<-EOT
38+
# Ensure screen is installed (required for Claude Code)
39+
if ! command -v screen &> /dev/null; then
40+
echo "Installing screen for Claude Code..."
41+
sudo apt-get update
42+
sudo apt-get install -y screen
43+
fi
44+
45+
# Ensure Node.js and npm are installed
46+
if ! command -v node &> /dev/null; then
47+
echo "Installing Node.js and npm..."
48+
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
49+
sudo apt-get install -y nodejs
50+
fi
51+
EOT
52+
53+
env = {
54+
# Git configuration
55+
GIT_AUTHOR_NAME = data.coder_workspace_owner.me.name
56+
GIT_AUTHOR_EMAIL = data.coder_workspace_owner.me.email
57+
GIT_COMMITTER_NAME = data.coder_workspace_owner.me.name
58+
GIT_COMMITTER_EMAIL = data.coder_workspace_owner.me.email
59+
}
60+
61+
# Basic workspace metrics
62+
metadata {
63+
display_name = "CPU Usage"
64+
key = "cpu_usage"
65+
script = "coder stat cpu"
66+
interval = 10
67+
timeout = 1
68+
}
69+
70+
metadata {
71+
display_name = "RAM Usage"
72+
key = "ram_usage"
73+
script = "coder stat mem"
74+
interval = 10
75+
timeout = 1
76+
}
77+
}
78+
79+
# Integrate Claude Code using the official module
80+
module "claude-code" {
81+
source = "registry.coder.com/modules/claude-code/coder"
82+
version = "1.2.1"
83+
agent_id = coder_agent.main.id
84+
85+
# Enable dashboard visualization features
86+
experiment_use_screen = true
87+
experiment_report_tasks = true
88+
}
89+
90+
# Configure Claude with Anthropic API key and Sonnet model
91+
resource "coder_env" "claude_api_key" {
92+
agent_id = coder_agent.main.id
93+
name = "CLAUDE_API_KEY"
94+
value = var.anthropic_api_key
95+
}
96+
97+
resource "coder_env" "claude_model" {
98+
agent_id = coder_agent.main.id
99+
name = "CLAUDE_MODEL"
100+
value = "claude-3-sonnet-20240229"
101+
}
102+
103+
# Pass parameter prompt to Claude Code
104+
resource "coder_env" "claude_task_prompt" {
105+
agent_id = coder_agent.main.id
106+
name = "CODER_MCP_CLAUDE_TASK_PROMPT"
107+
value = data.coder_parameter.ai_prompt.value
108+
}
109+
110+
# Add VS Code integration
111+
module "code-server" {
112+
source = "registry.coder.com/modules/code-server/coder"
113+
version = "1.0.2"
114+
agent_id = coder_agent.main.id
115+
folder = "/home/${local.username}"
116+
}
117+
118+
# Docker resources
119+
resource "docker_volume" "home_volume" {
120+
name = "coder-${data.coder_workspace.me.id}-home"
121+
lifecycle {
122+
ignore_changes = all
123+
}
124+
labels {
125+
label = "coder.workspace_id"
126+
value = data.coder_workspace.me.id
127+
}
128+
}
129+
130+
resource "docker_image" "main" {
131+
name = "codercom/enterprise-base:ubuntu"
132+
}
133+
134+
resource "docker_container" "workspace" {
135+
count = data.coder_workspace.me.start_count
136+
image = docker_image.main.name
137+
name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
138+
hostname = data.coder_workspace.me.name
139+
140+
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
141+
entrypoint = ["sh", "-c", coder_agent.main.init_script]
142+
143+
host {
144+
host = "host.docker.internal"
145+
ip = "host-gateway"
146+
}
147+
148+
volumes {
149+
container_path = "/home/${local.username}"
150+
volume_name = docker_volume.home_volume.name
151+
read_only = false
152+
}
153+
154+
labels {
155+
label = "coder.owner"
156+
value = data.coder_workspace_owner.me.name
157+
}
158+
159+
labels {
160+
label = "coder.workspace_id"
161+
value = data.coder_workspace.me.id
162+
}
163+
}
164+
165+
# Parameter for API authentication
166+
variable "anthropic_api_key" {
167+
type = string
168+
sensitive = true
169+
description = "Anthropic API key for Claude Sonnet integration"
170+
}
171+
172+
# Output with usage instructions
173+
output "claude_usage_instructions" {
174+
value = "Claude 3 Sonnet is available in this workspace. Use it through the terminal with 'claude-code \"Your prompt\"' or through the VS Code extension."
175+
}

0 commit comments

Comments
 (0)