GitLab Self-host for Maker
2024-08-16 | By Tobias Bruckmann
Motivation
When working on projects, I always found it quite difficult to keep all the project files together, and versioning was something I only allowed myself to dream of from time to time. Especially when working on a project across different devices or at different locations, my default solution became a USB-Flash drive, which was neither secure nor comfortable. So, if you are also struggling with the same problems, this tutorial might be for you because after a friend of mine introduced me to the world of server infrastructure, I now call a new versioning system my own: GitLab.
Prerequisites
To follow along with this tutorial, you will need:
- A Server: Don't worry, it does not have to be a DELL or HP Rack server, an old notebook will most likely do the job. Or if you are a student or otherwise get access to a service like Microsoft Azure or AWS, a virtual server works too.
- A domain (optional): If you want to access your new version control system from outside your network, you will need to get a domain (or use your static IP if you are lucky enough to have one). Domains are inexpensive these days, and together with a dynamic DNS system that keeps your domain pointing to your IP and a bit of settings done on your router it allows you to host your system publicly.
--DISCLAIMER--
Publicly hosting anything comes with risks associated with it. Be sure to be aware of and fully understand and accept these risks before attempting to host anything publicly. Because of these risks, this post will only describe how to host the system locally. To expose it globally, feel free to use the abundant guides out there on how to do it right.
Getting Started
Now that you have your server (physical or virtual) we will go ahead and install Alpine Linux onto it. Alpine is a really compact and secure Linux distribution, and therefore the perfect fit for this project. To install it, you may head to the alpine Linux wiki for a thorough overview of all options, but I will lay out the necessary steps for our purpose here too.
- Download the Alpine ISO from their website: I was going to use the STANDARD x86 version because it fit an ancient laptop I have lying around. But, as I painfully realized after a few hours, GitLab doesn't work with that architecture, and so I am using the x86_64 STANDARD version that should fit most modern and semi-modern PCs. Feel free to try out other Alpine versions too if you like to tinker around, but expect errors ;)
- Prepare your installation medium: For a physical PC, this involves downloading RUFUS at rufus.ie and "burning" the ISO to a USB-Flash drive using the following settings:
- Device: Select the USB-Flash drive (Attention! Be sure to select the right drive and save all data on it as it will be totally formatted)
- Boot selection: Disk or ISO image
- Click select and find the downloaded ISO file
- Persistent partition size: 0 (No persistence)
- Partition scheme: MBR
- Target System: BIOS or UEFI
- Volume label: Leave as is
- File System: FAT32
- Cluster Size: Default
- Click START and select "Write in ISO image mode" if asked. Accept the warning that the device will be formatted if you are sure there is no valuable data on it anymore, and you selected the right device.
- Wait till Rufus is done.
If you fancy the old-school version, you can also burn the image to an Optical Drive and boot your system from that, although I would not recommend this. For virtual servers, the process differs depending on the provider, but it usually involves uploading the ISO and mounting it as a virtual drive to boot from.
Install Alpine
- Boot your installation Medium: Once your virtual or real boot medium is prepared, insert or mount it to the system and boot to it. With most computers and virtual servers, this typically involves finding the right F-Key for a single-time boot menu or changing the boot order in the bios. If you are unsure how to do it for your system, do some online research using the keywords "one-time-boot menu" or "boot order" and "BIOS".
- Installing Alpine: If the computer succeeds in booting from your medium, you will be greeted with a text-based login. Use root as login username and no password to access the system. Then run the "setup-alpine" command. You are now being presented with a text-based setup utility.
- Select keyboard layout: Select your layout (if unsure, google)
- Hostname: Nothing, just press enter
- Network interfaces: Select the one you want to use (most likely eth0 or wlan0 for laptops, although Ethernet is recommended)
- Make sure the network cable is plugged in for the next steps.
- IP address: Select DHCP for now
- If asked about another interface, just type "done"
- Manual network configuration: type "n" and enter
- New password: Type in a password of your choosing and retype it
- Timezone: Select your time zone
- Proxy: Just hit enter
- NTP client: Just hit enter
- Enter mirror number or URL: type "f" and hit enter
- Set up a user? Just hit enter
- Which ssh server? Type "none" and hit enter
- Disks to use for install: Select the system disk you want to install Alpine to (most likely sda)
- How to use the disk? Type "sys" and hit enter
- Erase disk? Type "y" and enter.
- The installation is done!
- Type "poweroff" and hit enter. Remove the installation medium and start the device again.
- The same text login screen should appear.
- You can now use root and your previously defined password to log in.
Installing docker
Now that the server OS is up and running, we need to install docker onto it to host GitLab. To do so, you can go to this Alpine wiki article or follow these steps:
- Run "apk add nano"
- Run "nano /etc/apk/repositories"
- Remove the # in front of the community repository line
- Hit Ctrl+S to save and Ctrl+X to exit
- Run "apk add docker"
- Run "addgroup root docker"
- Run "rc-update add docker default"
- Run "service docker start".
Now, docker is installed and will start automatically once the server is running.
IP Setup
To reliably access GitLab once we install it, we need to configure a static IP address for our server. For that, we type "ifconfig" and hit enter. In the eth0 or wlan0 (not recommended) line, we will find an "inet addr". This will look something like "192.168.X.YYY". In my case, 192.168.7.137. Now we type "nano /etc/network/interfaces" and hit enter. In this file, I will replace the line "iface eth0 inet dhcp" with these settings:
iface eth0 inet static address 192.168.7.150 netmask 255.255.255.0 gateway 192.168.7.1
For your configuration, make sure to keep the X number exactly the same (in my case, the 7) and choose a free IP for the YYY number. If in doubt, just use the same IP address that you got when running ifconfig. The template for your configuration would be:
iface eth0 inet static address 192.168.X.YYY netmask 255.255.255.0 gateway 192.168.X.1
Once complete, press Ctrl+S and Ctrl+X, type "reboot" and press enter.
Install GitLab
After logging into the system again, you can start the GitLab installation as described in their documentation or along these steps:
- Run "apk add docker-compose"
- Run "mkdir /docker"
- Run "cd /docker"
- Run "mkdir gitlab"
- Run "cd gitlab"
- Run "nano docker-compose.yml"
- Copy these lines and fill in your IP and a suitable password:
services: gitlab: image: gitlab/gitlab-ce:latest restart: always hostname: '192.168.X.YYY' environment: GITLAB_OMNIBUS_CONFIG: external_url 'http://192.168.X.YYY' GITLAB_ROOT_PASSWORD: '--please fill--' container_name: gitlab-ce volumes: - './config:/etc/gitlab' - './logs:/var/log/gitlab' - './data:/var/opt/gitlab' ports: - '80:80' - '22:22' - '443:443'
8. Run "docker-compose up -d"
Now, all the necessary files for the GitLab container are pulled, and the container boots up. This might take quite a while. After the container starts, you can try to reach it under the defined IP address. Once the login screen appears, enter root as user and use the password you set to log in. You did it. You are now the proud owner of a local GitLab server. Try it out by creating your first project and pulling it with a git client or by configuring the installed system further. Also, feel free to adapt this tutorial to your needs and enjoy your new version control system.
![TechForum](http://www.digikey.com/-/media/Images/Footer/TechForum2.png?la=en&ts=9efa75a7-28fd-48d1-bcf2-3300f3edfa4e)
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum