Skip to content

Commit 0b79965

Browse files
committed
Merge branch 'main' into mes/template-validation-2
2 parents 45cf01b + fd074a5 commit 0b79965

File tree

5 files changed

+117
-9
lines changed

5 files changed

+117
-9
lines changed

registry/coder-labs/templates/docker-build/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ tags: [docker, container, dockerfile]
88

99
# Remote Development on Docker Containers (Build from Dockerfile)
1010

11+
> [!NOTE]
12+
> This template is designed to be a starting point for testing purposes.
13+
> In a production environment, you would want to move away from storing the Dockerfile in-template and move towards using a centralized image registry.
14+
1115
Build and provision Docker containers from a Dockerfile as [Coder workspaces](https://coder.com/docs/workspaces) with this example template.
1216

1317
This template builds a custom Docker image from the included Dockerfile, allowing you to customize the development environment by modifying the Dockerfile rather than using a pre-built image.
@@ -18,7 +22,22 @@ This template builds a custom Docker image from the included Dockerfile, allowin
1822

1923
### Infrastructure
2024

21-
The VM you run Coder on must have a running Docker socket and the `coder` user must be added to the Docker group:
25+
#### Running Coder inside Docker
26+
27+
If you installed Coder as a container within Docker, you will have to do the following things:
28+
29+
- Make the the Docker socket available to the container
30+
- **(recommended) Mount `/var/run/docker.sock` via `--mount`/`volume`**
31+
- _(advanced) Restrict the Docker socket via https://github.com/Tecnativa/docker-socket-proxy_
32+
- Set `--group-add`/`group_add` to the GID of the Docker group on the **host** machine
33+
- You can get the GID by running `getent group docker` on the **host** machine
34+
35+
If you are using `docker-compose`, here is an example on how to do those things (don't forget to edit `group_add`!):
36+
https://github.com/coder/coder/blob/0bfe0d63aec83ae438bdcb77e306effd100dba3d/docker-compose.yaml#L16-L23
37+
38+
#### Running Coder outside of Docker
39+
40+
If you installed Coder as a system package, the VM you run Coder on must have a running Docker socket and the `coder` user must be added to the Docker group:
2241

2342
```sh
2443
# Add coder user to Docker group

registry/coder/modules/zed/README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Zed is a high-performance, multiplayer code editor from the creators of Atom and
1919
module "zed" {
2020
count = data.coder_workspace.me.start_count
2121
source = "registry.coder.com/coder/zed/coder"
22-
version = "1.0.1"
22+
version = "1.1.0"
2323
agent_id = coder_agent.example.id
2424
}
2525
```
@@ -32,7 +32,7 @@ module "zed" {
3232
module "zed" {
3333
count = data.coder_workspace.me.start_count
3434
source = "registry.coder.com/coder/zed/coder"
35-
version = "1.0.1"
35+
version = "1.1.0"
3636
agent_id = coder_agent.example.id
3737
folder = "/home/coder/project"
3838
}
@@ -44,7 +44,7 @@ module "zed" {
4444
module "zed" {
4545
count = data.coder_workspace.me.start_count
4646
source = "registry.coder.com/coder/zed/coder"
47-
version = "1.0.1"
47+
version = "1.1.0"
4848
agent_id = coder_agent.example.id
4949
display_name = "Zed Editor"
5050
order = 1
@@ -57,8 +57,36 @@ module "zed" {
5757
module "zed" {
5858
count = data.coder_workspace.me.start_count
5959
source = "registry.coder.com/coder/zed/coder"
60-
version = "1.0.1"
60+
version = "1.1.0"
6161
agent_id = coder_agent.example.id
6262
agent_name = coder_agent.example.name
6363
}
6464
```
65+
66+
### Configure Zed settings including MCP servers
67+
68+
Zed stores settings at `~/.config/zed/settings.json` by default. If `XDG_CONFIG_HOME` is set on Linux, settings will be at `$XDG_CONFIG_HOME/zed/settings.json`.
69+
70+
You can declaratively set/merge settings with the `settings` input. Provide a JSON string (e.g., via `jsonencode(...)`). For example, to configure MCP servers:
71+
72+
```tf
73+
module "zed" {
74+
count = data.coder_workspace.me.start_count
75+
source = "registry.coder.com/coder/zed/coder"
76+
version = "1.1.0"
77+
agent_id = coder_agent.example.id
78+
79+
settings = jsonencode({
80+
context_servers = {
81+
your-mcp-server = {
82+
source = "custom"
83+
command = "some-command"
84+
args = ["arg-1", "arg-2"]
85+
env = {}
86+
}
87+
}
88+
})
89+
}
90+
```
91+
92+
See Zed’s settings files documentation: https://zed.dev/docs/configuring-zed#settings-files

registry/coder/modules/zed/main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ variable "display_name" {
5050
default = "Zed"
5151
}
5252

53+
variable "settings" {
54+
type = string
55+
description = "JSON encoded settings.json"
56+
default = ""
57+
}
58+
5359
data "coder_workspace" "me" {}
60+
5461
data "coder_workspace_owner" "me" {}
5562

5663
locals {
@@ -60,6 +67,30 @@ locals {
6067
hostname = var.agent_name != "" ? "${local.agent_name}.${local.workspace_name}.${local.owner_name}.coder" : "${local.workspace_name}.coder"
6168
}
6269

70+
resource "coder_script" "zed_settings" {
71+
agent_id = var.agent_id
72+
display_name = "Configure Zed settings"
73+
icon = "/icon/zed.svg"
74+
run_on_start = true
75+
script = <<-EOT
76+
set -eu
77+
SETTINGS_JSON='${replace(var.settings, "\"", "\\\"")}'
78+
if [ -z "$${SETTINGS_JSON}" ] || [ "$${SETTINGS_JSON}" = "{}" ]; then
79+
exit 0
80+
fi
81+
CONFIG_HOME="$${XDG_CONFIG_HOME:-$HOME/.config}"
82+
ZED_DIR="$${CONFIG_HOME}/zed"
83+
mkdir -p "$${ZED_DIR}"
84+
SETTINGS_FILE="$${ZED_DIR}/settings.json"
85+
if command -v jq >/dev/null 2>&1 && [ -s "$${SETTINGS_FILE}" ]; then
86+
tmpfile="$(mktemp)"
87+
jq -s '.[0] * .[1]' "$${SETTINGS_FILE}" <(printf '%s\n' "$${SETTINGS_JSON}") > "$${tmpfile}" && mv "$${tmpfile}" "$${SETTINGS_FILE}"
88+
else
89+
printf '%s\n' "$${SETTINGS_JSON}" > "$${SETTINGS_FILE}"
90+
fi
91+
EOT
92+
}
93+
6394
resource "coder_app" "zed" {
6495
agent_id = var.agent_id
6596
display_name = var.display_name

registry/coder/templates/docker-devcontainer/README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,26 @@ Provision Devcontainers as [Coder workspaces](https://coder.com/docs/workspaces)
1414

1515
### Infrastructure
1616

17-
Coder must have access to a running Docker socket, and the `coder` user must be a member of the `docker` group:
17+
#### Running Coder inside Docker
1818

19-
```shell
19+
If you installed Coder as a container within Docker, you will have to do the following things:
20+
21+
- Make the the Docker socket available to the container
22+
- **(recommended) Mount `/var/run/docker.sock` via `--mount`/`volume`**
23+
- _(advanced) Restrict the Docker socket via https://github.com/Tecnativa/docker-socket-proxy_
24+
- Set `--group-add`/`group_add` to the GID of the Docker group on the **host** machine
25+
- You can get the GID by running `getent group docker` on the **host** machine
26+
27+
If you are using `docker-compose`, here is an example on how to do those things (don't forget to edit `group_add`!):
28+
https://github.com/coder/coder/blob/0bfe0d63aec83ae438bdcb77e306effd100dba3d/docker-compose.yaml#L16-L23
29+
30+
#### Running Coder outside of Docker
31+
32+
If you installed Coder as a system package, the VM you run Coder on must have a running Docker socket and the `coder` user must be added to the Docker group:
33+
34+
```sh
2035
# Add coder user to Docker group
21-
sudo usermod -aG docker coder
36+
sudo adduser coder docker
2237

2338
# Restart Coder server
2439
sudo systemctl restart coder

registry/coder/templates/docker/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,22 @@ Provision Docker containers as [Coder workspaces](https://coder.com/docs/workspa
1616

1717
### Infrastructure
1818

19-
The VM you run Coder on must have a running Docker socket and the `coder` user must be added to the Docker group:
19+
#### Running Coder inside Docker
20+
21+
If you installed Coder as a container within Docker, you will have to do the following things:
22+
23+
- Make the the Docker socket available to the container
24+
- **(recommended) Mount `/var/run/docker.sock` via `--mount`/`volume`**
25+
- _(advanced) Restrict the Docker socket via https://github.com/Tecnativa/docker-socket-proxy_
26+
- Set `--group-add`/`group_add` to the GID of the Docker group on the **host** machine
27+
- You can get the GID by running `getent group docker` on the **host** machine
28+
29+
If you are using `docker-compose`, here is an example on how to do those things (don't forget to edit `group_add`!):
30+
https://github.com/coder/coder/blob/0bfe0d63aec83ae438bdcb77e306effd100dba3d/docker-compose.yaml#L16-L23
31+
32+
#### Running Coder outside of Docker
33+
34+
If you installed Coder as a system package, the VM you run Coder on must have a running Docker socket and the `coder` user must be added to the Docker group:
2035

2136
```sh
2237
# Add coder user to Docker group

0 commit comments

Comments
 (0)