Tuesday, August 31, 2021

Configure Self-Hosted Runners in GitHub

GitHub action is set of tools which helps to automate software development lifecycle including continuous integration and deployment. As any of the automated workflow, GitHub use two type of  machines named as GitHub hosted runners which are hosted by GitHub and self-hosted runners which you can use your own machines to run GitHub actions. This blog explains how to setup a self-hosted runner in GitHub.

Why we need self-hosted runners?

  • You can setup secured self-hosted agents when isolating your development environments to enhance the security by limiting the access from and to public internet.
  • You can setup self-hosted agents when there are specific custom configurations required in runners

Let's get started.

Pre-requites: 

  • Windows Server 2019 64-bit Virtual Machine
  • GitHub account

Login to GitHub and open settings. Select Actions from the side menu and select the Runners section appeared in the side menu. You would be navigated to runners page. Click on New self-hosted runner to add a new self-hosted runner.

Select the runner image and architecture of the VM which going to configured as runner. Once you select the runner image, you can find the commands to configure runner.


Login to VM which is going to be configured as runner. Open PowerShell window and run following commands to create directory, download GitHub action runner and extract it.

  • Create a directory using following command and move to directory

           mkdir actions-runner; cd actions-runner

  • Download GitHub runner package 

            Invoke-WebRequest -Uri             https://github.com/actions/runner/releases/download/v2.284.0/actions-runner-win-x64-2.284.0.zip -OutFile actions-runner-win-x64-2.284.0.zip

  • Extract the installer

           Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/actions-runner-win-x64-2.284.0.zip", "$PWD")

Now, let's start configuration.

./config.cmd --url https://github.com/PushpaH/<<git project>> --token <<auto generated token>>

You will be asked to provide runner group, runner name, runner labels, work folder, run as service or not,  and service permission. 


Once configuration done successfully, you can find self-hosted runner added to GitHub. You can utilize the runner in GitHub action pipelines using  runs-on: self-hosted in workflow jobs. 




This blog explained how to configure self-hosted runner in GitHub and use of it.


No comments:

Post a Comment