GitLab Setup
Module Objective
Setting up a GitLab server
Creating users
Pushing and Pulling repositories from our private instance
Creating build pipelines to test for failures
Prerequisites
Network Setup (OPTIONAL)
Section Objective
Create a segregated network for private connections
This section goes over how to set up a Host-Only network if you want to access the server from a virtual machine that is not connected to NAT.
On the Virtual Network Editor, click on Add Network -> OK then select the Host-Only option. You can rename it if you would like.
After you're done with the network configuration, click on your Ubuntu Server VM and click on VM -> Settings
and add your network
GitLab Installation
Section Objective
Setting up a GitLab instance
Setting up runners to compile projects
If you don't see an IP Address, then try running sudo dhclient <INTERFACE>
Before starting this section, have a Linux server up and ready. The script below will install GitLab, Docker, and some quality-of-life tools such as Vim and ohmyzsh (you can remove these from the script if you do not want them).
Download the script then run the following commands:
Once the installation is complete, you should be able to open the GitLab web page from your host/Window VM at the selected IP Address
GitLab creates a random root password which you can get by running the command below
Use this to log in to the web console
Make sure to save or change the root password, as it will be deleted from the server files after logging in.
OPTIONAL - Adding an SSL Certificate
If you are implementing this in an organisation environment, setting up a TLS certificate is advisable to encrypt the traffic going to and from the server. We will not go through this in this blog, but you can easily find it on the GitLab documentation below.
Adding a Runner
Section Objectives
Create a Runner instance
Register the runner to the GitLab server
A runner is a program that runs on your server. It compiles and builds projects depending on the language it's using. We will need to create a runner for each language we use in our project, though multiple projects can use the same runner making it handy for multiple build pipelines.
Below are a couple of languages that you can have a runner use, there are a lot more though.
Installing a runner
To install a runner, we first need to get the dependencies, we've made this simpler by providing the script below:
Download it then execute it. After installation is complete, you will be met with a prompt - keep this open as we move on to the next step.
Getting a Token
Each runner we create requires a unique token which we can generate from the Runners tab, under CI/CD.
Click on New Instance Runner -> Linux -> Create runner to open the runner config settings
Copy the token, then go back to your terminal. Enter your GitLab server IP, then your runner's token, name your runner (you can give it the same name as the UI one), type docker
for the executor, and then the language of your choice. Since I'll be using Go for this demo, use golang:1.22
Once you are done, type in sudo gitlab-runner
run to generate a callback to the server. This will register it for later use.
Make sure to run the command as sudo
sudo gitlab-runner ...
Adding Users
Section Objectives
Create normal users
Add an SSH key for the user
Now that we have the core settings set up, we can start creating users by going to Admin Area -> Users -> New User
Fill in the required details, set the access level as Regular, then click Create User
Before logging out of root, click the Edit button next to the user and give them a username and password. You can optionally set up SMTP to send a password reset link instead.
Once the password has been set, log in to your user, go to Edit Profile -> SSH Keys and add a new SSH key. This will let you push and pull private repositories from this user. We will also do this for our Windows VM to connect our private GitLab repositories to TeamCity.
You can create one by running ssh-keygen
if you do not have a copy or want a separate key for the server. SSH keys can be found in /home/$USER/.ssh/SSH_KEY_NAME.pub
Last updated