Skip to content

Commit 4a34a91

Browse files
committed
chore: Unify Docker terraform templates
Changes to terraform templates: * Remove DNS (this can interfere with users running their own DNS servers) * Remove `lower()` restriction from hostnames so that it will show the name set by the user, as-is (there is no restriction on upper case letters in hostnames) * Remove superfluous `trap` in entrypoints, this is already handled by the init script * Switch from `command` to `entrypoint` as the latter can support more Docker images out-of-the-box
1 parent bf4a6fb commit 4a34a91

File tree

5 files changed

+9
-23
lines changed

5 files changed

+9
-23
lines changed

dogfood/main.tf

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,8 @@ resource "docker_container" "workspace" {
9494
name = local.container_name
9595
# Hostname makes the shell more user friendly: coder@my-workspace:~$
9696
hostname = lower(data.coder_workspace.me.name)
97-
dns = ["1.1.1.1"]
9897
# Use the docker gateway if the access URL is 127.0.0.1
99-
command = [
100-
"sh", "-c",
101-
<<EOT
102-
trap '[ $? -ne 0 ] && echo === Agent script exited with non-zero code. Sleeping infinitely to preserve logs... && sleep infinity' EXIT
103-
${replace(coder_agent.dev.init_script, "localhost", "host.docker.internal")}
104-
EOT
105-
]
98+
command = ["sh", "-c", replace(coder_agent.dev.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
10699
# CPU limits are unnecessary since Docker will load balance automatically
107100
memory = 32768
108101
runtime = "sysbox-runc"

examples/templates/docker-code-server/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ resource "docker_container" "workspace" {
6262
image = "codercom/code-server:latest"
6363
# Uses lower() to avoid Docker restriction on container names.
6464
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
65-
hostname = lower(data.coder_workspace.me.name)
66-
dns = ["1.1.1.1"]
65+
# Hostname makes the shell more user friendly: coder@my-workspace:~$
66+
hostname = data.coder_workspace.me.name
6767
# Use the docker gateway if the access URL is 127.0.0.1
6868
entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
6969
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]

examples/templates/docker-image-builds/main.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ resource "docker_container" "workspace" {
9090
# Uses lower() to avoid Docker restriction on container names.
9191
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
9292
# Hostname makes the shell more user friendly: coder@my-workspace:~$
93-
hostname = lower(data.coder_workspace.me.name)
94-
dns = ["1.1.1.1"]
93+
hostname = data.coder_workspace.me.name
9594
# Use the docker gateway if the access URL is 127.0.0.1
9695
command = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
9796
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]

examples/templates/docker-with-dotfiles/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ resource "docker_container" "workspace" {
5555
image = var.docker_image
5656
# Uses lower() to avoid Docker restriction on container names.
5757
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
58-
dns = ["1.1.1.1"]
59-
# Refer to Docker host when Coder is on localhost
58+
# Hostname makes the shell more user friendly: coder@my-workspace:~$
59+
hostname = data.coder_workspace.me.name
60+
# Use the docker gateway if the access URL is 127.0.0.1
6061
command = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
6162
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
6263
host {

examples/templates/docker/main.tf

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,9 @@ resource "docker_container" "workspace" {
8080
# Uses lower() to avoid Docker restriction on container names.
8181
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
8282
# Hostname makes the shell more user friendly: coder@my-workspace:~$
83-
hostname = lower(data.coder_workspace.me.name)
84-
dns = ["1.1.1.1"]
83+
hostname = data.coder_workspace.me.name
8584
# Use the docker gateway if the access URL is 127.0.0.1
86-
command = [
87-
"sh", "-c",
88-
<<EOT
89-
trap '[ $? -ne 0 ] && echo === Agent script exited with non-zero code. Sleeping infinitely to preserve logs... && sleep infinity' EXIT
90-
${replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")}
91-
EOT
92-
]
85+
command = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
9386
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
9487
host {
9588
host = "host.docker.internal"

0 commit comments

Comments
 (0)