DEV Community

Cover image for Configure self-hosted runner for GitHub Actions
Ďēv Šhãh 🥑
Ďēv Šhãh 🥑

Posted on

Configure self-hosted runner for GitHub Actions

Introduction

Whats up everyone? This is Dev. This is a tutorial blog on how to configure a personal server or cloud to run GitHub Actions’ jobs. As prerequisite to understand this tutorial, you should know how GitHub Actions work.


Tutorial

To set up a self hosted runner for a repository, firstly go to the project repository’s settings, click on Runners, under Actions section.

GitHub Screenshot

Then click on the New self-hosted runner.

GitHub Screenshot

Clicking on the button gives you a page, were you can select the OS of your server. Since, I have a Linux server, I will go for Linux.

GitHub Screenshot

Based on your OS, you will get all the commands to Download and Configure the runner. Since I am using a Linux server, following are the commands to Download and Configure the runner.

Step 1: Download the runner

# GitHub recommends downloading the runner in a directory named "actions-runner"
mkdir actions-runner && cd actions-runner

# The following command downloads the latest runner package.
curl -o actions-runner-linux-x64-2.321.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.321.0/actions-runner-linux-x64-2.321.0.tar.gz

# The following command extracts the installer.
tar xzf ./actions-runner-linux-x64-2.321.0.tar.gz
Enter fullscreen mode Exit fullscreen mode

Step 2: Configure the runner

# The following command creates a runner.
# The required token will already be there when you get the commands after choosing the OS.
./config.sh --url [GitHub Repo URL] --token [GitHub Repo Token]
Enter fullscreen mode Exit fullscreen mode

Entering the above commands prompts you the following questions,

  1. Enter the name of the runner group to add this runner to: You can add this runner to any group that you want to or simply press enter to add it to a default group.
  2. Enter the name of the runner: You can give any name to this runner, or press enter to give it a default name.
  3. This runner will have the following labels: 'self-hosted', 'Linux', 'X64' Enter any additional labels (ex. label-1,label-2): You can add labels to this runner, if you want to, or press enter to skip.
  4. Enter name of the work folder: Similarly, you can enter a specific name to the work folder or press enter to give it a default name.

GitHub Actions Runner Registration

Once the runner is configured, now its time to run the runner using the bash script ./run.sh that is already present.

As soon as you run this script, the runner will start listening for jobs.

GitHub Runner Listening for Jobs

Step 3: Update the workflow yml file

Lastly, to make sure that the required jobs, runs on the self-hosted runner, use the following value of runs-on for the jobs.

runs-on: self-hosted
Enter fullscreen mode Exit fullscreen mode

Now, whenever the workflow is triggered, the runner will log everything. To see how this works, practically whenever the workflow is triggered, check out the following video.


Benefits

Using a self-hosted runner has several benefits such as,

  • You can use more powerful machines than the limited resources of GitHub's hosted runners.
  • You can use your specific operating system to match your production or testing environment.
  • You can pre-install tools, libraries, and software to save time during build and deployment jobs.
  • Self-hosted runners can be located closer to your code, artifacts, or databases, reducing latency during execution.
  • You can set up caching mechanisms locally to avoid downloading dependencies repeatedly, improving speed.
  • GitHub-hosted runners may experience delays when many jobs are queued.
  • You can run self-hosted runners on your existing cloud infrastructure, taking advantage of reserved instances or spot pricing for cost savings.
  • Your self-hosted runner can run inside your organization's secure network, keeping data and secrets safe.

Final Words

This was the blog on how to configure self-hosted runner for GitHub Actions. Let me know if you have any questions or feedback.

Top comments (0)