UPDATE 2020 After using GitLab on the Pi 3 for a while it became obvious to me that it’s just not cut out for the task. I discovered Gitea, which is very similar in functionality to GitLab, but is written in Go, runs really well on a Raspberry Pi, and is far easier to install and configure. I’ve left this post up for historical reasons (plus the advice about booting from hard disk still stands) but if you want to run a Git server on a Raspberry Pi, I highly recommend using Gitea, and not GitLab.
Original post follows…
I recently got GitLab running on a Raspberry Pi 3. It’s something I’ve been meaning to try for a while and, although there are numerous guides online, none of them seemed to work, hence why I’m documenting my experiences here. GitLab is a code management environment based around git. It can host repositories, yes, but you can also create groups for your repos, create tasks based on them, assign them to users, etc etc. If you’re a “proper” developer, it’s got lots of really good tools.
Booting from Hard Disk
This is actually quite important in the long term. An SD card is not the best choice for hosting a linux filesystem like Raspbian uses, and this becomes particularly important one you start pushing to it regularly. Hard drives are also considerably bigger in terms of data storage.
If you’re using a Pi 3B+, you can simply use dd or similar to write the latest version of Raspbian to a USB hard drive, rather than an SD card, plug it into the Pi and turn it on. If you’re using a normal 3B, you need to enable a one-time setting first, before this can happen. Take an SD card (not necessarily a brand new one, you’ll only be using it once) and copy a Raspbian image to it. Then, with the SD card in a PC or another Pi, modify the file /boot/config.txt. Add the following line to the end of this file:
program_usb_boot_mode=1
Save, and eject the card. Now put the card into the Pi, plug it in, and wait for it to boot. Now you can turn off and remove the card and continue with the above instructions as if you’re using a 3B+.
Config.txt is quite picky. Specifically, make sure there’s no blank line at the end of the file if you want to do this. To be extra certain, rather than using Nano or Vi, use this command to add the required text to the end of the file:
echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
Configure the Swap File
Ideally you’ll need quite a lot of swap space, because GitLab is a bit of a RAM hog. To do this, open the file /etc/dphys-swapfile and uncomment and modify the line CONF_SWAPSIZE to read as follows:
CONF_SWAPSIZE=4000
This will give you 4GB of swap, which is what GitLab requires.
Install Dependencies
Not a massive problem, all can be added using apt-get with the following command:
sudo apt-get install curl openssh-server ca-certificates apt-transport-https postfix
Install the Package
I’ve not found a repository that contains an up-to-date version of GitLab compiled for the ARM architecture that the Raspberry Pi uses. So the best thing to do is download a package file manually, and install it using dpkg:
wget --content-disposition https://packages.gitlab.com/gitlab/raspberry-pi2/packages/raspbian/stretch/gitlab-ce_12.4.5-ce.0_armhf.deb/download.deb
sudo dpkg -i gitlab-ce_12.4.5-ce.0_armhf.deb
Configuration
The main configuration at this point is in the file /etc/gitlab/gitlab.rb. The main thing in here to note is the external_url setting, which is what you type into a browser in order to access the Gitlab instance. It’s basically the Pi’s host name.
Once you’ve modified the file, run the following:
sudo gitlab-ctl reconfigure
The first time you run this, it’ll probably take a while. And you may need to re-run it straight afterwards, depending on what happens. But eventually all will be fine.
Reduce Processes
This is optional, but to improve performance on the Raspberry Pi, it’s a good idea to make a couple more changes to /etc/gitlab/gitlab.rb. Find the following lines in the file and modify/uncomment them as necessary:
unicorn['worker_processes'] = 2
sidekiq['concurrency'] = 9
prometheus_monitoring['enable'] = false
These will turn off monitoring in order to conserve idle CPU, and reduce the number of running processes to the minimum so as not to overload the Pi.
That should be enough to get you up and running. Try connecting to the Pi from a web browser, creating an account and creating and checking out some git repos. Just bear in mind that you will find some performance issues. The only reason I’ve not yet tried this on a Pi 4 is because at present I don’t know how to make a Pi 4 boot from a hard drive. But I’m sure I’ll update this article once I figure it out.