Create GitHub Actions self Hosted Runner on Google Cloud

Vishal Bulbule
4 min readMay 20, 2024

--

Introduction:

GitHub Actions is rapidly becoming a dominant force in the CI/CD landscape.

GitHub Actions has revolutionized the way developers automate their workflows, enabling seamless integration and automation of software development processes. With GitHub Actions, you can automate tasks such as building, testing, and deploying your code directly from your GitHub repositories.

In this article, we’ll explore GitHub Actions runners, their types, limitations, and step-by-step instructions on setting up a self-hosted runner on a Google Cloud VM.

Understanding GitHub Actions:

GitHub Actions is a powerful CI/CD (Continuous Integration/Continuous Deployment) tool provided by GitHub. It allows developers to automate their workflows directly within their GitHub repositories. Workflows are defined in YAML files within the repository and can be triggered by various events such as push, pull request, or scheduled intervals.

What is a Runner?

Runners are the machines that execute jobs in a GitHub Actions workflow. For example, a runner can clone your repository locally, install testing software, and then run commands that evaluate your code. There are two types of runners: GitHub Hosted Runners and Self-Hosted Runners.

GitHub Hosted Runners:

GitHub provides pre-configured virtual machines with various operating systems and software environments known as GitHub Hosted Runners. These runners are managed by GitHub and are available for use in your workflows without any additional setup.

To use a GitHub-hosted runner, create a job and use runs-on to specify the type of runner that will process the job, such as ubuntu-latest, windows-latest, or macos-latest.

GitHub hosts Linux and Windows runners on virtual machines in Microsoft Azure with the GitHub Actions runner application installed.macOS runners are hosted in GitHub’s own macOS cloud.

Self-Hosted Runners:

Self-hosted runners, on the other hand, are machines that you provision and manage yourself. They allow you to customize the hardware, software environment, and security settings to fit your specific needs. Self-hosted runners are particularly useful for projects that require specific dependencies or require access to private resources.

You can add self-hosted runners at various levels in the management hierarchy:

  • Repository-level runners are dedicated to a single repository.
  • Organization-level runners can process jobs for multiple repositories in an organization.
  • Enterprise-level runners can be assigned to multiple organizations in an enterprise account.

How to Setup Self-Hosted Runner on Google Cloud VM Instance:

Setting up a self-hosted runner on a Google Cloud VM instance is a straightforward process. Here’s a step-by-step guide:

Create a Google Cloud VM Instance:
— Log in to your Google Cloud Console.
— Navigate to Compute Engine > VM instances.
— Click on “Create Instance” and configure the VM with your desired specifications such as machine type, boot disk, and networking options.
— Click “Create” to provision the VM instance.

Now Navigate to GitHub Repository>Setting>Actions>New Self-hosted Runner

Select your VM OS and follow the instruction

Execute All command in VM Instance one by one . Please find below expected output for each command.

Verify If you can see Runner in Your repository. You might see any one of the following status

Idle — If No job running

Active — If any Job is running

Offline — If runner application is not running on VM

Test with sample Workflow. Your runner should pick job and display below logs

Sample Workflow


name: Simple Workflow

on:
push:
branches: [ "master" ]



jobs:
build:
# The type of runner that the job will run on, self-hosted is label on runner
runs-on: self-hosted
steps:
- uses: actions/checkout@v4

- name: Run a one-line script
run: echo Hello, Learning Github Actions!!
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.

Workflow Logs

Conclusion:

Setting up a self-hosted runner on a Google Cloud VM instance allows you to leverage the power of GitHub Actions while maintaining control over your execution environment. Whether you need custom dependencies, access to private resources, or specific security configurations, self-hosted runners provide the flexibility to meet your project’s requirements. By following the steps outlined above, you can seamlessly integrate GitHub Actions into your development workflow and automate your software development processes with ease.

--

--