Setup GitLab runner on AWS-ec2

suyog shinde
nonstopio
Published in
4 min readMar 28, 2022

--

In this article, we are gonna set up a GitLab runner on the amazon ec2 instance.

What is GitLab?

Gitlab is a simple, understanding, and efficient platform for DevOps platform. There are six core values of GitLab 🤝 Collaboration, 📈 Results, ⏱️ Efficiency, 🌐 Diversity, Inclusion & Belonging.

What are Gitlab runners? 🤔

GitLab runner is like a kitchen 🍳 in our home, We use it to cook something. In DevOps, it’s called an agent/Slave. It’s basically an agent that runs your CI/CD that comes from GitLab. When we set up a runner that creates a communication between your GitLab and the machine where GitLab Runner is installed.

For example⬇️,

1 . We need to build a container and push it to a repository.

2. Run an npm build and copy the build folder to a remote location.

3. Perform some remote execution using ssh.

Let’s start setting up the GitLab runner👷,

Here, We are going to use a Ubuntu ec2 instance .

Step 1: Add the repository of Gitlab-runner.

curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash

This will add an official GitLab repository.

Step 2: Install GitLab Runner on ubuntu

The below commands to install the latest GitLab runner.⬇️

sudo apt-get update 
sudo apt-get install gitlab-runner

Step 3: Check if it’s installed correctly or not.

sudo gitlab-runner -version

After running the above command you can view the output shown below.

Version:      14.8.2
Git revision: c6e7e194
Git branch: 14-8-stable
GO version: go1.17.7
Built: 2022-03-01T17:18:25+0000
OS/Arch: linux/amd64

Note📝: This may differ in your case

To check the Gitlab runner status

sudo gitlab-runner status

Output:

Runtime platform  
arch=amd64 os=linux pid=284992 revision=c6e7e194 version=14.8.2
gitlab-runner: Service is running

Step 4: Register a Gitlab Runner to Gitlab on Ubuntu

  1. Login to the GitLab account. Go to the project and its setting.

Gitlab ➡️Login ➡️project ➡️ Settings ➡️ CI/CD ➡️ runners

CI/CD

👀 Expand the runner tab and you’ll see two things: the URL and the
registration token. 👀

Keep a copy of them as we are going to use them to register the runner.

Note: You should disable the Public runner so all the jobs tents towards the private runner. i.e Ubuntu.

Now, Let’s register it.

sudo gitlab-runner register

Use the above command to start the registration process.

You’ll be prompted for 6 inputs.

  1. Enter the GitLab instance URL: https://gitlab.com/
  2. Enter the registration token: We copied it from the project setting above. These are private and Do not share with anyone.
  3. Enter a description for the runner: Your choice
  4. Enter tags for the runner (comma-separated):

These tags are most important as we are gonna use them in the pipelines to uniquely identify the runner

5. Enter an optional maintenance note for the runner: Your choice

6. Enter an executor:

Note: the executor might change use-case to use-case. For example

A. We need a docker container and perform an action on that, In this case, we use “docker” as executor.

B. We need to shell, In this case, we use “shell” as executor.

Step 5: Let’s start the GitLab-runner.

sudo gitlab-runner start

Step 6: Check in the Gitlab console

⭐ You can see the available runner in GitLab

We have successfully installed and registered the GitLab runner on the Ubuntu ec2 instance.

Thanks for reading!

Do read my other blogs on various topics related to DevOps

  1. How-to-set-up-code-ready-containers-on-ubuntu

2. Part 1: GitHub Actions → Docker Hub — Versioning → Continous Integrations

3. Kubernetes-architecture-in-simple-words

--

--