GitHub Actions on Google Cloud Platform via Cirun.io
The Problem
GitHub Actions is a CI/CD platform for automating the builds, test, and deployment process. Using GitHub actions, we can build and test every pull request in the repository using workflows, or push the merged pull requests to production with workflows. So GitHub actions makes your job easier but there are also some limitations of GitHub actions.
- GitHub actions provide you with limited workflow runs and if you exceed that you have to pay GitHub cloud for the extra workflow runs. GitHub provides you with 2000minutes/month and one can outrun that if they just have 2 cronjobs running every 10min.
- It does not provide users with custom images, variable RAM, and variable CPU's. Custom images are machine images made to do particular things. Sometimes users do not want the full features of a heavy operating system and just want some of the required functionalities. So they use lighter images and set these images for their use case. So for this type of use case, custom images are used and GitHub cloud does not provide you with this. It also provides fixed RAM and CPU's.
- It does not provide you with GPU instances. There are many GitHub repositories that require GPU to build them, and GitHub Actions does not support them as of now.
Cirun
Cirun provides self-hosted GitHub actions. Setting up a self-hosted runner would be a tedious process and Cirun does that for you.
Whenever an event(commit, pull request) is triggered on your GitHub repo, GitHub sends a web hook request to Cirun. As soon as Cirun receives the request, Cirun uses your cloud credentials and creates a VM on your cloud with the specs you have defined on cirun.yml, and then all the workflow files defined on your GitHub repo runs on the newly created VM. After this Cirun continuously checks whether the workflow is completed or not and as soon as the workflow is completed Cirun deletes the VM created. Like this, you can run your GitHub actions on any VM with any specs you want and only pay for what you use.
This blog explains how to set up Cirun for the Google Cloud Platform. The steps for other cloud providers are almost the same. For more reference, you can check the official documentation of cirun.
You need to follow the below steps to set up Cirun on GCP.
- Login via GitHub
- Connect GCP with Cirun
- Install Cirun on your GitHub Repository
- Add GitHub Actions workflow file on your Repository
- Add a
.cirun.yml
file on your Repository - Toggle on the Repository to activate it for Cirun
It’s done!
Demo
Login via GitHub
Connect GCP with Cirun
For connecting google cloud with Cirun we need to follow 3 steps
- Create a Service Account with Compute Engine Admin Permissions
2 . Add a new key pair to your created service account, download JSON file, and paste the JSON content on the Cirun dashboard
3. Enabled Compute Engine API
Visit https://console.cloud.google.com/apis/library?project and search compute engine and enable the API.
Install Cirun on your GitHub Repository
Add GitHub Actions workflow file on your Repository
Create a new gcp.yml
inside .github/workflows
in your GitHub repository and paste the below code. This code prints the host-name, system information, and system architecture. For more information, you can check github-actions-examples.
Add a cirun.yml
file on your Repository
This cirun.yml
file has parameters that define what kind of VM you are requesting, here you specify cloud(GCP, AWS, Azure), instance_type(depends on a cloud provider), machine_image(ubuntu, centos), preemptible(spot instances), etc. For more information check cirun-docs.
Toggle on the Repository to activate it for Cirun
Testing
To test it out let us make a new commit on our GitHub repo.
And the job has started.
And it has printed the host-name, system info, and system architecture.
Conclusion
Cirun automates the process of setting up a self-hosted runner for your GitHub repository. At this time it supports all major cloud providers(AWS, GCP, Digital Ocean, Azure, Openstack). It also supports GPU instances(if your cloud subscription allows it). At this time you only pay your cloud provider for what you use and cirun does not charge you anything for it.
Cirun is also completely free for open source.
Appendix
Repository Link used for Demo — https://github.com/nabin-nath/cirun-demo-gcp
Cirun — https://cirun.io
Cirun Documentation — https://docs.cirun.io