DEV Community

Cover image for Self hosted GitHub Actions using Raspberry Pi
Angad Sharma
Angad Sharma

Posted on

Self hosted GitHub Actions using Raspberry Pi

We live in a time where anyone can write code. What matters is how efficiently you write and test it and of course how you distribute it. Continuous integration has become a major part of GitOps and github actions has make it very easy to write simple configurations for CI and associate it with an event on your code repository (for example: on code release).

The need

The Github Actions platform provides developers with the power to test and package their code on github's infrastructure for free. But like all free things, this also comes with a catch. You can only run your actions as per a limited quota provided by github. This forces developers to compromise their pipeline to ensure that CI builds run less often. What if I told you that your cheap credit-card sized raspberry pi can be used as a machine to run all of your github actions automatically? Well such is the power of SBCs(single board computers) in 2020.

Ever since the launch of raspberry pi 4, single board computing has reached new heights, with more than 35 million copies sold as per the publishing date of this article, with around 44% of the units sold to industrial customers. In light of this development, this article will be all the more relevant to a wide variety of consumers willing to run more workloads from their internal networks and self hosted comfort zones.

Let us start by elaborating why you would want your github actions to run on the raspberry pi:

  • Unlimited github actions quota
  • No need to expose infrastructure from the internal network
  • Low power draw
  • Full and sole ownership of data

    If you are an enterprise user (or part of an organization that is an enterprise on github), you can pretty much configure your entire organization actions to run on self hosted solutions, but if you are an individual user, you can only do so on a per-repository level. With this information, let us get started with how to offload your github actions to your raspberry pi.

Steps to run your own actions on a raspberry pi

  1. Firstly you will need a raspberry pi with any linux distribution. I prefer Ubuntu server 20.04. Run a quick update and upgrade on it to set it up. Remember that you don't need to configure any kind of port forwarding since this solution will work even if you raspberry pi is not exposed on the external network. You do need an internet connection though since your pi will have to connect to the GitHub servers for this to work.

  2. Go to the Actions setting in your repository (remember, this is a repository level setting rather than a global one. If you are an enterprise user, you can go into your enterprise settings for the same) and press the option to add a new Self Hosted Runner.

  3. In the add self hosted runner section, choose operating system as linux and architecture as ARM64 if you are using a 64 bit raspberry pi, or just ARM if you are using a 32 bit version.

  4. The add self hosted runners section gives you the necessary commands to run inside your raspberry pi to set everything up. After you have pasted those commands one by one, you are ready to starting the service in your pi that will listen or any dispatched actions and perform them internally.

  5. ./run.sh allows you to start listening immediately. If you want this service to run permanently in the background, you can run the following command:

sudo ./svc.sh install
sudo ./svc.sh start
Enter fullscreen mode Exit fullscreen mode
  1. Configure your actions to use this infrastructure by using the keyword self-hosted in the actions configuration for the repository for which you have set up the actions. For example:
name: Go Build

on:
  push:
    branches: [ main ]

jobs:

  build:
    name: Build
    runs-on: self-hosted
    steps:

    - name: Set up Go 1.x
      uses: actions/setup-go@v2
      with:
        go-version: ^1.15

    - name: Check out code into the Go module directory
      uses: actions/checkout@v2

    - name: Run Build
      run: |
        make build
Enter fullscreen mode Exit fullscreen mode

Conclusion

Raspberry pi attracts a huge community of enthusiasts who use it for various use cases. There have been amazing projects like the turing pi, which make use of the more compact Compute module 4 of the raspberry pi to provide server grade computing. Projects like these have enabled developers and system administrators to get cheap compute for self hosted workloads. Easy GitOps is just another fun yet sustainable solution to configure to your own satisfaction, whether it be for a fun project or an industrial use case.

Top comments (4)

Collapse
 
krishna007cloud profile image
raam

Hi Angad, i am unable to install github runner on my pi with 8gb . If i try to run ./config.sh followed by token then i am getting "touch: cannot touch '.env': Permission denied" and if i use sudo then i am getting error that i shouldnt be using sudo. Any advise on how this can be resolved would be great. i have selected Ubuntu ->Arm64 . Thanks

Collapse
 
l04db4l4nc3r profile image
Angad Sharma

That is really good to know. Does it work in the case of a docker build and push GitHub action?