diff --git a/.env b/.env index 7d397c1..000ce4f 100644 --- a/.env +++ b/.env @@ -1,6 +1,8 @@ # Runners settings -# ex. org: https://github.com//staging-monorepo or repo: https://github.com// -PAT= +PAT= +# -- OR -- +# TOKEN= +# ex. RUNNER_URL org: https://github.com/ or repo: https://github.com// RUNNER_URL= RUNNERS=2 # Vagrant image settings diff --git a/README.md b/README.md index 4fb1baf..6c7c6dc 100644 --- a/README.md +++ b/README.md @@ -9,21 +9,41 @@ Explore an innovative, efficient, and cost-effective approach to deploying a cus - [docker](https://www.docker.com/) version 24 or higher. - [docker-compose](https://www.docker.com/) version 1.18 or higher. - +# 🚥 Authentication for Self-Hosted Runners +For the purpose of authenticating your custom self-hosted runners, we offer two viable authentication methods: + +1. Personal Access Token (`PAT`) - The Personal Access Token is a static, manually created token that provides secure access to GitHub. This offers a long-lived method of authentication (The PAT token needs Read and Write access to organization self-hosted runners). + +2. Registration Token (`TOKEN`) - The Registration Token is a dynamic, short-lived token generated automatically by GitHub during the creation of a new self-hosted runner. This provides a temporary but immediate method of authentication. + +> **Note:** Only one of these authentication methods is necessary. Choose the method that best fits your # 🚀 Deployment Guide 1. Create/Update the environmental file `.env` - `PAT`: Personal access token from GitHub + - `TOKEN`: Short lived Github token - `RUNNER_URL`: The URL of the GitHub that the runner connects to - `RUNNERS`: Number of runners - `MEMORY`: Amount of memory for the Vagrant image (in MB) - `CPU`: Number of CPUs for the Vagrant image - `DISK_SIZE`: Disk size for the Vagrant image (in GB) + +### Example with PAT ```env # Runner settings -PAT= +PAT= +RUNNER_URL= +RUNNERS=1 +# Vagrant image settings +MEMORY=8000 # 8GB +CPU=4 +DISK_SIZE=100 +``` +### Example with TOKEN +```env +# Runner settings +TOKEN= RUNNER_URL= RUNNERS=1 # Vagrant image settings @@ -47,9 +67,6 @@ services: ``` 3. Run: `docker-compose up -d` -> The PAT token needs Read and Write access to organization self-hosted runners - - # 🌐 Access via Remote Desktop For debugging purposes or testing you can always connect to the VM with remote desktop softwares. diff --git a/Vagrantfile b/Vagrantfile index ecea84d..cd35656 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -43,7 +43,11 @@ Vagrant.configure("2") do |config| Write-Host "Running $runner"; $random = -join ((48..57) + (97..122) | Get-Random -Count 8 | % {[char]$_}); Expand-Archive -LiteralPath ${GITHUB_RUNNER_FILE} -DestinationPath runner-$random -Force; - Invoke-Expression -Command "C:\\runner-$random\\config.cmd --name ${GITHUB_RUNNER_NAME}_$random --replace --unattended --url ${RUNNER_URL} --labels ${GITHUB_RUNNER_LABELS} --pat ${PAT}"; + if (![string]::IsNullOrEmpty("${PAT}")) { + Invoke-Expression -Command "C:\\runner-$random\\config.cmd --name ${GITHUB_RUNNER_NAME}_$random --replace --unattended --url ${RUNNER_URL} --labels ${GITHUB_RUNNER_LABELS} --pat ${PAT}"; + } else { + Invoke-Expression -Command "C:\\runner-$random\\config.cmd --name ${GITHUB_RUNNER_NAME}_$random --replace --unattended --url ${RUNNER_URL} --labels ${GITHUB_RUNNER_LABELS} --token ${TOKEN}"; + } Start-Process "C:\\runner-$random\\run.cmd" -Credential ($credentials); } SHELL diff --git a/startup.sh b/startup.sh index aaefc81..8661b50 100644 --- a/startup.sh +++ b/startup.sh @@ -8,7 +8,7 @@ export RANDOM_STR=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n if [ ! -f Vagrantfile ] then envsubst \ - '${VAGRANT_BOX},${PRIVILEGED},${INTERACTIVE},${MEMORY},${CPU},${DISK_SIZE},${GITHUB_RUNNER_FILE},${GITHUB_RUNNER_NAME},${RANDOM_STR},${RUNNERS},${GITHUB_RUNNER_LABELS},${RUNNER_URL},${PAT},${GITHUB_RUNNER_URL}' \ + '${VAGRANT_BOX},${PRIVILEGED},${INTERACTIVE},${MEMORY},${CPU},${DISK_SIZE},${GITHUB_RUNNER_FILE},${GITHUB_RUNNER_NAME},${RANDOM_STR},${RUNNERS},${GITHUB_RUNNER_LABELS},${RUNNER_URL},${PAT},${TOKEN},${GITHUB_RUNNER_URL}' \ < Vagrantfile.tmp > Vagrantfile fi