Skip to content

Commit 6bb4a4c

Browse files
bpmctmatifali
andauthored
chore: add latest dogfood template (#7321)
Co-authored-by: Muhammad Atif Ali <matifali@live.com>
1 parent 8d4a8fd commit 6bb4a4c

13 files changed

+124
-45
lines changed

dogfood/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ RUN mkdir --parents "$GOPATH" && \
5353
# charts and values files
5454
go install github.com/norwoodj/helm-docs/cmd/helm-docs@v1.5.0 && \
5555
# sqlc for Go code generation
56-
go install github.com/kyleconroy/sqlc/cmd/sqlc@v1.17.2 && \
56+
go install github.com/kyleconroy/sqlc/cmd/sqlc@v1.16.0 && \
5757
# gcr-cleaner-cli used by CI to prune unused images
5858
go install github.com/sethvargo/gcr-cleaner/cmd/gcr-cleaner-cli@v0.5.1 && \
5959
# ruleguard for checking custom rules, without needing to run all of
852 Bytes
Binary file not shown.
2.09 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
909 Bytes
Binary file not shown.
2.15 KB
Binary file not shown.
452 Bytes
Binary file not shown.
826 Bytes
Binary file not shown.
1.72 KB
Binary file not shown.
2.57 KB
Binary file not shown.
8.02 KB
Binary file not shown.

dogfood/main.tf

+123-44
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
coder = {
44
source = "coder/coder"
5-
version = "0.6.10"
5+
version = "0.7.0"
66
}
77
docker = {
88
source = "kreuzwerker/docker"
@@ -11,67 +11,155 @@ terraform {
1111
}
1212
}
1313

14-
# User parameters
15-
16-
variable "region" {
17-
type = string
18-
description = "Which region to deploy to."
19-
default = "us-pittsburgh"
20-
validation {
21-
condition = contains(["us-pittsburgh", "eu-helsinki", "ap-sydney"], var.region)
22-
error_message = "Region must be one of us-pittsburg, eu-helsinki, or ap-sydney."
23-
}
24-
}
25-
26-
variable "dotfiles_uri" {
27-
type = string
28-
description = <<-EOF
29-
Dotfiles repo URI (optional)
30-
31-
see https://dotfiles.github.io
32-
EOF
33-
default = ""
34-
}
35-
36-
variable "datocms_api_token" {
37-
type = string
38-
description = "An API token from DATOCMS for usage with building our website."
39-
default = ""
40-
}
41-
4214
locals {
4315
// These are Tailscale IP addresses. Ask Dean or Kyle for help.
4416
docker_host = {
4517
"" = "tcp://100.94.74.63:2375"
4618
"us-pittsburgh" = "tcp://100.94.74.63:2375"
4719
"eu-helsinki" = "tcp://100.117.102.81:2375"
4820
"ap-sydney" = "tcp://100.87.194.110:2375"
21+
"sa-saopaulo" = "tcp://100.99.64.123:2375"
22+
"eu-paris" = "tcp://100.74.161.61:2375"
4923
}
5024
}
5125

26+
data "coder_parameter" "repo_dir" {
27+
type = "string"
28+
name = "Coder Repository Directory"
29+
default = "~/coder"
30+
description = "The directory specified will be created and [coder/coder](https://github.com/coder/coder) will be automatically cloned into it 🪄."
31+
mutable = true
32+
}
33+
34+
data "coder_parameter" "dotfiles_url" {
35+
type = "string"
36+
name = "Dotfiles URL"
37+
description = "A path to your dotfiles. See: https://dotfiles.github.io"
38+
default = " "
39+
mutable = true
40+
}
41+
42+
data "coder_parameter" "region" {
43+
type = "string"
44+
name = "Region"
45+
icon = "/emojis/1f30e.png"
46+
option {
47+
icon = "/emojis/1f1fa-1f1f8.png"
48+
name = "Pittsburgh"
49+
value = "us-pittsburgh"
50+
}
51+
option {
52+
icon = "/emojis/1f1eb-1f1ee.png"
53+
name = "Helsinki"
54+
value = "eu-helsinki"
55+
}
56+
option {
57+
icon = "/emojis/1f1e6-1f1fa.png"
58+
name = "Sydney"
59+
value = "ap-sydney"
60+
}
61+
option {
62+
icon = "/emojis/1f1e7-1f1f7.png"
63+
name = "São Paulo"
64+
value = "sa-saopaulo"
65+
}
66+
# option {
67+
# icon = "/emojis/1f1eb-1f1f7.png"
68+
# name = "Phorcys' Server in Paris"
69+
# value = "eu-paris"
70+
# }
71+
}
72+
5273
provider "docker" {
53-
host = lookup(local.docker_host, var.region)
74+
host = lookup(local.docker_host, data.coder_parameter.region.value)
5475
}
5576

5677
provider "coder" {}
5778

79+
data "coder_git_auth" "github" {
80+
id = "github"
81+
}
82+
5883
data "coder_workspace" "me" {}
5984

6085
resource "coder_agent" "dev" {
6186
arch = "amd64"
6287
os = "linux"
6388

64-
login_before_ready = false
89+
dir = data.coder_parameter.repo_dir.value
90+
env = {
91+
GITHUB_TOKEN : data.coder_git_auth.github.access_token,
92+
OIDC_TOKEN : data.coder_workspace.me.owner_oidc_access_token,
93+
}
94+
login_before_ready = false
95+
96+
metadata {
97+
display_name = "CPU Usage"
98+
key = "cpu"
99+
script = <<EOT
100+
vmstat | awk 'FNR==3 {printf "%2.0f%%", $13+$14+$16}'
101+
EOT
102+
interval = 1
103+
timeout = 1
104+
}
105+
106+
metadata {
107+
display_name = "Load Average"
108+
key = "load"
109+
script = "awk '{print $1}' /proc/loadavg"
110+
interval = 1
111+
timeout = 1
112+
}
113+
114+
metadata {
115+
display_name = "Disk Usage"
116+
key = "disk"
117+
script = "df -h | awk '$6 ~ /^\\/$/ { print $5 }'"
118+
interval = 1
119+
timeout = 1
120+
}
121+
122+
metadata {
123+
display_name = "Memory Usage"
124+
key = "mem"
125+
script = <<EOT
126+
free | awk '/^Mem/ { printf("%.0f%%", $4/$2 * 100.0) }'
127+
EOT
128+
interval = 1
129+
timeout = 1
130+
}
131+
132+
133+
metadata {
134+
display_name = "Word of the Day"
135+
key = "word"
136+
script = <<EOT
137+
curl -o - --silent https://www.merriam-webster.com/word-of-the-day 2>&1 | awk ' $0 ~ "Word of the Day: [A-z]+" { print $5; exit }'
138+
EOT
139+
interval = 60
140+
timeout = 5
141+
}
142+
143+
65144
startup_script_timeout = 60
66145
startup_script = <<-EOT
67146
set -eux -o pipefail
147+
68148
# install and start code-server
69149
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.8.3
70150
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
151+
152+
153+
if [ ! -d ${data.coder_parameter.repo_dir.value} ]; then
154+
mkdir -p ${data.coder_parameter.repo_dir.value}
155+
156+
git clone https://github.com/coder/coder ${data.coder_parameter.repo_dir.value}
157+
fi
158+
71159
sudo service docker start
72-
DOTFILES_URI=${var.dotfiles_uri}
160+
DOTFILES_URI="${data.coder_parameter.dotfiles_url.value}"
73161
rm -f ~/.personalize.log
74-
if [ -n "$DOTFILES_URI" ]; then
162+
if [ -n "$${DOTFILES_URI// }" ]; then
75163
coder dotfiles "$DOTFILES_URI" -y 2>&1 | tee -a ~/.personalize.log
76164
fi
77165
if [ -x ~/personalize ]; then
@@ -125,15 +213,6 @@ resource "docker_volume" "home_volume" {
125213
}
126214
}
127215

128-
resource "coder_metadata" "home_info" {
129-
resource_id = docker_volume.home_volume.id
130-
item {
131-
key = "🤫🤫🤫<br/><br/>"
132-
value = "❤️❤️❤️"
133-
sensitive = true
134-
}
135-
}
136-
137216
locals {
138217
container_name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
139218
registry_name = "codercom/oss-dogfood"
@@ -157,14 +236,14 @@ resource "docker_container" "workspace" {
157236
image = docker_image.dogfood.name
158237
name = local.container_name
159238
# Hostname makes the shell more user friendly: coder@my-workspace:~$
160-
hostname = data.coder_workspace.me.name
239+
hostname = data.coder_workspace.me.name
240+
# Use the docker gateway if the access URL is 127.0.0.1
161241
entrypoint = ["sh", "-c", coder_agent.dev.init_script]
162242
# CPU limits are unnecessary since Docker will load balance automatically
163243
memory = 32768
164244
runtime = "sysbox-runc"
165245
env = [
166246
"CODER_AGENT_TOKEN=${coder_agent.dev.token}",
167-
"DATOCMS_API_TOKEN=${var.datocms_api_token}",
168247
]
169248
host {
170249
host = "host.docker.internal"

0 commit comments

Comments
 (0)