GitHub Actions runners on Oracle Cloud with Cirun.
Tags: cirun, github, oracle, cicd
Published: 2022-12-29 15:17:49


![Cirun](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p4js59col2lauidbe62i.png)
## Understanding The Problem
As we all know GitHub Actions is a CI/CD platform used to automate the builds, test, and deployment process. GitHub Actions uses workflows to automate the whole process. We can run the builds and tests on every push and pull request, or even on merging the pull request with workflows. For all this GitHub Actions use its cloud machines but also they have some limitations.

1. GitHub Actions does not provide support for custom images, or customized configurations of hardware. Sometimes users need a custom image to complete their build and run tests on it according to their use case. Also, GitHub Actions provides a fixed configuration of the systems.![GitHub Actions Hardware](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kujjc2yff7ptdxs5hdkq.png)

2. It does not provide users with GPU instances. When working on stuff like MLops that may requires GPU to build. 

3. GitHub Actions provide you with limited execution time for each run in a workflow that is 6 hours. If a job takes more than this time to execute it will automatically terminate. GitHub provides you with 2000 minutes/month and 500 MB of free storage. To use beyond these limits we have to pay some amount. You can see the pricing [here](https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions).

### What if we can automate this whole process on our cloud and run workflows on desired machine?
 
Definitely, we can do this on our cloud using GitHub actions feature self-hosted runners and Cirun. Also, we have to pay what we are using.

## About Cirun
Cirun provides self-hosted GitHub Actions Runners on your clouds. 
![Flowchart](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vzdob8i4e92uo1ptvh4c.png)

### From Flowchart
We can see whenever an event is triggered on the repository. GitHub sends a webhook to cirun. Cirun authenticates the cloud using credentials provided by you. It takes Machine configurations defined in `.cirun.yml` from your GitHub repository and sends a request to the cloud for creating instance. The cloud will create a instance using `.cirun.yml` file, and then all workflow files defined on the GitHub repo will run on the instance. Besides all of this, Cirun continuously checks whether the workflow is completed and the machine is idle or not? If condition is satisfied then cirun delete's the VM, and we have to pay what we used.

This blog explains GitHub Actions runners on Oracle Cloud with Cirun.. For reference, you can check cirun [documentation](https://docs.cirun.io/reference/examples#oracle-cloud).

The steps are almost the same for other cloud providers.

1. In Cirun, log in with GitHub
2. Install Cirun on your Repository
3. Toggle on the Repository to activate.
4. Pass your cloud credentials and connect Oracle with Cirun
5. Add workflow file and `.cirun.yml` file on your repository
6. Now push a trigger in your Repository

It's done! :rocket:

#### Demo

#### In Cirun login with GitHub
![Login with GitHub](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ulwhwo6a3bkri0q95ug.png)
##### Install Cirun on your Repository
![Install github to repo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/udl92fc7hq7rb4l9ihyl.png)
1. Configure Cirun
![Install](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3drqeohdc7mgphugowo.png)
2. Give access to repositories
![Access to repo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bat5j5hnco50k78y10qo.png)
3. To activate the repository toggle the button.

![Toggle on the repo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cocnn9133po249roa5xj.png)




## Adding Oracle cloud to Cirun

**_NOTE:_**  Make sure you have permissions to create VMs/runners.

1. Navigate to profile.

![Oracle user profile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5hbpalxfl388hw5ha8dc.png)

- Click on API keys
![API keys](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b73hfaodujb4y3rrfoq8.png)

- After clicking on Add api key, download private key and hit add button.
![Add API key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sfn0mhl58tszp2ttraxu.png)

- After adding, you will have this kind of configuration file. Copy `user`, `fingerprint`, `tenancy` and paste them in text file.
![Configuration file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iouog2k84cjjaaj4o8l6.png)

- Then navigate to compartments and copy ocid, then paste this inside text file as `compartment_id=`.

![Ocid](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2ad3rnfotat0orm3t8h.png)

- Paste your text saved in text file and downloaded private key in Cirun dashboard under cloud section.

![Paste your keys](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83bz1c1yaninr9wsmke5.png)

### Add Workflow file on your Repository
Create a `oracle.yml` file inside `.github/workflows`. In workflow you can put jobs you want. For example paste the yml file given below to print the hostname, system info, memory, architecture, OS version. For latest file you can visit [GitHub repo](https://github.com/vishal9629/cirun-oracle).
```yml
name: GitHub Actions on Oracle Cloud

on: push
jobs:
  build:
    runs-on: [self-hosted, oracle-cloud]

    steps:
      - uses: actions/checkout@v3
      - name: Get Hostname
        run: |
          hostname
      - name: Get system Information
        run: |
          uname -a
      - name: Get Architecture
        run: |
          dpkg --print-architecture
      - name: Get system Disk space
        run: |
          df -h
      - name: Get OS version
        run: |
          cat /etc/*release
      - name: Run "lscpu"
        run: lscpu
      - name: hello world
        run: echo hello world
      - name: Todays Date
        run: date
```

#### Now add a `.cirun.yml` file in your Repository

In this yml, we define the configuration and flags we want on your clouds (AWS, GCP, Oracle, etc.), instance_type, and machine_image. To explore more you can visit cirun [documentation](https://docs.cirun.io/reference/examples#oracle-cloud).

In this blog, we are creating `.cirun.yml` file for the AWS cloud with the infinitely scalable runner. 
```yml
runners:
  runners:
  - name: oracle-runner
    cloud: oracle
    instance_type: VM.Standard.E2.1.Micro
    machine_image: ocid1.image.oc1.uk-london-1.aaaaaaaavy5v3inu2ho2h57vwvvsclukdh4jvhg45um2nrejyxa7s46zcwoq
    region: uk-london-1
    workflow: .github/workflows/oracle.yml
    labels:
      - oracle-cloud
```

### Pushing a trigger

- To trigger an event we must commit something in our repo.


![New trigger](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iid51fcltn5z2hrqw86n.png)

- With a new commit, cirun sends a request to the cloud then the cloud makes a instance and runs the workflow


![Running workflow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5blfmq43mzfd4h33j8n9.png)

- Printed the hostname, system info, memory, architecture, OS version.

![Printed jobs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mxb4914j06cl0uis6nvl.png)

### Conclusion

GitHub Actions provide us with self-hosted runners for your repository but setting up them is a tedious task. You can automate the set-up process using cirun. Cirun charges some amount for private repositories and you have to pay for what you use on your cloud. Cirun supports all major cloud providers at this time. (AWS, GCP, Digital Ocean, Azure, Openstack, Oracle).
For more information you can visit [cirun.io](https://cirun.io/).

### References 

- [Cirun](https://cirun.io/)
- [Cirun documentation](https://docs.cirun.io/)
- [Repository used for demo](https://github.com/vishal9629/cirun-oracle)

If you have any questions and feedback about this blog, feel free to comment or reach out [Cirun.io](https://cirun.io/).