The problem

Github Actions are amazing. They let you perform jobs on Github Cloud. But if you are using Github Actions too much, you might run out of the free minutes and you end up paying a lot. It is very likely that you are already paying for a cloud provider like AWS, Digital Ocean or Azure. So, a better idea would be to run the job on the existing cloud itself, instead of paying separately to run on Github cloud.

The best part about Github Actions is they allow you to run these jobs on Self hosted machines. That means when an event happens, Github will send a request to API that you provide to let you know that job needs to be performed. And you can perform the job on your own cloud machine. By using this process, you have 2 advantages

  • You don’t have to pay for Github Actions
  • You can see checks and logs on Github’s interface

Cirun.io

Setting up your self hosted runner with Github Actions from scratch is a time taking process. Cirun.io saves your time. Setting up Cirun.io is extremely easy. The rest of blog shows you how to setup self-hosted runner on Digital Ocean using Cirun. The following steps outline process is

  1. Sign up on Cirun using Github

  2. Connect Digital Ocean with Cirun.io

  3. Install Cirun on the Repo

  4. Add Github Actions file

  5. Add a .cirun.yml file

  6. Toggle on the Actions on Cirun

    Its done!

The first step is a trivial step, just like any other OAuth signup.

Connect Digital Ocean with Cirun

  1. In the navbar present on the left hand side, click on Cloud and click on the Connect DigitialOcean button

Click on Cloud

  1. Give access to the account that you want to

Give Access to Cirun

Install Cirun on the repo

  1. In the Navbar present on the left hand side, click on Repositories and click on Install App on Github

    Installing App on Repo

  2. Select the organization or your account(like I did)

    Select Organization

  3. Select the repo on which you want to install

    Select repo

  4. Click install

    Install

    Adding Github Actions file

    To add the yaml file for Github Actions, create a new file, say demo.yml at the path .github/workflows/demo.yml. Here is a simple action, which does a simple wget request when something is pushed to the repo.

    name: Sample demo Action
       
    on:
      push
        
    jobs:
      build:
        name: Send a GET request via wget
        runs-on: self-hosted # THIS IS IMPORTANT
        steps:
          - name: wget request
            run: wget https://archive.org/stream/GuerillaOpenAccessManifesto/Goamjuly2008_djvu.txt
       
    

Note that runs-on has the value self-hosted. The name of machine should not be mentioned in this file.

Adding .cirun.yml file

In the root of the repository file, create a file named .cirun.yml which will be utilized by Cirun to run action on the machine.

# Self-Hosted Github Action Runners on DO via Cirun.io
# Reference: https://docs.cirun.io/reference/yaml.html
runners:
  - name: Sample action
    # Cloud Provider: DigitalOcean
    cloud: digitalocean
    # Cheapest VM on DigitalOcean
    instance_type: s-1vcpu-1gb
    # Ubuntu-20.4  image"
    machine_image: ubuntu-20-10-x64
    # Path of the relevant workflow file
    workflow: .github/workflows/demo.yml
    # Number of runners to provision on every trigger on Actions job
    count: 1

The comments in the above code are self-explanatory.

Toggle on

In Cirun Dashboard, click on Repositories present on the navbar on left hand side. Toggle on the repo, where you have installed Github Actions

Toggle on

Testing

To test lets trigger a commit in README

Trigger a commit

Its running!

Its running

And its done!

Done

Note

  1. You can see in the above image that some of the previous actions failed. That is because it takes some time for Cirun to start working. So if it fails, check the configuration files once again and if everything seems alright, try triggering another commit after few minutes.

  2. If its a cronjob, it takes some time to get triggered. If you want to verify if your configurations file are configured right, follow these steps

    • Make changes to file present in .github/workflows such that action is triggered on a push

    • Try making a commit after few minutes. If it still fails, try reading the error logs under Actions tab in Github(a common error is not putting self-hosted in the Github Actions file as discussed above)

Turning off

  1. Vist the Cirun Dashboard

  2. Click on the Repositories on the navbar present on the left hand side

  3. Click the toggle button beside the repository name you want to turn off

    Turn off

How to verify that the Actions are NOT running on Github Cloud

  • If the yaml file in .github/workflows folder contains runs-on: self-hosted, the action will never run on Github Cloud

  • You can also check the logs through the below steps:

    1. Go to the Actions Tab on Github Repository’s link by visiting https://github.com/USERNAME/REPONAME/actions

    2. Click on the Workflow that you want to check

      Click on Workflow

    3. Click on the tag containing the job name

      Click on Job name

    4. Click on the Set up job header, to read the logs. You will find that the Machine name or Runner name have contain cirun, which indicates that the job ran on a machine on another cloud created by Cirun.

      Machine name or Runner name

(The Actions that run on Github Cloud have different logs. They look something like this

Actions that run on Github Cloud)

Thanks

Thanks to Amit Kumar, the founder of Cirun.io, who help us setup Cirun at Neera.ai. At Neera, we run a cronjob every 10 minutes to update User’s pocket articles and Notion documents. Github Actions provides a convenient interface to check the status of Cronjob. With 2 cronjob running every 10 minutes, we were out of free minutes soon after a couple of weeks. Now currently, we run both the cronjobs on Digital Ocean cloud using Cirun.

Setting up Cirun was really a smooth experience and done quickly. There are other nice use cases for Cirun like it supports running on GPU, which Github actions does not. Most amazing thing about Cirun is, it is free for open source Projects.

Cirun Supporting Open Source

Appendix

  • Repository Link used for Demo - https://github.com/rakaar/cirun-demo
  • Video to setup Cirun on AWS Cloud - https://youtu.be/lDx0YVTn6yg (Demo video by Amit Kumar)