Skip to content

Windows GitHub Actions Runner

Javier Romero edited this page Mar 8, 2021 · 41 revisions

Host information:

Installation

In a new Administrator Powershell terminal:

# Install chocolately (https://chocolatey.org/install)
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

# Install dependencies; Note: for Windows 2016, use `choco install docker-desktop --version=2.0.0.3`
choco install docker-desktop git make cygwin -y

# Exit and start a new terminal to reload `$env:PATH`
Exit

In a new Administrator Powershell terminal:

# Set up Github Actions Runner Process
## IMPORTANT:
## Each runner is specific to only one git repository. To reuse the same VM, you must run a service per repo.
## Convention is to install each runner in a directory named after the repo. eg. `\actions-runners\pack\`
Set-Variable -Name REPO -Value pack
mkdir \actions-runners\$REPO; cd \actions-runners\$REPO
curl.exe -Lo actions-runner-win-x64-2.168.0.zip https://github.com/actions/runner/releases/download/v2.168.0/actions-runner-win-x64-2.168.0.zip
Expand-Archive actions-runner-win-x64-2.168.0.zip

# Disable automatic CRLF
git config --global core.autocrlf false

# Add cygwin binaries path
[Environment]::SetEnvironmentVariable("PATH", "$ENV:PATH;C:\tools\cygwin\bin", "USER")

# Install Hyper-V for Docker; NOTE: This will restart the machine.
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart

For LCOW only

  1. Enable C: drive sharing for volume mounting:
    • On Windows 2016, Docker Desktop -> Right click Settings -> Shared Drives -> Check C
    • On Windows 2019, Docker Desktop -> Right click Settings -> Resources -> File Sharing -> Check C

For WCOW only

In an Administrator Powershell terminal:

# Get the runner's internal IP address (it should start with `10.`)
$IPAddress=(Get-NetIPAddress -InterfaceAlias bond0 -AddressFamily IPv4)[1].IPAddress

"# Modified by CNB: https://github.com/buildpacks/ci/wiki/Windows-GitHub-Actions-Runner#for-wcow-only

${IPAddress} host.docker.internal
${IPAddress} gateway.docker.internal
" | Out-File -Filepath C:\Windows\System32\drivers\etc\hosts -Encoding utf8
  1. In Docker settings, add "10.0.0.0/8" to the insecure-registries list (Docker should restart after applying).

    wcow-insecure-registries

GitHub Runner

  • Configure:
    • In a browser, go to https://github.com/buildpacks/{{REPO}}/settings/actions
    • Click Add Runner
    • Run configure step in PowerShell
      • Set name to the hostname of the worker
      • Set Y when asked to run as Service
        • When asked what user to run the service as, open another terminal and type whoami, that's the value you want to use
      • Leave other options as their default
    • Add appropriate labels

Labels

These labels should be added to runners that then may be refrered to by the GitHub workflows:

  • wcow - Docker configured with Windows Containers on Windows

Example usage:

jobs:
  test:
    runs-on: [self-hosted, windows, wcow]

Maintenance

If tests begin to fail for Docker-related issues, try the following:

  • Restart Docker (use taskbar icon, not command line)
  • Double check that c:\windows\system32\drivers\etc\hosts entries for host.docker.internal and gateway.docker.internal are correct (a Docker update or restart may overwrite changes)
  • Restart runner service: Restart-Service "actions.runner*
  • Restart runner machine
Clone this wiki locally