@@ -7,14 +7,13 @@ user-controlled startup, repository selection, and infrastructure tuning.
7
7
8
8
Run independent dev containers in the same workspace so each component appears as its own agent.
9
9
10
- In this example, there are three : ` frontend ` , ` backend ` , and a ` database ` :
10
+ In this example, there are two : ` frontend ` and ` backend ` :
11
11
12
12
``` terraform
13
13
# Clone each repo
14
14
module "git_clone_frontend" {
15
15
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"
18
17
19
18
agent_id = coder_agent.main.id
20
19
url = "https://github.com/your-org/frontend.git"
@@ -23,24 +22,13 @@ module "git_clone_frontend" {
23
22
24
23
module "git_clone_backend" {
25
24
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"
28
26
29
27
agent_id = coder_agent.main.id
30
28
url = "https://github.com/your-org/backend.git"
31
29
base_dir = "/home/coder/backend"
32
30
}
33
31
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
-
44
32
# Dev container resources
45
33
resource "coder_devcontainer" "frontend" {
46
34
count = data.coder_workspace.me.start_count
@@ -54,11 +42,6 @@ resource "coder_devcontainer" "backend" {
54
42
workspace_folder = "/home/coder/backend/${module.git_clone_backend[0].folder_name}"
55
43
}
56
44
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
- }
62
45
```
63
46
64
47
Each dev container appears as a separate agent, so developers can connect to any
@@ -89,112 +72,40 @@ resource "coder_devcontainer" "frontend" {
89
72
90
73
Prompt users to pick a repository or team at workspace creation time and clone the selected repo(s) automatically into the workspace:
91
74
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
+ ```
195
106
196
107
## Troubleshooting
197
108
198
109
1. Run `docker ps` inside the workspace to ensure Docker is available.
199
110
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