Installing GitLab is a bit of a chicken and egg story.

I need GitLab because it’s a repository, pipeline trigger, Docker image registry, etc. But I’d like the installation to be automated, with Terraform, Ansible, etc.

But for now, I’m going to do the installation manually. The Terraform and Ansible scripts I want to run in pipelines and be versioned should also be in Docker images in the GitLab registry.

Installation

Of all the services so far, Gitlab is the most resource-intensive, in terms of CPU and memory, which is why I chose to create a VM in Vagrant.

(Vagranfile)

Vagrant.configure("2") do |config|
  config.vm.define "srv-gitlab-02" do |gitlab|
    gitlab.vm.box = "bento/ubuntu-22.04"
    gitlab.vm.hostname = 'srv-gitlab-02'

    gitlab.vm.network "public_network", use_dhcp_assigned_default_route: true, bridge: "enp7s0", ip: "172.21.5.153"
    gitlab.vm.synced_folder "/work/", "/work"
    gitlab.vm.provider :virtualbox do |v|
        v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
        v.customize ["modifyvm", :id, "--memory", 4096]
        v.customize ["modifyvm", :id, "--name", "srv-gitlab-02"]
    end
  end
end

Once the VM has been created, start preparing and installing it:

$ apt-get update
$ apt-get install -y python3 wget net-tools gpg lsb-release vim libcap2-bin curl python3-pip less iputils-ping ssh ca-certificates postfix tzdata perl

Set up SSH:

# as root:
$ sudo sed -i 's/\#PasswordAuthentication yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config
$ sudo systemctl restart sshd.service

Also create a root user:

$ adduser faustobranco
$ vi /etc/sudoers

faustobranco ALL=(ALL:ALL) NOPASSWD: ALL
$ usermod -aG sudo faustobranco

Add the GitLab repository and install it:

$ cd /tmp
$ curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6865  100  6865    0     0  16118      0 --:--:-- --:--:-- --:--:-- 16115
$ sudo bash /tmp/script.deb.sh

Detected operating system as Ubuntu/jammy.
Checking for curl...
Detected curl...
Checking for gpg...
Detected gpg...
Running apt-get update... done.
Installing apt-transport-https... done.
Installing /etc/apt/sources.list.d/gitlab_gitlab-ce.list...done.
Importing packagecloud gpg key... done.
Running apt-get update... done.

The repository is setup! You can now install packages.
$ sudo apt-get install -y gitlab-ce

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  gitlab-ce
0 upgraded, 1 newly installed, 0 to remove and 34 not upgraded.
Need to get 1,128 MB of archives.
After this operation, 3,175 MB of additional disk space will be used.
Get:1 https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu jammy/main amd64 gitlab-ce amd64 16.9.2-ce.0 [1,128 MB]
Fetched 1,128 MB in 24s (46.6 MB/s)
Selecting previously unselected package gitlab-ce.
(Reading database ... 52015 files and directories currently installed.)
Preparing to unpack .../gitlab-ce_16.9.2-ce.0_amd64.deb ...
Unpacking gitlab-ce (16.9.2-ce.0) ...
Setting up gitlab-ce (16.9.2-ce.0) ...
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.



     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/


Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

Help us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=16-9

Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

First configuration

In this installation, the Gitlab VM has the IP 172.21.5.153.

First, create a DNS entry in Bind9 – DNS.

gitlab             IN      A      172.21.5.153
$ nslookup gitlab.devops-db.internal
Server:         172.21.5.155
Address:        172.21.5.155#53

Name:   gitlab.devops-db.internal
Address: 172.21.5.153

Change external_url

vi /etc/gitlab/gitlab.rb

external_url 'http://gitlab.devops-db.internal'

Reload the configuration (it takes a while):

sudo gitlab-ctl reconfigure

Recover the initial password:

$ sudo cat /etc/gitlab/initial_root_password
# 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: QrdaA5VcHZW4J2k6ZNIHsYHp9WpV6MfKAotCkuUEGeQ=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

We’re ready for the first login. Go here: http://gitlab.devops-db.internal/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.