Skip to content

Commit a2f6b25

Browse files
authored
Add new Dogfood template (#2959)
* Setup base template * Add sysbox * Run code-server in background * Fix small typo
1 parent a66b852 commit a2f6b25

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

dogfood/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# dogfood template
2+
3+
Ammar is this template's admin.
4+
5+
This template runs the `gcr.io/coder-dogfood/master/coder-dev-ubuntu` Docker
6+
image in a `sysbox-runc` container.
7+
8+
## Personalization
9+
10+
The startup script runs your `~/personalize` file if it exists.
11+
12+
## How is this hosted?
13+
14+
Coder dogfoods on a beefy, single Teraswitch machine. We decided to use
15+
a bare metal provider for best-in-class cost-to-performance. We decided to
16+
use a single machine for crazy fast parallelized builds and tests.
17+
18+
## How is the provisioner configured?
19+
20+
Our dogfood VM runs an SSH tunnel to our dogfood Docker host's docker socket.
21+
The socket is mounted on `/var/run/dogfood-docker.sock`.
22+
23+
The SSH command can be found hanging out in the screen session named
24+
`forward`.
25+
26+
The tunnel and corresponding SSH key is under the root user.

dogfood/main.tf

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
version = "0.4.2"
6+
}
7+
docker = {
8+
source = "kreuzwerker/docker"
9+
version = "~> 2.18.0"
10+
}
11+
}
12+
}
13+
14+
# Admin parameters
15+
16+
provider "docker" {
17+
host = "unix:///var/run/dogfood-docker.sock"
18+
}
19+
20+
provider "coder" {
21+
}
22+
23+
data "coder_workspace" "me" {
24+
}
25+
26+
resource "coder_agent" "dev" {
27+
arch = "amd64"
28+
os = "linux"
29+
startup_script = <<EOF
30+
#!/bin/sh
31+
set -x
32+
# install and start code-server
33+
curl -fsSL https://code-server.dev/install.sh | sh
34+
code-server --auth none --port 13337 &
35+
sudo service docker start
36+
if [ -f ~/personalize ]; then ~/personalize 2>&1 | tee ~/.personalize.log; fi
37+
EOF
38+
}
39+
40+
resource "coder_app" "code-server" {
41+
agent_id = coder_agent.dev.id
42+
name = "code-server"
43+
url = "http://localhost:13337/?folder=/home/coder"
44+
icon = "/icon/code.svg"
45+
}
46+
47+
48+
resource "docker_volume" "home_volume" {
49+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-home"
50+
}
51+
52+
resource "docker_container" "workspace" {
53+
count = data.coder_workspace.me.start_count
54+
image = "gcr.io/coder-dogfood/master/coder-dev-ubuntu:latest"
55+
# Uses lower() to avoid Docker restriction on container names.
56+
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
57+
# Hostname makes the shell more user friendly: coder@my-workspace:~$
58+
hostname = lower(data.coder_workspace.me.name)
59+
dns = ["1.1.1.1"]
60+
# Use the docker gateway if the access URL is 127.0.0.1
61+
command = [
62+
"sh", "-c",
63+
<<EOT
64+
trap '[ $? -ne 0 ] && echo === Agent script exited with non-zero code. Sleeping infinitely to preserve logs... && sleep infinity' EXIT
65+
${replace(coder_agent.dev.init_script, "localhost", "host.docker.internal")}
66+
EOT
67+
]
68+
# CPU limits are unnecessary since Docker will load balance automatically
69+
memory = 32768
70+
runtime = "sysbox-runc"
71+
env = ["CODER_AGENT_TOKEN=${coder_agent.dev.token}"]
72+
host {
73+
host = "host.docker.internal"
74+
ip = "host-gateway"
75+
}
76+
volumes {
77+
container_path = "/home/coder/"
78+
volume_name = docker_volume.home_volume.name
79+
read_only = false
80+
}
81+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy