Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dogfood/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ RUN mkdir --parents "$GOPATH" && \
# charts and values files
go install github.com/norwoodj/helm-docs/cmd/helm-docs@v1.5.0 && \
# sqlc for Go code generation
go install github.com/kyleconroy/sqlc/cmd/sqlc@v1.17.2 && \
go install github.com/kyleconroy/sqlc/cmd/sqlc@v1.16.0 && \
# gcr-cleaner-cli used by CI to prune unused images
go install github.com/sethvargo/gcr-cleaner/cmd/gcr-cleaner-cli@v0.5.1 && \
# ruleguard for checking custom rules, without needing to run all of
Expand Down
Binary file modified dogfood/files/usr/share/keyrings/ansible.gpg
Binary file not shown.
Binary file modified dogfood/files/usr/share/keyrings/docker.gpg
Binary file not shown.
Binary file modified dogfood/files/usr/share/keyrings/github-cli.gpg
Binary file not shown.
Binary file modified dogfood/files/usr/share/keyrings/google-chrome.gpg
Binary file not shown.
Binary file modified dogfood/files/usr/share/keyrings/google-cloud.gpg
Binary file not shown.
Binary file modified dogfood/files/usr/share/keyrings/hashicorp.gpg
Binary file not shown.
Binary file modified dogfood/files/usr/share/keyrings/microsoft.gpg
Binary file not shown.
Binary file modified dogfood/files/usr/share/keyrings/neovim.gpg
Binary file not shown.
Binary file modified dogfood/files/usr/share/keyrings/nodesource.gpg
Binary file not shown.
Binary file modified dogfood/files/usr/share/keyrings/postgresql.gpg
Binary file not shown.
Binary file modified dogfood/files/usr/share/keyrings/yarnpkg.gpg
Binary file not shown.
167 changes: 123 additions & 44 deletions dogfood/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.6.10"
version = "0.7.0"
}
docker = {
source = "kreuzwerker/docker"
Expand All @@ -11,67 +11,155 @@ terraform {
}
}

# User parameters

variable "region" {
type = string
description = "Which region to deploy to."
default = "us-pittsburgh"
validation {
condition = contains(["us-pittsburgh", "eu-helsinki", "ap-sydney"], var.region)
error_message = "Region must be one of us-pittsburg, eu-helsinki, or ap-sydney."
}
}

variable "dotfiles_uri" {
type = string
description = <<-EOF
Dotfiles repo URI (optional)

see https://dotfiles.github.io
EOF
default = ""
}

variable "datocms_api_token" {
type = string
description = "An API token from DATOCMS for usage with building our website."
default = ""
}

locals {
// These are Tailscale IP addresses. Ask Dean or Kyle for help.
docker_host = {
"" = "tcp://100.94.74.63:2375"
"us-pittsburgh" = "tcp://100.94.74.63:2375"
"eu-helsinki" = "tcp://100.117.102.81:2375"
"ap-sydney" = "tcp://100.87.194.110:2375"
"sa-saopaulo" = "tcp://100.99.64.123:2375"
"eu-paris" = "tcp://100.74.161.61:2375"
}
}

data "coder_parameter" "repo_dir" {
type = "string"
name = "Coder Repository Directory"
default = "~/coder"
description = "The directory specified will be created and [coder/coder](https://github.com/coder/coder) will be automatically cloned into it 🪄."
mutable = true
}

data "coder_parameter" "dotfiles_url" {
type = "string"
name = "Dotfiles URL"
description = "A path to your dotfiles. See: https://dotfiles.github.io"
default = " "
mutable = true
}

