@@ -19,11 +19,35 @@ When integrated with Coder templates, they provide:
19
19
20
20
##Prerequisites
21
21
22
- Dev containers require Docker to build and run containers.
23
- Ensure your workspace infrastructure has Docker configured with container creation permissions and sufficient resources.
22
+ - Dev containers require Docker to build and run containers inside the workspace.
24
23
25
- To confirm that Docker is configured correctly, create a test workspace and confirm that` docker ps ` runs.
26
- If it doesn't, follow the steps in[ Docker in workspaces] ( ./docker-in-workspaces.md ) .
24
+ Ensure your workspace infrastructure has Docker configured with container creation permissions and sufficient resources.
25
+
26
+ To confirm that Docker is configured correctly, create a test workspace and confirm that` docker ps ` runs.
27
+ If it doesn't, follow the steps in[ Docker in workspaces] ( ./docker-in-workspaces.md ) .
28
+
29
+ - The` devcontainers-cli ` module requires npm.
30
+
31
+ - Use an image that already includes npm, such as` codercom/enterprise-node:ubuntu `
32
+ - <details ><summary >If your template doesn't already include npm, install it at runtime with the `nodejs` module:</summary >
33
+
34
+ 1 . This block should be before the` devcontainers-cli ` block in` main.tf ` :
35
+
36
+ ``` terraform
37
+ module "nodejs" {
38
+ count = data.coder_workspace.me.start_count
39
+ source = "dev.registry.coder.com/modules/nodejs/coder"
40
+ agent_id = coder_agent.main.id
41
+ }
42
+ ```
43
+
44
+ 1. Add `depends_on` to the `devcontainers-cli` module block:
45
+
46
+ ```terraform
47
+ depends_on = [module.nodejs]
48
+ ```
49
+
50
+ </details>
27
51
28
52
## Enable Dev Containers Integration
29
53
@@ -50,7 +74,7 @@ to install `@devcontainers/cli` in your workspace:
50
74
module "devcontainers-cli" {
51
75
count = data.coder_workspace.me.start_count
52
76
source = "dev.registry.coder.com/modules/devcontainers-cli/coder"
53
- agent_id = coder_agent.dev .id
77
+ agent_id = coder_agent.main .id
54
78
}
55
79
```
56
80
@@ -62,12 +86,12 @@ RUN npm install -g @devcontainers/cli
62
86
63
87
##Define the dev container resource
64
88
65
- Point the resource at the folder that contains` devcontainer.json ` :
89
+ If you don't use [ ` git_clone ` ] ( #clone-the-repository ) , point the resource at the folder that contains` devcontainer.json ` :
66
90
67
91
``` terraform
68
92
resource "coder_devcontainer" "project" {
69
93
count = data.coder_workspace.me.start_count
70
- agent_id = coder_agent.dev .id
94
+ agent_id = coder_agent.main .id
71
95
workspace_folder = "/home/coder/project"
72
96
}
73
97
```
@@ -76,41 +100,26 @@ resource "coder_devcontainer" "project" {
76
100
77
101
This step is optional, but it ensures that the project is present before the dev container starts.
78
102
103
+ Note that if you use the` git_clone ` module, place it before the` coder_devcontainer ` resource
104
+ and update or replace that resource to point at` /home/coder/project/${module.git_clone[0].folder_name} ` so that it is only defined once:
105
+
79
106
``` terraform
80
107
module "git_clone" {
81
108
count = data.coder_workspace.me.start_count
82
109
source = "dev.registry.coder.com/modules/git-clone/coder"
83
- agent_id = coder_agent.dev .id
110
+ agent_id = coder_agent.main .id
84
111
url = "https://github.com/example/project.git"
85
- path = "/home/coder/project"
112
+ base_dir = "/home/coder/project"
86
113
}
87
114
88
115
resource "coder_devcontainer" "project" {
89
116
count = data.coder_workspace.me.start_count
90
- agent_id = coder_agent.dev .id
91
- workspace_folder = module.git_clone[0].path
117
+ agent_id = coder_agent.main .id
118
+ workspace_folder ="/home/coder/project/${ module.git_clone[0].folder_name}"
92
119
depends_on = [module.git_clone]
93
120
}
94
121
```
95
122
96
- ##Configure Automatic Dev Container Startup
97
-
98
- The
99
- [ ` coder_devcontainer ` ] ( https://registry.terraform.io/providers/coder/coder/latest/docs/resources/devcontainer )
100
- resource automatically starts a dev container in your workspace, ensuring it's
101
- ready when you access the workspace:
102
-
103
- ``` terraform
104
- resource "coder_devcontainer" "my-repository" {
105
- count = data.coder_workspace.me.start_count
106
- agent_id = coder_agent.dev.id
107
- workspace_folder = "/home/coder/my-repository"
108
- }
109
- ```
110
-
111
- The` workspace_folder ` attribute must specify the location of the dev container's workspace and should point to a
112
- valid project folder that contains a` devcontainer.json ` file.
113
-
114
123
##Dev container features
115
124
116
125
Enhance your dev container experience with additional features.
@@ -144,22 +153,22 @@ For more advanced use cases, consult the [advanced dev containers doc](./advance
144
153
Coder names dev container agents in this order:
145
154
146
155
1 . ` customizations.coder.agent.name ` in` devcontainer.json `
147
- 2 . ` name ` in` devcontainer.json `
148
- 3 . Directory name that contains the config
149
- 4 . ` devcontainer ` (default)
156
+ 1 . ` name ` in` devcontainer.json `
157
+ 1 . Directory name that contains the config
158
+ 1 . ` devcontainer ` (default)
150
159
151
160
###Multiple dev containers
152
161
153
162
``` terraform
154
163
resource "coder_devcontainer" "frontend" {
155
164
count = data.coder_workspace.me.start_count
156
- agent_id = coder_agent.dev .id
165
+ agent_id = coder_agent.main .id
157
166
workspace_folder = "/home/coder/frontend"
158
167
}
159
168
160
169
resource "coder_devcontainer" "backend" {
161
170
count = data.coder_workspace.me.start_count
162
- agent_id = coder_agent.dev .id
171
+ agent_id = coder_agent.main .id
163
172
workspace_folder = "/home/coder/backend"
164
173
}
165
174
```
@@ -181,7 +190,7 @@ terraform {
181
190
data "coder_workspace" "me" {}
182
191
data "coder_workspace_owner" "me" {}
183
192
184
- resource "coder_agent" "dev " {
193
+ resource "coder_agent" "main " {
185
194
os = "linux"
186
195
arch = "amd64"
187
196
env = { CODER_AGENT_DEVCONTAINERS_ENABLE = "true" }
@@ -194,28 +203,28 @@ resource "coder_agent" "dev" {
194
203
module "devcontainers_cli" {
195
204
count = data.coder_workspace.me.start_count
196
205
source = "dev.registry.coder.com/modules/devcontainers-cli/coder"
197
- agent_id = coder_agent.dev .id
206
+ agent_id = coder_agent.main .id
198
207
}
199
208
200
209
module "git_clone" {
201
210
count = data.coder_workspace.me.start_count
202
211
source = "dev.registry.coder.com/modules/git-clone/coder"
203
- agent_id = coder_agent.dev .id
212
+ agent_id = coder_agent.main .id
204
213
url = "https://github.com/example/project.git"
205
- path = "/home/coder/project"
214
+ base_dir = "/home/coder/project"
206
215
}
207
216
208
217
resource "coder_devcontainer" "project" {
209
218
count = data.coder_workspace.me.start_count
210
- agent_id = coder_agent.dev .id
211
- workspace_folder = module.git_clone[0].path
219
+ agent_id = coder_agent.main .id
220
+ workspace_folder ="/home/coder/project/${ module.git_clone[0].folder_name}"
212
221
depends_on = [module.git_clone]
213
222
}
214
223
215
224
resource "docker_container" "workspace" {
216
225
count = data.coder_workspace.me.start_count
217
- image = "codercom/enterprise-base :ubuntu"
218
- name = "coder-$ta .coder_workspace_owner.me.name}-$ta .coder_workspace.me.name}"
226
+ image = "codercom/enterprise-node :ubuntu"
227
+ name = "coder-${data .coder_workspace_owner.me.name}-${lower(data .coder_workspace.me.name) }"
219
228
privileged = true # or mount /var/run/docker.sock
220
229
}
221
230
```
@@ -235,7 +244,7 @@ terraform {
235
244
data "coder_workspace" "me" {}
236
245
data "coder_workspace_owner" "me" {}
237
246
238
- resource "coder_agent" "dev " {
247
+ resource "coder_agent" "main " {
239
248
os = "linux"
240
249
arch = "amd64"
241
250
env = { CODER_AGENT_DEVCONTAINERS_ENABLE = "true" }
@@ -247,45 +256,45 @@ resource "coder_agent" "dev" {
247
256
module "devcontainers_cli" {
248
257
count = data.coder_workspace.me.start_count
249
258
source = "dev.registry.coder.com/modules/devcontainers-cli/coder"
250
- agent_id = coder_agent.dev .id
259
+ agent_id = coder_agent.main .id
251
260
}
252
261
253
262
module "git_clone" {
254
263
count = data.coder_workspace.me.start_count
255
264
source = "dev.registry.coder.com/modules/git-clone/coder"
256
- agent_id = coder_agent.dev .id
265
+ agent_id = coder_agent.main .id
257
266
url = "https://github.com/example/project.git"
258
- path = "/home/coder/project"
267
+ base_dir = "/home/coder/project"
259
268
}
260
269
261
270
resource "coder_devcontainer" "project" {
262
271
count = data.coder_workspace.me.start_count
263
- agent_id = coder_agent.dev .id
264
- workspace_folder = module.git_clone[0].path
272
+ agent_id = coder_agent.main .id
273
+ workspace_folder ="/home/coder/project/${ module.git_clone[0].folder_name}"
265
274
depends_on = [module.git_clone]
266
275
}
267
276
268
277
resource "kubernetes_pod" "workspace" {
269
278
count = data.coder_workspace.me.start_count
270
279
271
280
metadata {
272
- name = "coder-$ta .coder_workspace_owner.me.name}-$ta .coder_workspace.me.name}"
281
+ name = "coder-${data .coder_workspace_owner.me.name}-${lower(data .coder_workspace.me.name) }"
273
282
namespace = "coder-workspaces"
274
283
}
275
284
276
285
spec {
277
286
container {
278
- name = "dev "
287
+ name = "main "
279
288
image = "codercom/enterprise-base:ubuntu"
280
289
281
290
security_context { privileged = true } # or use Sysbox / rootless
282
- env { name = "CODER_AGENT_TOKEN" value = coder_agent.dev .token }
291
+ env { name = "CODER_AGENT_TOKEN" value = coder_agent.main .token }
283
292
}
284
293
}
285
294
}
286
295
```
287
296
288
- </detail >
297
+ </details >
289
298
290
299
##Troubleshoot common issues
291
300