-
docker-github-runner-windows
Repository for building a self hosted GitHub runner as a windows container
-
Moby
The Moby Project - a collaborative project for the container ecosystem to assemble container-based systems
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
Puts Debuggerer
Ruby library for improved puts debugging, automatically displaying bonus useful information such as source line number and source code.
Open VSCode, you can clone the repo found on my GitHub project docker-github-runner-windows which contains all the files or simply follow along with the following steps. We will prepare a few PowerShell scripts that will be needed as part of our docker image creation.
#This script invokes GitHub-CLI (Already installed on container image) #To use this entrypoint script run: Docker run -e GH_TOKEN='myPatToken' -e GH_OWNER='orgName' -e GH_REPOSITORY='repoName' -d imageName Param ( [Parameter(Mandatory = $false)] [string]$owner = $env:GH_OWNER, [Parameter(Mandatory = $false)] [string]$repo = $env:GH_REPOSITORY, [Parameter(Mandatory = $false)] [string]$pat = $env:GH_TOKEN ) #Use --with-token to pass in a PAT token on standard input. The minimum required scopes for the token are: "repo", "read:org". #Alternatively, gh will use the authentication token found in environment variables. See gh help environment for more info. #To use gh in GitHub Actions, add GH_TOKEN: $ to "env". on Docker run: Docker run -e GH_TOKEN='myPatToken' gh auth login #Get Runner registration Token $jsonObj = gh api --method POST -H "Accept: application/vnd.github.v3+json" "/repos/$owner/$repo/actions/runners/registration-token" $regToken = (ConvertFrom-Json -InputObject $jsonObj).token $runnerBaseName = "dockerNode-" $runnerName = $runnerBaseName + (((New-Guid).Guid).replace("-", "")).substring(0, 5) try { #Register new runner instance write-host "Registering GitHub Self Hosted Runner on: $owner/$repo" ./config.cmd --unattended --url "https://github.com/$owner/$repo" --token $regToken --name $runnerName #Remove PAT token after registering new instance $pat=$null $env:GH_TOKEN=$null #Start runner listener for jobs ./run.cmd } catch { Write-Error $_.Exception.Message } finally { # Trap signal with finally - cleanup (When docker container is stopped remove runner registration from GitHub) # Does not currently work due to issue: https://github.com/moby/moby/issues/25982# # Perform manual cleanup of stale runners using Cleanup-Runners.ps1 ./config.cmd remove --unattended --token $regToken }
##### BASE IMAGE INFO ###### #Using servercore insider edition for compacted size. #For compatibility on "your" host running docker you may need to use a specific tag. #E.g. the host OS version must match the container OS version. #If you want to run a container based on a newer Windows build, make sure you have an equivalent host build. #Otherwise, you can use Hyper-V isolation to run older containers on new host builds. #The default entrypoint is for this image is Cmd.exe. To run the image: #docker run mcr.microsoft.com/windows/servercore/insider:10.0.{build}.{revision} #tag reference: https://mcr.microsoft.com/en-us/product/windows/servercore/insider/tags #Win10 #FROM mcr.microsoft.com/windows/servercore/insider:10.0.19035.1 #Win11 FROM mcr.microsoft.com/windows/servercore/insider:10.0.20348.1 #input GitHub runner version argument ARG RUNNER_VERSION LABEL Author="Marcel L" LABEL Email="[email protected]" LABEL GitHub="https://github.com/Pwd9000-ML" LABEL BaseImage="servercore/insider:10.0.20348.1" LABEL RunnerVersion=${RUNNER_VERSION} SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"] #Set working directory WORKDIR /actions-runner #Install chocolatey ADD scripts/Install-Choco.ps1 . RUN .\Install-Choco.ps1 -Wait; \ Remove-Item .\Install-Choco.ps1 -Force #Install Git, GitHub-CLI, Azure-CLI and PowerShell Core with Chocolatey (add more tooling if needed at build) RUN choco install -y \ git \ gh \ powershell-core \ azure-cli #Download GitHub Runner based on RUNNER_VERSION argument (Can use: Docker build --build-arg RUNNER_VERSION=x.y.z) RUN Invoke-WebRequest -Uri "https://github.com/actions/runner/releases/download/v$env:RUNNER_VERSION/actions-runner-win-x64-$env:RUNNER_VERSION.zip" -OutFile "actions-runner.zip"; \ Expand-Archive -Path ".\\actions-runner.zip" -DestinationPath '.'; \ Remove-Item ".\\actions-runner.zip" -Force #Add GitHub runner configuration startup script ADD scripts/start.ps1 . ADD scripts/Cleanup-Runners.ps1 . ENTRYPOINT ["pwsh.exe", ".\\start.ps1"]
##### BASE IMAGE INFO ###### #Using servercore insider edition for compacted size. #For compatibility on "your" host running docker you may need to use a specific tag. #E.g. the host OS version must match the container OS version. #If you want to run a container based on a newer Windows build, make sure you have an equivalent host build. #Otherwise, you can use Hyper-V isolation to run older containers on new host builds. #The default entrypoint is for this image is Cmd.exe. To run the image: #docker run mcr.microsoft.com/windows/servercore/insider:10.0.{build}.{revision} #tag reference: https://mcr.microsoft.com/en-us/product/windows/servercore/insider/tags #Win10 #FROM mcr.microsoft.com/windows/servercore/insider:10.0.19035.1 #Win11 FROM mcr.microsoft.com/windows/servercore/insider:10.0.20348.1 #input GitHub runner version argument ARG RUNNER_VERSION LABEL Author="Marcel L" LABEL Email="[email protected]" LABEL GitHub="https://github.com/Pwd9000-ML" LABEL BaseImage="servercore/insider:10.0.20348.1" LABEL RunnerVersion=${RUNNER_VERSION} SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"] #Set working directory WORKDIR /actions-runner #Install chocolatey ADD scripts/Install-Choco.ps1 . RUN .\Install-Choco.ps1 -Wait; \ Remove-Item .\Install-Choco.ps1 -Force #Install Git, GitHub-CLI, Azure-CLI and PowerShell Core with Chocolatey (add more tooling if needed at build) RUN choco install -y \ git \ gh \ powershell-core \ azure-cli #Download GitHub Runner based on RUNNER_VERSION argument (Can use: Docker build --build-arg RUNNER_VERSION=x.y.z) RUN Invoke-WebRequest -Uri "https://github.com/actions/runner/releases/download/v$env:RUNNER_VERSION/actions-runner-win-x64-$env:RUNNER_VERSION.zip" -OutFile "actions-runner.zip"; \ Expand-Archive -Path ".\\actions-runner.zip" -DestinationPath '.'; \ Remove-Item ".\\actions-runner.zip" -Force #Add GitHub runner configuration startup script ADD scripts/start.ps1 . ADD scripts/Cleanup-Runners.ps1 . ENTRYPOINT ["pwsh.exe", ".\\start.ps1"]