In this guide, I’ll walk you through the process of installing GitLab, a comprehensive suite of tools for version control, continuous integration, continuous delivery, and more, in my Home Lab collection.


Preparation

After obtaining the latest Ubuntu Server, I utilized Rufus, a utility for formatting and creating bootable USB flash drives.


Installation

Following the installation instructions, initiate a quick installation using the following command:

curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

gitlab-quick-install


Upgrading to the Latest Version

Referencing the official repositories for upgrading, upgrade GitLab to the latest version:

sudo apt update && sudo apt install gitlab-ce

# List all the versions
sudo apt-cache madison list gitlab-ce

# Gitlab upgrade to a specific version, e.g. version 17.3.3
sudo apt install gitlab-ce=17.3.3-ce.0

gitlab-upgraded


Setting External URL

Begin by configuring the external URL:

sudo vi /etc/gitlab/gitlab.rb

# Search for external_url and input the IP address
external_url 'http://192.168.68.126'

gitlab-external-url

Once configured, start the GitLab instance:

sudo gitlab-ctl reconfigure

gitlab-reconfigured

Retrieve the default admin account password:

sudo vi /etc/gitlab/initial_root_password

Visit the configured address, http://192.168.68.126:

gitlab-initial-login

Deactivate sign-up restrictions:

gitlab-deactivate-sign-up

Clink the Save changes button:

gitlab-uncheck-sign-up-enabled


Migrating from Old to New Repository

1. Clone the Existing Repository

Clone the existing repository to your local machine:

git clone <old_repo_url>

2. Set up SSH key

  1. Generate an SSH key on your working machine:
ssh-keygen -t rsa -b 4096

eval "$(ssh-agent -s)"

# Save the key to ~/.ssh/gitlab_id_rsa
ssh-add ~/.ssh/gitlab_id_rsa

# Export the public key
cat ~/.ssh/gitlab_id_rsa.pub
  1. Update shell profile (e.g. ~/.bashrc) by adding the following lines to the bottom:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/gitlab_id_rsa
  1. Restart your shell or source the configuration:
source ~/.bashrc  # or source ~/.zshrc for Zsh
  1. Save the SSH public key in GitLab.

gitlab-add-ssh-public-key

  1. Since th SSH key pair is not in the default location, save these settings in ~/.ssh/config file:
Host 192.168.68.126
	PreferredAuthentications publickey
    IdentityFile C:\Users\seehi\.ssh\gitlab_id_rsa

3. Create a New Repository

Navigate to the cloned repository directory and update the remote URL:

cd <local_repo_directory>

# In this example, a new group called personal is created; the new repo is not yet created
git remote set-url origin git@192.168.68.126:personal/langchain4j-spring-boot.git

4. Push to the New Repository

Push the local repository:

git push -u origin main

Install GitLab Runner

Referencing Install GitLab Runner, add the official GitLab repository:

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

gitlab-add-repository-for-runner

Install the latest GitLab Runner version:

# To install or update the GitLab Runner
sudo apt-get update
sudo apt-get install gitlab-runner

# Verify if GitLab Runner is running
sudo gitlab-runner status

Install Docker

Referring to Install Docker Engine on Ubuntu, set up Docker’s apt repository:

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

# Install the Docker packages
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Verify Docker Engine installation
sudo docker run hello-world

# Adds user to docker group (needs to re-login to take effect)
sudo usermod -aG docker pi

Register GitLab Runner

In the project settings, navigate to the CI/CD option, expand the Runners section, and click on the New project runner button:

gitlab-setup-runner-for-project

Set the tag (e.g., docker-linux), select Run untagged jobs, and click the Create runner button:

gitlab-new-project-runner

Once the runner is created, copy the command provided:

gitlab-runner-created

Next, paste the command to register a runner:

# You may use sudo to save config to /etc/gitlab-runner/config.toml instead (otherwise follow optional section)
gitlab-runner register  --url http://192.168.68.126  --token glrt--LuoR7v6HNubypzQusrz

# You can run this in the background
gitlab-runner run

gitlab-runner-registered


Run GitLab Pipeline

Here’s a sample .gitlab-ci.yml file:

variables:
    IMAGE_GRADLE_JAVA: gradle:jdk17
stages:
    - build
gradle-build:
    image: $IMAGE_GRADLE_JAVA
    stage: build
    script:
        - echo "Building"
        - sh $CI_PROJECT_DIR/gradlew clean build

gitlab-create-ci-yml-file

To trigger the build stage, go to Build -> Pipeline, and click on the Run pipeline button. Here’s a sample run and its result:

gitlab-runner-run

gitlab-pipeline-build-result


Optional: Register GitLab runner as a Service

If you observe, my config file is stored in /home/pi/.gitlab-runner/config.toml. To use this setting:

# The easiest way is to copy the config to the default location
sudo cp /home/pi/.gitlab-runner/config.toml /etc/gitlab-runner/config.toml

Start the GitLab runner service:

sudo systemctl enable gitlab-runner
sudo systemctl status gitlab-runner

Run the pipeline again:

gitlab-pipeline-rebuild


Optional: Enable Container and Package Registry

To enable the container and package registry, follow these steps:

  1. Modifies the gitlab.rb file:
sudo vi /etc/gitlab/gitlab.rb
  1. Make the necessary changes to configure the registry:
external_url 'http://192.168.68.126'

registry_external_url 'http://192.168.68.126:5005'
gitlab_rails['registry_enabled'] = true
gitlab_rails['registry_host'] = "192.168.68.126"
gitlab_rails['registry_port'] = "5005"
gitlab_rails['registry_path'] = "/mnt/registry"

registry['enable'] = true
registry['dir'] = "/var/opt/gitlab/registry"
registry['registry_http_addr'] = "127.0.0.1:5000"
registry['log_directory'] = "/var/log/gitlab/registry"
registry['env_directory'] = "/opt/gitlab/etc/registry/env"
registry['env'] = {
  "REGISTRY_HTTP_RELATIVEURLS" => true
}

letsencrypt['enable'] = false

gitlab_rails['packages_enabled'] = true
gitlab_rails['packages_storage_path'] = "/mnt/packages"
  1. Reconfigures gitlab:
sudo gitlab-ctl reconfigure

# Verifies if gitlab registry is accessible; authentication required message expected
curl -k http://192.168.68.126:5005/v2/
  1. Modify Docker Desktop (for Windows) via Settings -> Docker Engine:
"insecure-registries": [
   "192.168.68.126:5005"
],
  1. Log in to the registry from your Windows machine:
 docker login 192.168.68.126:5005
  1. You may have to configure your docker if you see this error from Windows box:
Error response from daemon: Get "https://192.168.68.126:5005/v2/": http: server gave HTTP response to HTTPS client

a. From gitlab server, configure docker to use local registry:

sudo vi /etc/docker/daemon.json

b. Copy this content into daemon.json:

{
 "insecure-registries": [
   "192.168.68.126:5005"
 ]
}

c. Edit docker default configuration file, with sudo vi /etc/default/docker and add this:

DOCKER_OPTS="--config-file=/etc/docker/daemon.json"

d. Restart docker to apply the changes:

sudo systemctl restart docker