Setting up Cirun on Digital Ocean
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
-
Sign up on Cirun using Github
-
Connect Digital Ocean with Cirun.io
-
Install Cirun on the Repo
-
Add Github Actions file
-
Add a
.cirun.yml
file -
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
- In the navbar present on the left hand side, click on
Cloud
and click on theConnect DigitialOcean
button
- Give access to the account that you want to
Install Cirun on the repo
-
In the Navbar present on the left hand side, click on
Repositories
and click onInstall App on Github
-
Select the organization or your account(like I did)
-
Select the repo on which you want to install
-
Click install
Adding Github Actions file
To add the
yaml
file for Github Actions, create a new file, saydemo.yml
at the path.github/workflows/demo.yml
. Here is a simple action, which does a simplewget
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
Testing
To test lets trigger a commit in README
Its running!
And its done!
Note
-
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.
-
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
-
Vist the Cirun Dashboard
-
Click on the
Repositories
on the navbar present on the left hand side -
Click the toggle button beside the repository name you want to turn off
How to verify that the Actions are NOT running on Github Cloud
-
If the
yaml
file in.github/workflows
folder containsruns-on: self-hosted
, the action will never run on Github Cloud -
You can also check the logs through the below steps:
-
Go to the
Actions
Tab on Github Repository’s link by visitinghttps://github.com/USERNAME/REPONAME/actions
-
Click on the
Workflow
that you want to check -
Click on the tag containing the job name
-
Click on the
Set up job
header, to read the logs. You will find that theMachine name
orRunner name
have containcirun
, which indicates that the job ran on a machine on another cloud created by Cirun.
-
(The Actions that run on Github Cloud have different logs. They look something like this
)
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.
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)