Skip to content

Commit c502247

Browse files
mafredripull[bot]
authored andcommitted
chore: Unify Docker terraform templates (#4952)
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 7401249 commit c502247

File tree

5 files changed

+17
-32
lines changed

5 files changed

+17
-32
lines changed

dogfood/main.tf

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,11 @@ resource "docker_image" "dogfood" {
9090
resource "docker_container" "workspace" {
9191
count = data.coder_workspace.me.start_count
9292
image = docker_image.dogfood.name
93-
# Uses lower() to avoid Docker restriction on container names.
94-
name = local.container_name
93+
name = local.container_name
9594
# Hostname makes the shell more user friendly: coder@my-workspace:~$
96-
hostname = lower(data.coder_workspace.me.name)
97-
dns = ["1.1.1.1"]
95+
hostname = data.coder_workspace.me.name
9896
# 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-
]
97+
entrypoint = ["sh", "-c", replace(coder_agent.dev.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
10698
# CPU limits are unnecessary since Docker will load balance automatically
10799
memory = 32768
108100
runtime = "sysbox-runc"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ resource "docker_container" "workspace" {
6161
count = data.coder_workspace.me.start_count
6262
image = "codercom/code-server:latest"
6363
# Uses lower() to avoid Docker restriction on container names.
64-
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"]
64+
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@ 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
96-
command = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
97-
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
95+
entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
96+
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
9897
host {
9998
host = "host.docker.internal"
10099
ip = "host-gateway"

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ 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
60-
command = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
61-
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
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
61+
entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
62+
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
6263
host {
6364
host = "host.docker.internal"
6465
ip = "host-gateway"

examples/templates/docker/main.tf

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,10 @@ 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-
]
93-
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
85+
entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
86+
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
9487
host {
9588
host = "host.docker.internal"
9689
ip = "host-gateway"

0 commit comments

Comments
 (0)