Skip to content

chore: add coder_git_auth to the dogfood template #6359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
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
105 changes: 62 additions & 43 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.6.14"
}
docker = {
source = "kreuzwerker/docker"
Expand All @@ -11,67 +11,96 @@ 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.127.2.1:2375"
"ap-sydney" = "tcp://100.87.194.110: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"
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/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
login_before_ready = false
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 &


CODER_REPO_DIR="${data.coder_parameter.repo_dir.value}"
if [ -n "$${CODER_REPO_DIR// }" ] && [ ! -d "$CODER_REPO_DIR" ]; then
mkdir -p "$CODER_REPO_DIR"

git clone https://github.com/coder/coder "$CODER_REPO_DIR"
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 +154,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 Down Expand Up @@ -165,7 +185,6 @@ resource "docker_container" "workspace" {
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