From a813eb0029e40b33baf7271cdc0da554713d7904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Kolsj=C3=B6?= Date: Mon, 2 Dec 2024 13:32:53 +0100 Subject: [PATCH] cloud_init: Add config and setup to run github actions runners Co-authored-by: Peter Wall <47324121+p-wall@users.noreply.github.com> --- app/controllers/api/cloud_inits_controller.rb | 17 +++++++++++------ config/initializers/app.rb | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/cloud_inits_controller.rb b/app/controllers/api/cloud_inits_controller.rb index 99dbddbf..50350be5 100644 --- a/app/controllers/api/cloud_inits_controller.rb +++ b/app/controllers/api/cloud_inits_controller.rb @@ -10,7 +10,7 @@ def show lock_passwd: false, chpasswd: { expire: false }, sudo: "ALL=(ALL) NOPASSWD:ALL", - shell: "/bin/bash" + shell: "/bin/bash", } ], disable_root: true, @@ -21,16 +21,21 @@ def show package_upgrade: true, write_files: [ { - path: "/etc/motd", - content: "Hello there." - } + path: "/etc/environment", + content: %{ + RUNNER_CFG_PAT=#{App.github_actions_runner_cfg_pat} + }, + append: true, + }, ], runcmd: [ + "while read -r env; do export \"$env\"; done < /etc/environment", "systemctl stop sshd", "systemctl disable sshd", "curl https://maintenance.auctionet.dev/it-ran", - "reboot" - ] + "curl -s https://raw.githubusercontent.com/actions/runner/main/scripts/create-latest-svc.sh | bash -s #{App.github_actions_runner_scope}", + "reboot", + ], } yaml = "#cloud-config\n" + diff --git a/config/initializers/app.rb b/config/initializers/app.rb index b6ba458c..3560bb40 100644 --- a/config/initializers/app.rb +++ b/config/initializers/app.rb @@ -7,6 +7,22 @@ def self.api_token end end + def self.github_actions_runner_cfg_pat + if Rails.env.test? || Rails.env.development? + "test-runner-cfg-pat" + else + ENV.fetch("CLOUD_INIT_GITHUB_ACTIONS_RUNNER_CFG_PAT") + end + end + + def self.github_actions_runner_scope + if Rails.env.test? || Rails.env.development? + "test-runner-scope" + else + ENV.fetch("CLOUD_INIT_GITHUB_ACTIONS_RUNNER_SCOPE") + end + end + def self.revisions_to_keep (ENV["REVISIONS_TO_KEEP"] || 500).to_i end