Akamai Connected Cloud Architecture Cloud GitHub GitHub runner Linux

Get your own own Github runner deployed and configured on Linode in less than 5 minutes.

Why would you run your own runner anyways?

GitHub Actions (along with Azure DevOps) has emerged as a powerful managed tool that allows developers to automate workflows directly within their GitHub repositories. While GitHub provides hosted runners to execute these workflows, running your own GitHub runner can offer several advantages.

1. Money talks

One of the primary benefits of running your own GitHub runner is cost efficiency. GitHub Actions provides a certain number of free minutes for public and private repositories, but once you exceed these limits, costs can add up quickly, especially if your execution takes a while 🙁

2. Customization and Control

When you run your own GitHub runner, you gain full control over the environment in which your workflows execute. This means you can customize the runner’s operating system, software, and dependencies to match your project’s specific needs. It doesn’t matter anymore if you need a particular version of a programming language, specialized libraries, or specific system configurations, your self-hosted runner can be tailored to your requirements.

3. Performance and Speed

Self-hosted runners can significantly enhance the performance of your CI/CD pipelines. Since these runners are dedicated to your projects, you can optimize them for speed and efficiency. You can run builds on beefy machines, use faster storage, or even set up parallel execution across multiple runners to speed up your workflows. This is especially beneficial for larger projects or teams with multiple repositories or a bunch of members working in parallel.

4. Security and Compliance

For organizations handling sensitive data or operating in regulated industries, security is number one. Running your own GitHub runner allows you to maintain control over your CI/CD environment. You can implement your own security measures, restrict network access, and ensure that sensitive information does not leave your secured infrastructure. Additionally, you can regularly update and audit your runner to comply with internal policies or external regulations.

5. Reduced Queue Times

Using GitHub’s hosted runners means you may encounter queue times, especially during peak usage periods. By setting up your own runners, you can mitigate these delays, ensuring that your workflows kick off as soon as possible.

How do I get it running?

Step 1 – Clone the repository using the following command.

git clone https://github.com/slepix/GitHubRunner-Linode.git

You will need to prepare 5 things; it’s not hard, I promise.
  1. Linode API token with permission to deploy virtual machines – more info
  2. GitHub PAT limited only to the repository you want to connect – more details
  3. GitHub repository name you want to connect your runner to.
  4. GitHub username which owns the repository.
  5. Root password for the runner VM – can be anything, as long as it’s long and complex.

Step 2 – Fill in the details in linoderunner.tfvars file; it should look something like this.

*These are random values, so make sure to replace them with your own.

linode_api_token = "eee44387b0030bd6bb051452bg65gz56z465fba5d77c5a238ea8e12f"
github_pat = "github_pat_1HG534e67d3K52IUSL_D2vM1pzjDGjX5sCiUEXWD6TRKDut4jnJty"
root_password = "Rand0mSecurePassword.123!" # Root password for your VM
github_repo = "myawesomeapp" # Your Github repo name
github_username = "slepix" # Your GitHub username

Step 3 – run the following command:

terraform apply --var-file="linoderunner.tfvars"

Entire codebase is available at https://github.com/slepix/GithubRunner-Linode

Ok, let’s take a look at some code. Once again, we’ll go with Terraform and cloud-init to deploy and configure our server. Ideally you would use some configuration management tool like Puppet, Ansible, Chef or similar, but for this use case, we can keep it simple.

Using cloud-init, we create a new user called “gitrunner” which will be used to run the agent, update all the packes, install jq (needed by the agent configuration script) and kick off the installation of the runner as a service.

compute.tf file – this is where you can adjust the region, OS and instance type you want to run.

resource "linode_instance" "github_runner" {
  image     = "linode/ubuntu22.04"
  region    = "nl-ams"
  type      = "g6-nanode-1"
  label     = "github-runner"
  root_pass = var.root_password  # Set the root password

  metadata {
    user_data = base64encode(templatefile("./linode.yaml.tpl", {
      githubpat = var.github_pat
      githubuser = var.github_username
      githubrepo = var.github_repo
    }))
  }
}

linode.yaml.tpl file

#cloud-config
package_update: true
packages:
  - jq

users:
  - name: gitrunner
    shell: /bin/bash
    groups:
      - sudo
    sudo:
      - ALL=(ALL) NOPASSWD:ALL

runcmd:
  - export RUNNER_CFG_PAT=${githubpat}
  - su gitrunner -c "cd /home/gitrunner && curl -s https://raw.githubusercontent.com/actions/runner/main/scripts/create-latest-svc.sh | bash -s ${githubuser}/${githubrepo}" 

If all went good, you should see the new GitHub runner appear in your runner overview in a few mins.

Happy building and deploying!

Alex!

LEAVE A RESPONSE

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Senior Cloud Architect at Akamai