Join us
@prateekjain ・ Sep 01,2022 ・ 3 min read ・ 3158 views
GitLab Runner is an open-source tool that runs CICD jobs in the pipeline. GitLab provides 400 min per month of runner time for free. It’s enough for individuals but not for the teams. GitLab allows you to set up your custom runner on any virtual machine. (separate from the server running GitLab if you have a self-hosted GitLab). Having our custom runner gives us benefits like better security and faster deployments.
In this blog, I will install a GitLab runner in an EC2. Please refer to this article if you don’t know how to spin up an EC2 instance; you can go for t3.micro if you want to benefit from the AWS free tier.
Please refer to the following instance configuration
Now follow the following steps:
SSH to the EC2 instance
Run the following command in your local machine to ssh to your EC2 instance
Install GitLab Runner
Now run these commands to install and start the GitLab runner service.
Before going forward, let’s discuss the concept of executors. The executors decide the environment where you want to run your job. For example,
If you want to run a shell command in your job, then the shell executor should be the choice, and if you want to run the jobs inside the docker container, you will have to use the docker executors. GitLab supports multiple types of runners; please refer to this to understand them.
In this blog, we will register the runners with shell and docker executors.
Register runner with Shell Executor
To register a runner, you will need a registration token from GitLab. For this, log in to your Gitlab account and click on any existing project or create a new one.
Inside the project got to Settings > CICD > Runners
You will see a token; keep this for the next step. Now go back to the EC2 shell and this command with the token you just copied.
This command will ask for inputs and enter them according to this
As we are using Ubuntu 20:04, we might face issues while running the shell runner in the future due to this open issue.
We can resolve this issue by running this command.
Now you are done registering the runner with shell executor, go to the GitLab dashboard and refresh the page, you will be able to see the runner with the tag.
Now let’s install the Runner with Docker executor. but before that, we will have to install the Docker on the server.
Docker Installation
Run these two commands to install the latest stable version of docker
Run these two commands to provide permission of docker to the gitlab-runner user
Register runner with Docker executor
You can’t use the same token for registering two different runners; click on the Reset Registration token to reset the runner.
Now rerun the following command with the new token.
Command will ask for similar information we have seen for shell runner. Just choose executor type as put a different tag, choose docker as executor, and alpine:latest as latest image.
Run this command to verify the runners:
Now you have successfully installed the Gitlab runner with docker executor. Just go back to the Gitlab dashboard and refresh the page; you will be able to see two runners with different tags.
Testing the installation
As we finish the runner setup, it’s time to test the installation. Add a simple .gitlab-ci.yml file in the repo with the following pipeline definition. Don’t forget to change the runner name in the tags section if you use another name.
After saving this file, go to CI/CD > Pipelines. You will see a pipeline is triggered. You can click on individual jobs to see the output of the commands
That’s all for this blog; We will use these runners for running the CI/CD jobs like scan, build and deploy in the upcoming blogs.
Join other developers and claim your FAUN account now!
DevSecOps Engineer, Tech Alchemy
@prateekjainInfluence
Total Hits
Posts
Only registered users can post comments. Please, login or signup.