Skip to content

Commit 67702ae

Browse files
committed
tested configs; remove untested
1 parent 1804190 commit 67702ae

File tree

1 file changed

+35
-124
lines changed

1 file changed

+35
-124
lines changed

docs/admin/templates/extending-templates/advanced-dev-containers.md

Lines changed: 35 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ user-controlled startup, repository selection, and infrastructure tuning.
77

88
Run independent dev containers in the same workspace so each component appears as its own agent.
99

10-
In this example, there are three: `frontend`, `backend`, and a `database`:
10+
In this example, there are two: `frontend` and `backend`:
1111

1212
```terraform
1313
# Clone each repo
1414
module "git_clone_frontend" {
1515
count = data.coder_workspace.me.start_count
16-
source = "registry.coder.com/modules/git-clone/coder"
17-
version = "~> 1.0"
16+
source = "dev.registry.coder.com/modules/git-clone/coder"
1817
1918
agent_id = coder_agent.main.id
2019
url = "https://github.com/your-org/frontend.git"
@@ -23,24 +22,13 @@ module "git_clone_frontend" {
2322
2423
module "git_clone_backend" {
2524
count = data.coder_workspace.me.start_count
26-
source = "registry.coder.com/modules/git-clone/coder"
27-
version = "~> 1.0"
25+
source = "dev.registry.coder.com/modules/git-clone/coder"
2826
2927
agent_id = coder_agent.main.id
3028
url = "https://github.com/your-org/backend.git"
3129
base_dir = "/home/coder/backend"
3230
}
3331
34-
module "git_clone_database" {
35-
count = data.coder_workspace.me.start_count
36-
source = "registry.coder.com/modules/git-clone/coder"
37-
version = "~> 1.0"
38-
39-
agent_id = coder_agent.main.id
40-
url = "https://github.com/your-org/database.git"
41-
base_dir = "/home/coder/database"
42-
}
43-
4432
# Dev container resources
4533
resource "coder_devcontainer" "frontend" {
4634
count = data.coder_workspace.me.start_count
@@ -54,11 +42,6 @@ resource "coder_devcontainer" "backend" {
5442
workspace_folder = "/home/coder/backend/${module.git_clone_backend[0].folder_name}"
5543
}
5644
57-
resource "coder_devcontainer" "database" {
58-
count = data.coder_workspace.me.start_count
59-
agent_id = coder_agent.main.id
60-
workspace_folder = "/home/coder/database/${module.git_clone_database[0].folder_name}"
61-
}
6245
```
6346

6447
Each dev container appears as a separate agent, so developers can connect to any
@@ -89,112 +72,40 @@ resource "coder_devcontainer" "frontend" {
8972

9073
Prompt users to pick a repository or team at workspace creation time and clone the selected repo(s) automatically into the workspace:
9174

92-
### Dropdown selector
93-
94-
```terraform
95-
data "coder_parameter" "project" {
96-
name = "Project"
97-
description = "Choose a project"
98-
type = "string"
99-
mutable = true
100-
order = 1
101-
102-
option { name = "E-commerce FE" value = "https://github.com/org/ecom-fe.git" icon = "/icon/react.svg" }
103-
option { name = "Payment API" value = "https://github.com/org/pay.git" icon = "/icon/nodejs.svg" }
104-
}
105-
106-
module "git_clone_selected" {
107-
count = data.coder_workspace.me.start_count
108-
source = "registry.coder.com/modules/git-clone/coder"
109-
version = "~> 1.0"
110-
111-
agent_id = coder_agent.main.id
112-
url = data.coder_parameter.project.value
113-
base_dir = "/home/coder/project"
114-
}
115-
```
116-
117-
### Team-based selection
118-
119-
```terraform
120-
data "coder_parameter" "team" {
121-
name = "Team"
122-
type = "string"
123-
mutable = true
124-
order = 1
125-
126-
option { name = "Frontend" value = "frontend" icon = "/icon/react.svg" }
127-
option { name = "Backend" value = "backend" icon = "/icon/nodejs.svg" }
128-
}
129-
130-
locals {
131-
repos = {
132-
frontend = ["https://github.com/your-org/web.git"]
133-
backend = ["https://github.com/your-org/api.git"]
134-
}
135-
}
136-
137-
module "git_clone_team" {
138-
count = length(local.repos[data.coder_parameter.team.value]) * data.coder_workspace.me.start_count
139-
source = "registry.coder.com/modules/git-clone/coder"
140-
version = "~> 1.0"
141-
142-
agent_id = coder_agent.main.id
143-
url = local.repos[data.coder_parameter.team.value][count.index]
144-
base_dir = "/home/coder/${replace(basename(url), \".git\", \"\")}"
145-
}
146-
```
147-
148-
## Infrastructure Tuning
149-
150-
Adjust workspace infrastructure to set memory/CPU limits, attach a custom Docker network,
151-
or add persistent volumes—to improve performance and isolation for dev containers:
152-
153-
### Resource limits
154-
155-
```terraform
156-
resource "docker_container" "workspace" {
157-
count = data.coder_workspace.me.start_count
158-
image = "codercom/enterprise-node:ubuntu"
159-
160-
resources {
161-
memory = 4096 # MiB
162-
cpus = 2
163-
memory_swap = 8192
164-
}
165-
}
166-
```
167-
168-
### Custom network
169-
170-
```terraform
171-
resource "docker_network" "dev" {
172-
name = "coder-${data.coder_workspace.me.id}-dev"
173-
}
174-
175-
resource "docker_container" "workspace" {
176-
networks_advanced { name = docker_network.dev.name }
177-
}
178-
```
179-
180-
### Volume caching
181-
182-
```terraform
183-
resource "docker_volume" "node_modules" {
184-
name = "coder-${data.coder_workspace.me.id}-node-modules"
185-
lifecycle { ignore_changes = all }
186-
}
187-
188-
resource "docker_container" "workspace" {
189-
volumes {
190-
container_path = "/home/coder/project/node_modules"
191-
volume_name = docker_volume.node_modules.name
192-
}
193-
}
194-
```
75+
1. Add a parameter to the template:
76+
77+
```terraform
78+
data "coder_parameter" "project" {
79+
name = "project"
80+
display_name = "Choose a project"
81+
type = "string"
82+
default = "https://github.com/coder/coder.git"
83+
84+
option {
85+
name = "coder/coder"
86+
value = "https://github.com/coder/coder.git"
87+
}
88+
option {
89+
name = "Dev Container template"
90+
value = "https://github.com/devcontainers/template-starter.git"
91+
}
92+
}
93+
```
94+
95+
1. Change the `git_clone` module to accept the `value` as the `url`:
96+
97+
```terraform
98+
module "git_clone" {
99+
count = data.coder_workspace.me.start_count
100+
source = "dev.registry.coder.com/modules/git-clone/coder"
101+
agent_id = coder_agent.main.id
102+
url = data.coder_parameter.project.value
103+
base_dir = "/home/coder"
104+
}
105+
```
195106
196107
## Troubleshooting
197108
198109
1. Run `docker ps` inside the workspace to ensure Docker is available.
199110
1. Check `/tmp/coder-agent.log` for agent logs.
200-
1. Verify the workspace image includes Node/npm or add the `nodejs` module before the `devcontainers_cli` module.
111+
1. Verify that the workspace image includes Node/npm.

0 commit comments

Comments
 (0)