Are you interested in hosting your own servers to run your GitLab CI/CD pipelines but don’t know where to begin? Setting up a GitLab Runner to run your pipelines on your own infrastructure can seem like a daunting task as it requires infrastructure knowledge and the know-how to maintain that infrastructure. Typically this process requires the provision of infrastructure, the installing of dependency, and testing that it works with your GitLab instance.
This article highlights how easy it is to easily spin up a GitLab Runner of your own utilizing GitLab’s Google Cloud Integration. Follow this tutorial and it will teach you how to set up a new group runner on GitLab.com using Google Cloud Platform in less than 10 minutes!
You will learn how to:
- Create a new group runner.
- Configure the new group runner’s tags and description.
- Register the new group runner by adding in configurations.
- Provision the GitLab Runner utilizing
gcloud cli
and Terraform. - Have your GitLab Runner pick up its first GitLab CI job.
Prerequisites
- A terminal with Bash installed
- Owner access on a Google Cloud Platform project
- Terraform (or OpenTofu) Version 1.5 or greater
- gcloud CLI
- 10 minutes
Tutorial
- Create a new group runner under Build > Runners > New Group Runner.
Note: Navigate to the group level.
- Configure the new group runner’s tags, description, and any additional configurations.
- Select Google Cloud.
- Copy your project ID from Google Cloud Platform.
- Fill out your Google Cloud project ID and choose a region, zone, and type of machine you want to use.
6. Once this information is filled out, click Setup instructions.
Run the bash script provided in Step 1 above.
Note: This script was saved to a file called setup.sh
for ease of use. You may copy this right into your terminal if you are confident in debugging.
7. Create a main.tf
file and follow the instructions in GitLab.
Note: If you want to use OpenTofu instead of Terraform, you can still copy the code and only have to adjust the Terraform commands for applying the configuration.
Once successfully provisioned, you should be see the following:
8. If you close the instructions and click the View runners button, you will now have a newly provisioned runner present with “Never contacted” as its status.
9. In any project, add the following .gitlab-ci.yml
.
stages:
- greet
hello_job:
stage: greet
tags:
- gcp-runner
script:
- echo "hello"
Volia! You have set up your first GitLab Runner utilizing Google Cloud Platform.
Now that you have provisioned your very own GitLab Runner, consider optimizing it for your specific use case. Some things to consider with your runner moving forward:
- Is the runner I provisioned the right size? Does it need additional resources for my use case?
- Does the GitLab Runner contain all the dependency my builds need?
- How can I store the GitLab Runner as infrastructure as code?
Make sure to bookmark the Provisioning runners in Google Cloud documentation for easy reference.