Skip to content

Dockerized self hosted runner on Windows

Shivam Mathur edited this page May 13, 2020 · 1 revision

Dockerfile

You can use this Dockerfile to setup a self hosted runner for GitHub Actions on windows.

FROM mcr.microsoft.com/windows/servercore:ltsc2019

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]

ARG RUNNER_VERSION=ver
ARG RUNNER_URL=https://github.com/foo/bar
ARG RUNNER_TOKEN=tkn

RUN Invoke-WebRequest -Uri 'https://aka.ms/install-powershell.ps1' -OutFile install-powershell.ps1; ./install-powershell.ps1 -AddToPath; Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v$env:RUNNER_VERSION/actions-runner-win-x64-$env:RUNNER_VERSION.zip -OutFile runner.zip; Expand-Archive -Path $pwd/runner.zip -DestinationPath $pwd

CMD [ "pwsh", "-c", "./config.cmd --url $env:RUNNER_URL --token $env:RUNNER_TOKEN; ./run.cmd"]

Switch to Windows containers

Switch to windows containers Courtesy docker blog

Build

Place the above Dockerfile in a directory and build an image. In the runner installation instructions you can find the RUNNER_VERSION from the curl command. Replace the values in the command below before executing.

docker build -t winselfhosted:0.1 --build-arg RUNNER_VERSION=1.2.3 .

Run

In the runner installation instructions you can find the RUNNER_URL and RUNNER_TOKEN from the config command. Replace the values in the command below before executing.

docker run -it -e RUNNER_URL=https://github.com/foo/bar -e RUNNER_TOKEN=ABCDEFGHIJKLNMOPQRSTUVWXYZABC winselfhosted:0.1