Introduction
Git is a popular version control system used widely in the community. Git takes snapshots of your project in time and stores them in logical units called repositories. These repositories allow you to perform actions such as branch a project, merge a working branch, and revert back to a previous committed change. This allows for efficient non-linear and collaborative development.
When stored remotely, git repositories act as a backup store for your projects. There exist many free and subscription-based remote git repositories that usually offer a web GUI to allow you to manage git users and projects. When your needs outnumber the services supported by third-party providers you will have to consider self-hosted git services. GitLab Community Edition (CE) is an open source project that offers Git repository management, code reviews, issue tracking, activity feeds and wikis. It comes bundled with GitLab CI for continuous integration. Stack Harbor has made the process of building your own git server even easier by offering a turnkey GitLab stack you can deploy with minimal configuration.
Configuring Domain Names & Email
You’ll likely want people to access the web GUI and push code using your domain name and not your IP address. In order to get this working, you have to configure nginx and GitLab with your domain name. We’ll be using the command line based text editor ‘nano’ throughout the tutorial.
First we’ll edit our nginx configuration to change the server name. SSH into your remote machine and run the following command
sudo nano /etc/nginx/sites-available/gitlab
Locate the line that contains the “server_name” directive. By default, we’ve set this to be the IP address of your Stack. Change this to your domain name and press CTRL-O, return, and CTRL-X to save and exit. The changes will not take effect until you’ve restarted nginx, so run the following command.
sudo nginx -t
This tells nginx to check to see if the configuration file is valid before you restart your server. This is always recommended as restarting the nginx server with an invalid configuration file could result in some downtime for your site. Now to restart the server:
sudo service nginx restart
We need to take similar steps to configure the GitLab application with our domain name and additionally configure it to send administrative emails. GitLab needs this information to generate valid links in the web GUI so that you’re redirected to the right parts of the website. Open up the GitLab configuration file located at /home/git/gitlab/config
sudo nano /home/git/gitlab/config/config.yml
Near the top of this configuration file, locate the line that has “host” followed by your IP address. In the same manner as above, change the IP address to reflect your domain name. Now scroll down until you see three lines that read “email_from,” “email_display_name,” and “email_reply_to.” Commented above these lines is a short description of each. In order to create users and allow GitLab to send users emails regarding their password and other administrative details, you need to add a valid email to send mail from and optionally an email to receive replies. Set these parameters and save & quit the file (CTRL-O, return, CTRL-X). Once again, you’ll need to restart the GitLab application to persist the changes.
sudo service gitlab restart
Final Words
That’s it — you’re done! Point your browser to your newly configured domain name and you should be prompted with the GitLab login screen. Use the credentials shown to you when you SSH into your Stack to log into the Web interface. From here on, you can add SSH keys, create users, create projects, and begin pushing code. For more information regarding GitLab, check our their documentation. From us at Stack Harbor, ahoy!