VK Cloud logo
Updated at April 15, 2024   08:50 AM

Installing and configuring GitLab

GitLab is a tool for collaborating on software development projects. It provides storage and management of Git repositories, as well as code version control. GitLab automates CI/CD processes: building, testing, and deploying software. To launch and automatically execute CI/CD tasks, GitLab uses the GitLab Runner application.

Below is an example of installing the free versions of GitLab and GitLab Runner on a virtual machine running Ubuntu 22.04. The Docker containerization platform and its Docker Compose plugin are used as the installation tool.

Preparatory steps

  1. Register at VK Cloud.

  2. Create a network network1 with internet access and a subnet with the address 10.0.0.0/24.

  3. Create a security group gitlab and add inbound permissions to it for the ports:

    • 80 (HTTP),
    • 443 (HTTPS),
    • 22 (SSH),
    • 35242 (SSH).

    Instead of 35242, you can use any port that is not reserved by the operating system.

  4. Create a VM running Ubuntu 22.04.

    When selecting VM options, consider the hardware requirements for installing GitLab and GitLab Runner.

    The following VM configuration is used as an example:

    • name: OA-Ubuntu-docker;
    • operating system: Ubuntu 22.04;
    • network: network1 with subnet 10.0.0.0/24;
    • flavor: STD2-4-12;
    • network HDD drive: 50 GB;
    • public IP address: assigned, further will be used 185.185.185.185;
    • security groups: default, gitlab.
  5. (Optional) Assign a domain name to the VM to use for accessing GitLab. Do it in one of the following ways:

    • If you have a domain, add your VM to it.
    • If you do not have a domain, use, for example, NoIP — one of the services that provides dynamic DNS. For this, install a dynamic update client on the VM. More details in the NoIP service documentation.
  6. Connect to the OA-Ubuntu-docker VM via SSH.

  7. Check the status of your operating system firewall and disable it if it is active:

    sudo ufw statussudo ufw disable
  8. Install and configure Docker.

  9. Install the Docker Compose plugin:

    1. Update the list of available Ubuntu packages and their versions:

      sudo apt-get update
    2. Install the latest version of the Docker Compose plugin:

      sudo apt-get install docker-compose-plugin
    3. Verify that the plugin is installed correctly by requesting its version:

      docker compose version

      Expected result:

      Docker Compose version vN.N.N

      Here N.N.N is the plugin version number.

1. Change the port for connecting to the VM via SSH

For access via SSH, GitLab by default uses port 22, which is reserved by the operating system for connecting to the VM via SSH. To avoid conflict, change the system SSH port to another one.

  1. Open the /etc/ssh/sshd_config file for editing:

    sudo nano /etc/ssh/sshd_config
  2. Replace the line #Port 22 with Port 35242.

  3. Save the file and exit the editor by pressing Ctrl + O and then Ctrl + X.

  4. Restart the sshd service:

    sudo systemctl restart sshd
  5. Close the current connection to the VM:

    exit
  6. Connect to the OA-Ubuntu-docker VM via SSH using the new port:

    ssh -i <path to SSH key> ubuntu@185.185.185.185 -p 35242

    Instead of 185.185.185.185 you can use the fully qualified domain name of the VM if it exists.

2. Install GitLab and GitLab Runner using Docker Compose

  1. Create directories for the GitLab persistent repository by sequentially running the commands:

    sudo mkdir -p /opt/gitlabsudo mkdir -p /opt/gitlab/configsudo mkdir -p /opt/gitlab/logssudo mkdir -p /opt/gitlab/datasudo mkdir -p /opt/gitlab-runnersudo mkdir -p /opt/gitlab-runner/configsudo mkdir -p /opt/gitlab-runner/data
  2. Create and open for editing a Docker Compose configuration file:

    sudo nano docker-compose.yml
  3. Copy the following content into the editor window, replacing 185.185.185.185 with the external IP address of the VM or its fully qualified domain name:

  4. Save the file and exit the editor by pressing Ctrl + O and then Ctrl + X.

  5. Launch the Docker Compose plugin:

    sudo docker compose up -d

3. Check the status of your GitLab container

Run the command:

sudo docker ps

Output upon successful operation:

CONTAINER ID   IMAGE                         COMMAND                  CREATED         STATUS                            PORTS                                                                                                         NAMES1e6cee4fe37a   gitlab/gitlab-ce:latest       "/assets/wrapper"        4 minutes ago   Up 9 seconds (health: starting)   0.0.0.0:22->22/tcp, :::22->22/tcp, 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp   gitlab882fc3fb80f5   gitlab/gitlab-runner:latest   "/usr/bin/dumb-init …"   4 minutes ago   Up 4 minutes                                                                                                                                    gitlab-runner

4. (Optional) Issue a public SSL certificate for the VM

If the VM on which GitLab is installed has a domain name, you can issue a public SSL certificate for your GitLab instance, for example from Let’s Encrypt. More details in the official GitLab documentation.

5. Check the functionality of GitLab

  1. Obtain and copy the automatically generated GitLab admin password:

    sudo cat /opt/gitlab/config/initial_root_password

    Output upon successful operation:

    # WARNING: This value is valid only in the following conditions#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).#          2. Password hasn't been changed manually, either via UI or via command line.##          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.Password: /XR7tRH_ХХХХ=# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
  2. In the browser, go to https://185.185.185.185.

    Instead of 185.185.185.185 you can use the fully qualified domain name of the VM if it exists.

    The GitLab login page will open.

  3. To log in, use the administrator login (root) and the copied password.

    The GitLab dashboard will open. The installation is complete, GitLab is ready for operation.

Delete unused resources

Deployed virtual resources are charged. If you do not need them anymore:

  • Delete the OA-Ubuntu-docker VM.
  • If necessary, delete the floating IP address 185.185.185.185.