Skip to content
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

Feat/enable token #2

Merged
merged 6 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Runners settings
# ex. org: https://github.com/<org name>/staging-monorepo or repo: https://github.com/<org name>/<repo name>
PAT=<Replace with your personal access token>
PAT=<TOKEN>
# -- OR --
# TOKEN=<TOKEN>
# ex. RUNNER_URL org: https://github.com/<org name> or repo: https://github.com/<org name>/<repo name>
RUNNER_URL=<org url or repo url>
RUNNERS=2
# Vagrant image settings
Expand Down
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- # 🚥 PAT - Organization Github Personal Access token
1. -->
# 🚥 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=<Replace with your personal access token>
PAT=<Your Personal access token>
RUNNER_URL=<runner url>
RUNNERS=1
# Vagrant image settings
MEMORY=8000 # 8GB
CPU=4
DISK_SIZE=100
```
### Example with TOKEN
```env
# Runner settings
TOKEN=<Your short lived acess token>
RUNNER_URL=<runner url>
RUNNERS=1
# Vagrant image settings
Expand All @@ -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.

Expand Down
6 changes: 5 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down