visit
GitLab CI can be very cryptic to learn, even if the maintainers say that . And the reason is that you need to go through hoops such as configuring a “Runner”, and then create a file which you barely know what to put inside.
In this post, I continue from and show you how to use a Docker runner with GitLab. Posts:I will go through each one of those steps. Feedback is appreciated, in case something needs clarification. If you’re here for the .gitlab-ci.yml
file and how to use it, go .
Things have changed ever since GitLab 10.3. GitLab introduced a Kubernetes Cluster that allows you to run CI in there. Kubernetes is an open-source container management platform (You can deploy Docker images inside it). This tutorial will not cover this. This will cover running a separate Docker instance that will run the CI. I will make a future tutorial on how to set it up with Google Cloud Platform.
For GitLab to use the CI, it needs help from what it calls a . It’s basically a scipt that is executed to run the CI jobs. Yes, they usually reside in a different server than your GitLab installation (Yup, another additional server to spin). They can also be installed in your current machine and do the process there. Haven’t looked into that, yet. I wouldn’t recommend it anyways, since GitLab is resource-intensive by its own.
The good news is that they’re cheap to run. You can run them in micro, nano, and even spot instances! If you’re not familiar with the latter, Amazon has what they call . Basically, since the runner will not always run (It only runs when someone with the CI config file pushes to the server), you don’t need to have a server that is 100% active. You can just rent it per limited time frames (Spot Instances), and you’ll be good to go.You’re more than welcome to create a dedicated instance, and shut it down when it doesn’t need to. You do not need to assign an Elastic IP to the spot instance or the dedicated one that the GitLab runner is using. It’s the runner that communicates to GitLab, not the other way around.
Let’s go to the EC2 DashboardYou can arrive here, by clicking “Services” on the top and then clicking “EC2” Click where it says “Launch Instance”
On the next screen select the Ubuntu Server 64-bit, which has a free tier (If you’re applicable). The version of Linux you choose doesn’t matter. Ubuntu is just more convenient to use.
You want to select the t2.micro since it could potentially give you a free tier. You don’t need a lot of power (This is just at first. If you need more power and speed, go ahead and enable the better instances. For occasional commits (1–2 per day) you won’t die) Then, select “Next: Configure Instance Details”
In here, you have the option to . I recommend you to do it, since it can save you some money. You can read more about EC2 Spot Instances, .
Do not underestimate the next step. Add as much SSD as the free tier gives you. GitLab CI can use Docker (And it’s going to be the method we’re going to use. You don’t have to learn Docker in order to use it), and it’s going to fill up the space really fast (Which you’ll have to give maintenance over time, and delete the images, more on that later).
After that, click on “Next: Add Tags”Tags aren’t mandatory, and you can safely skip this step.
I always recommend the following step because it secures it, and adds a layer of security to prevent unwanted access. Give access only to your IP. Understand, that you’re going to have to do this process each time your IP changes and you want to connect to the machine (If the IP remains the same, then you don’t need to do anything).
Check that everything is OK, and Launch it!
The following screen will ask you whether you want to use an existing or a new one. If you want to have the maximum security use a new key specifically for the GitLab Runner.
Put it into PuTTY (And remember about the .ppk file as well!)
Click on Yes. Once you’re logged in:
Run in the command: sudo apt-get update curl -L | sudo bash sudo apt-get install gitlab-runner If you ever want to update the runner, you just do:
For the URL, type the IPv4 address with the trailing slash (Slash at the end). For example: Then, we need to head to GitLab. Go to the project that you want to setup CI, and head to the main repo page. Then, in the left sidebar, there’s going to be a “Settings” link. Click there. It’ll show you CI/CD on the bottom. Once you’re there, look for “Runners settings”, and click “Collapse”.
Then it’s going to ask you for a description, you can just type “Docker Runner”
You’re going to type shell. Don’t type Docker. The reason is that if we specify Docker, we’ll be specifying what we call a from the Docker hub, and we will specify ours in the config file that we’ll create later.
There we go:
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
3. Add Docker’s official GPG key:
curl -fsSL //download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
4. Setup the repository:
sudo add-apt-repository \ "deb [arch=amd64] //download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
5. Update the package
sudo apt-get update
6. Install the latest version of Docker cE:
sudo apt-get install docker-ce
This will bring a yes/no question: Select yes to install.
7. Verify that Docker got installed correctly by running: sudo docker run hello-world
This is it! Finally, the runner has been configured 🎉🎉 With that in place, the runner should've been successfully configured.
Everything we’ve done so far was to setup the environment for the CI to work. All the Continuous Integration (CI) will work through a .gitlab-ci.yml
file that you need to create in the project.