data "coder_parameter" "region" {
type = "string"
name = "Region"
icon = "/emojis/1f30e.png"
option {
icon = "/emojis/1f1fa-1f1f8.png"
name = "Pittsburgh"
value = "us-pittsburgh"
}
option {
icon = "/emojis/1f1eb-1f1ee.png"
name = "Helsinki"
value = "eu-helsinki"
}
option {
icon = "/emojis/1f1e6-1f1fa.png"
name = "Sydney"
value = "ap-sydney"
}
option {
icon = "/emojis/1f1e7-1f1f7.png"
name = "São Paulo"
value = "sa-saopaulo"
}
# option {
# icon = "/emojis/1f1eb-1f1f7.png"
# name = "Phorcys' Server in Paris"
# value = "eu-paris"
# }
}

provider "docker" {
host = lookup(local.docker_host, var.region)
host = lookup(local.docker_host, data.coder_parameter.region.value)
}

provider "coder" {}

data "coder_git_auth" "github" {
id = "github"
}

data "coder_workspace" "me" {}

resource "coder_agent" "dev" {
arch = "amd64"
os = "linux"

dir = data.coder_parameter.repo_dir.value
env = {
GITHUB_TOKEN: data.coder_git_auth.github.access_token,
OIDC_TOKEN: data.coder_workspace.me.owner_oidc_access_token,
}
login_before_ready = false

metadata {
display_name = "CPU Usage"
key = "cpu"
script = <<EOT
vmstat | awk 'FNR==3 {printf "%2.0f%%", $13+$14+$16}'
EOT
interval = 1
timeout = 1
}

metadata {
display_name = "Load Average"
key = "load"
script = "awk '{print $1}' /proc/loadavg"
interval = 1
timeout = 1
}

metadata {
display_name = "Disk Usage"
key = "disk"
script = "df -h | awk '$6 ~ /^\\/$/ { print $5 }'"
interval = 1
timeout = 1
}

metadata {
display_name = "Memory Usage"
key = "mem"
script = <<EOT
free | awk '/^Mem/ { printf("%.0f%%", $4/$2 * 100.0) }'
EOT
interval = 1
timeout = 1
}


metadata {
display_name = "Word of the Day"
key = "word"
script = <<EOT
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 }'
EOT
interval = 60
timeout = 5
}


startup_script_timeout = 60
startup_script = <<-EOT
set -eux -o pipefail

# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.8.3
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &


if [ ! -d ${data.coder_parameter.repo_dir.value} ]; then
mkdir -p ${data.coder_parameter.repo_dir.value}

git clone https://github.com/coder/coder ${data.coder_parameter.repo_dir.value}
fi

sudo service docker start
DOTFILES_URI=${var.dotfiles_uri}
DOTFILES_URI="${data.coder_parameter.dotfiles_url.value}"
rm -f ~/.personalize.log
if [ -n "$DOTFILES_URI" ]; then
if [ -n "$${DOTFILES_URI// }" ]; then
coder dotfiles "$DOTFILES_URI" -y 2>&1 | tee -a ~/.personalize.log
fi
if [ -x ~/personalize ]; then
Expand Down Expand Up @@ -125,15 +213,6 @@ resource "docker_volume" "home_volume" {
}
}

resource "coder_metadata" "home_info" {
resource_id = docker_volume.home_volume.id
item {
key = "🤫🤫🤫<br/><br/>"
value = "❤️❤️❤️"
sensitive = true
}
}

locals {
container_name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
registry_name = "codercom/oss-dogfood"
Expand All @@ -157,14 +236,14 @@ resource "docker_container" "workspace" {
image = docker_image.dogfood.name
name = local.container_name
# Hostname makes the shell more user friendly: coder@my-workspace:~$
hostname = data.coder_workspace.me.name
entrypoint = ["sh", "-c", coder_agent.dev.init_script]
hostname = data.coder_workspace.me.name
# Use the docker gateway if the access URL is 127.0.0.1
entrypoint = ["sh", "-c", replace(coder_agent.dev.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
# CPU limits are unnecessary since Docker will load balance automatically
memory = 32768
runtime = "sysbox-runc"
env = [
"CODER_AGENT_TOKEN=${coder_agent.dev.token}",
"DATOCMS_API_TOKEN=${var.datocms_api_token}",
]
host {
host = "host.docker.internal"
Expand Down