From 71a904dc63079a3b4b33ed37671129e89dc1c498 Mon Sep 17 00:00:00 2001 From: Kakious Date: Mon, 25 Sep 2023 17:27:35 -0400 Subject: [PATCH] added boop template --- boop/main.tf | 285 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 boop/main.tf diff --git a/boop/main.tf b/boop/main.tf new file mode 100644 index 0000000..debec3a --- /dev/null +++ b/boop/main.tf @@ -0,0 +1,285 @@ +terraform { + required_providers { + coder = { + source = "coder/coder" + version = "~> 0.8.3" + } + docker = { + source = "kreuzwerker/docker" + version = "~> 3.0.1" + } + } +} + +locals { + username = data.coder_workspace.me.owner +} + +data "coder_provisioner" "me" { +} + +provider "docker" { +} + +data "coder_workspace" "me" { +} + +data "coder_git_auth" "github" { + # Matches the ID of the git auth provider in Coder. + id = "primary-github" +} + +resource "coder_app" "boop" { + agent_id = coder_agent.main.id + slug = "boop" + display_name = "B.O.O.P." + icon = "https://media.furality.online/boop/furality.png" + url = "http://localhost:3123" + share = "public" + subdomain = false +} + + +resource "coder_agent" "main" { + arch = data.coder_provisioner.me.arch + os = "linux" + + startup_script_timeout = 180 + startup_script = <<-EOT + set -e + + # start the services + echo "[SETUP] Starting core services (sql and redis)" + sudo service mysql start 2>&1 /dev/null + sudo service redis-server start 2>&1 /dev/null + echo "[SETUP] Core services started" + + if [ ! -f ~/.coder-env ]; then + echo "[SETUP] Creating ~/.coder-env" + echo "WORKSPACE_ENV=$WORKSPACE_ENV" >> ~/.coder-env + echo "USERNAME_ENV=$USERNAME_ENV" >> ~/.coder-env + echo "[SETUP] Created ~/.coder-env" + fi + + if [ ! -d ~/oauth-provider ]; then + echo "[SETUP] Cloning Github Repo" + git clone https://github.com/furality/oauth-provider/ + cp ~/oauth-provider/.env.example ~/oauth-provider/.env + echo "@fortawesome:registry=https://npm.fontawesome.com/" > ~/oauth-provider/.npmrc + echo "//npm.fontawesome.com/:_authToken=CEDBD954-ED84-4701-B22E-416075856EB4" > ~/oauth-provider/.npmrc + + echo "[SETUP] Downloading test keys from git" + mkdir ~/oauth-provider/keys + wget -q -O ~/oauth-provider/keys/cookies.json https://git.kakio.us/kakious/docker-images/raw/branch/main/boop-keys/cookies.json + wget -q -O ~/oauth-provider/keys/jwks.json https://git.kakio.us/kakious/docker-images/raw/branch/main/boop-keys/jwks.json + + echo "[SETUP] Git Keys imported" + + + echo "Downloading setup script from git" + wget -q -O ~/setup-script.sh https://git.kakio.us/kakious/docker-images/raw/branch/main/boop-keys/setup-boop.sh + echo "[SETUP] Downloaded setup script from git" + chmod +x ~/setup-script.sh + + echo "[SETUP] Running Setup Script" + sudo ./setup-script.sh 2>&1 /dev/null + echo "[SETUP] Setup Script Done" + cd ~/oauth-provider + + echo "[SETUP] Downloading NPM packages" + npm i --loglevel=error + sudo npm -g i node-ts --loglevel=errpr + + echo "[SETUP] Running TypeORM Migrations" + npm run typeorm:run-migrations + echo "[SETUP] Deleting DB Setup Script" + rm -rf ~/setup-script.sh + fi + + echo "[SETUP] Setup Complete" + EOT + + env = { + GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}" + GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}" + GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}" + GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}" + GITHUB_TOKEN = "${data.coder_git_auth.github.access_token}" + WORKSPACE_ENV = "${data.coder_workspace.me.name}" + USERNAME_ENV = "${data.coder_workspace.me.owner}" + } + +metadata { + display_name = "CPU Usage" + key = "0_cpu_usage" + script = "coder stat cpu" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "RAM Usage" + key = "1_ram_usage" + script = "coder stat mem" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Home Disk" + key = "3_home_disk" + script = "coder stat disk --path $${HOME}" + interval = 60 + timeout = 1 + } + + metadata { + display_name = "CPU Usage (Host)" + key = "4_cpu_usage_host" + script = "coder stat cpu --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Memory Usage (Host)" + key = "5_mem_usage_host" + script = "coder stat mem --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Load Average (Host)" + key = "6_load_host" + # get load avg scaled by number of cores + script = <