Installing GitLab CE on a Raspberry Pi 4
I’ve been aiming to work on a bunch of smaller coding projects and with that, I wanted a way of storing them locally on my network. This meant I can manage all the git infrastructure and storing binaries with LFS and not having to pay monthly costs for GitHub or the like. This led me to set up my own instance of Gitlab Community Edition on my Raspberry Pi 4. There are a few documents out there on the topic which I have listed at the end for further reading but this article will discuss my setup in full.
1. Install and configure the necessary dependencies
1 2 |
sudo apt-get install curl openssh-server ca-certificates apt-transport-https curl https://packages.gitlab.com/gpg.key | sudo apt-key add - |
For me I’m going to use GSuite to setup my SMTP web server for sending emails, we do that later in the config.
2. Setup HDD drive space.
For me, I’m using an external HDD atm. I just mounted one of the partitions to /var/opt/gitlab. I do this by editing my /etc/fstab file with the following line (you can ignore the comment, I’m keeping it here to explain the meaning of each value).
1 2 |
# device mounting_directory filesystem_type options dump fsck /dev/sda1 /var/opt/gitlab ext4 defaults,nofail 1 2 |
default means Use default options: rw, suid, dev, exec, auto, nouser, async
nofail means “do not report errors for this device if it does not exist.” Usually, our pi won’t boot if our external HDD is disconnected somehow.
dump 1 means the filesystem will be backed up by dump if used
fsck 2 means the system will be checked after root partitions 1
After you have finished editing you can mount your updated fstab file using mount -a
3. Download the deb file manually
Sadly, the package repository doesn’t seem to function for raspberry pi 4 (most likely because it’s still supplying stretch binaries instead of buster) however you are still able to download the image and install the application manually.
Go to https://packages.gitlab.com/gitlab/raspberry-pi2 and download the latest version (or the version you require). It does say raspberry-pi2 but it works fine for pi4.
For me, this was the following:
1 |
wget https://packages.gitlab.com/gitlab/raspberry-pi2/packages/raspbian/buster/gitlab-ce_13.5.3-ce.0_armhf.deb |
4. (Optional) Configure Swap memory
My raspberry pi 4 has 4gb of ram and GitLab recommends 8gb minimum. If you are using the 8gb model you can most likely skip this step.
There is a way to use disk space as memory called Swap. To do this, we edit the file /etc/dphys-swapfile
. For me I mounted a 16gb partition (although I’m only using 4gb currently) to /var/swap/
and set the swap file to be /var/swap/swap
https://nebl.io/neblio-university/enabling-increasing-raspberry-pi-swap/
-
1sudo dphys-swapfile swapoff
- As
root
, edit the file/etc/dphys-swapfile
and modify the variableCONF_SWAPSIZE
to 1024:
1CONF_SWAPSIZE=4096
1sudo nano /etc/dphys-swapfile -
1sudo dphys-swapfile setup
-
1sudo dphys-swapfile swapon
- Reboot
If you aren’t using an HDD (unlike me) you can also enable ZRAM swap which will increase performance when using an sd card https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/4105
5. (Optional) Setup your google SMTP Relay
If you are using GSuite like myself, you need to first set up your SMTP-Relay settings in your GSuite admin settings. I set it up like the following below:
1 2 3 4 5 |
SMTP Relay Allowed senders: Only addresses in my domains Only accept mail from the specified IP addresses: No Require SMTP Authentication: Yes Require TLS encryption: Yes |
Only addresses in my domains
means that you can send using an account like gitlab@jflynn.xyz
even though you don’t have a GSuite account with that email (saves paying for new email accounts that aren’t going to be used by people). If you use any of the other options for this make sure to change your gitlab_email_from
to match.
Note: You will get an EOF error if these don’t match up correctly (say, you use an email at gitlab.example.com
which is not apart of your domain.)
6. Configure GitLab
There are a few things to change in the file/etc/gitlab/gitlab.rb
-
- Change the
external_url
to your raspberry pi IP. You can use this one-liner to find it:ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'
For me, I use an Asus Merlin router so wanted to set a nice hostname. You can do that on most routers by setting up a dnsmasq like this https://github.com/RMerl/asuswrt-merlin.ng/wiki/Custom-domains-with-dnsmasq so for mine I’m usinghttp://gitlab.jflynn.xyz
. You can also do this by editing your client hosts file for each pc/mobile you want to access GitLab from.
Note: if you want to do HTTPS then you will need a CAA and setup Let’s Encrypt https://docs.gitlab.com/omnibus/settings/ssl.html#lets-encrypthttpsletsencryptorg-integration. Since I’m doing it on my LAN I’m not too bothered. - As mentioned here https://docs.gitlab.com/omnibus/settings/rpi.html we want to reduce the number of running processes to make the system run a bit smoother:
12345# Reduce the number of running workers to the minimum in order to reduce memory usagepuma['worker_processes'] = 2sidekiq['concurrency'] = 9# Turn off monitoring to reduce idle cpu and disk usageprometheus_monitoring['enable'] = false - (Optional) Configure the SMTP settings in GitLab
123456789101112gitlab_rails['gitlab_email_from'] = 'gitlab@jflynn.xyz'gitlab_rails['gitlab_email_reply_to'] = 'noreply@jflynn.xyz'gitlab_rails['smtp_enable'] = truegitlab_rails['smtp_address'] = "smtp-relay.gmail.com"gitlab_rails['smtp_port'] = 587gitlab_rails['smtp_user_name'] = "<USER>"gitlab_rails['smtp_password'] = "<PASS>"gitlab_rails['smtp_domain'] = "jflynn.xyz"gitlab_rails['smtp_authentication'] = "login"gitlab_rails['smtp_enable_starttls_auto'] = truegitlab_rails['smtp_tls'] = falsesmtp_tls
is set to false as this is only used on port 465 where connections start encrypted over TLS. You can read more at https://docs.gitlab.com/omnibus/settings/smtp.html#troubleshooting-ssltls
- Change the
7. Run the reconfigure
gitlab-ctl reconfigure
Now you can head over to your ip address (the one set in external_url
that we configured) and set up the root account.
That’s it!
If you have any questions feel free to post a comment or just drop me an email and I will get back to you.