Okay -- GitLab isn't really your own self-hosted GitHub. I don't believe GitLab or GitHub share any relationship besides both being Git Management Software, but it's the best way I find to describe in laymen terms what GitLab is. GitLab is awesome. It's featured packed, and it does nearly everything that Github does. Best of all, you get unlimited private repos with it (or techincally as many as your server can handle).
I have some pretty good DevOps skills, but I'm not really a server guy. Until recently, I've never previously wanted to deal with the hassle of setting up my own Git server, and GitHub's managed solution is really quite appealing. With GitHub, you have a reliable and easy solution that you never really have to worry about. It's also very nicely integrated with a huge array of social features like forking and organizations amongst other collaboration tools. The only thing is it can get expensive real fast if you need more than a handful of private repositories.
Digital Ocean has recently made it very simple and straight forward to setup Gitlab with minimal effort and fully supporting one-click restorable backups. They also even provide great resources and tutorials on it:
Table of Contents
- How to set up GitLab as your very own private Github clone
- How To Use the GitLab One-Click Install Image to Manage Git Repositories
This post will be very similar to those articles, but I'll be going through step-by-step in more detail as well as some improvements and notes of my own. Feel free to read below or go straight to the Digital Ocean docs themselves.
Sign up with Digital Ocean
The first thing you'll need to do is signup with Digital Ocean.
Setup Public SSH Keys
Digital Ocean automatically will provision your server with the public keys you upload to your account. This step isn't really required, but it makes it easier and faster to access your new server environment.
Create Your Droplet
If you don't know much about servers - don't worry. Digital Ocean will make this very easy for us, and they'll actually "automatically" do most of the work for us.
Select your Hostname
For this, use the domain (or subdomain) that you would like to use. For example, you could do
Select the server size
The official recommendation for GitLab can be found here. In summary, your server should have:
- 2 cores of CPU power
- 2 GB RAM
However, I've found that GitLab still works well even if you don't meet these requirements. If you select the smallest Droplet, GitLab will occasionally freeze or hang. This is usually fixed with a quick reboot of the server. I recommend the smallest Droplet you select is their $10/month plan. I have found no problems yet running this with a small team for both work and play.
Select a region
Select the region that you would like your server to be in. You should select a region that is closest to you to reduce latency.
Select an image
The next step is to select the GitLab application image provided by Digital Ocean. Selecting this basically means that GitLab will automatically be installed when the server is provisioned.
Select the SSH Key
Select the Public SSH Key you added from earlier. This will allow you to SSH into the server without needing a password. Selecting this also means that Digital Ocean won't send you a root password when the Droplet is created.
The last step is to enable backups. Even though Git is a distributed version control system, I still would enable this so that you can easily recover your Git repos if anything unexpected happens.
Configure the Server
Access the Droplet
Now that we have created our Droplet and before we do anything, lets SSH in and make some minor setting changes. To get the IP address of your Droplet, just navigate to your Droplets in the Digital Ocean backend. After you find it, open the terminal and connect with it via SSH (no password will be required since we are using public and private keys):
Update the Hosts File
This helps remove warnings when rebooting GitLab. We're going to add the hostname of your Droplet to the hosts file. To do this, open
/etc/hosts with your favorite editor:
Then, add your IP address, a tab, and the hostname on line 2 of that file:
Setup URLs and Emails
We'll need to set some default settings and globals for GitLab. These are things like the base URL and default support email. Open the /home/git/gitlab-shell/config.yml and update the variable
After that, we'll need to update one last file. Open up /home/git/gitlab/config/gitlab.yml in your editor:
You can go through this file and make adjustments to customize your installation. Most of these are just default settings. For the most part you should leave it as is, but you'll need to change
host under GitLab settings to your domain name.
Then, you need to set the default From and Admin emails:
email_from: firstname.lastname@example.org support_email: email@example.com
To finalize everything, reboot GitLab with the following command:
service gitlab restart
Point the A Record
The final step is to now point the A record of either the domain or subdomain to your Digital Ocean IP address. I use CloudFlare to manage my domains, but your setup should look very similar to the below screenshot:
Access Your New Git Server!
If everything worked out correctly and DNS propagated, you can now visit the URL in your browser to access your new git server!
You also can now SSH into your Droplet with the following command:
<div class="tile"> <div class="tile-content"> <h2> Default Login </h2> <p> Now that you have successfully navigated to your URL, you'll need to login. The default login for this image is: </p> <pre>
<div class="alert alert-warning"> You probably noticed this already when you were SSHing into the server. This appears in the welcome message. </div> <p> After you login, you'll be prompt to change the password, then you'll need to login again with the same email and the new password. Once you have logged in successfully, you'll need to change the default Admin email to your email address. To do this, navigate to the Admin Panel located here: </p> <p> <code>/admin/users/root/edit</code> </p> <p> Next, we'll need to update the default username (which is currently <strong>root</strong>). To do this, navigate to: </p> <code>/profile/account</code> After you make that change, you are all set on configuring the server! </div> </div> <div class="tile"> <div class="tile-content"> <h2> Next Steps </h2> <p> GitLab has a whole bunch of cool features. I won't go over everything in detail because a lot of it is self-explanatory, but some of the things you should consider playing around with once logged in are: </p> <ul> <li> Adding Public Keys </li> <li> Creating Groups and Teams </li> <li> Customizing Themes </li> <li> Your own GitLab API </li> <li> Webhooks </li> </ul> </div> </div> <div class="tile"> <div class="tile-content"> <h2> Debugging, Troubleshooting, and Backups </h2> <p> If GitLab ever hangs or freezes on you, you can try rebooting it with: </p> <pre>
service gitlab restart
<p> If that doesn't work, you can reboot your entire Droplet through the command line with: </p> <pre>
shutdown -h now
<p> or </p> <pre>
<p> When you do a power cycle from the command line like this, Digital Ocean will take a snapshot of your Server in case you need to safely restore. If that doesn't work, you can just login to your Digital Ocean account and reboot the Droplet through their backend. </p> <p> If you ever need to restore from a backup, all you have to do is log into the backend of Digital Ocean, select your Droplet, and click <i>Restore from Backup</i>. </p> <img src="https://cask.scotch.io/2014/03/Screen-Shot-2014-03-18-at-12.24.14-AM.png" alt="Screen Shot 2014-03-18 at 12.24.14 AM" class="alignnone size-full wp-image-2212 img-thumbnail" style="border: none;" /> </div> </div> <div class="tile"> <div class="tile-content"> <h2> Conclusion </h2> <p> That's all there is to getting your own little private Git server. GitLab is an amazing tool, and the awesome guys over at Digital Ocean have made it really straight forward to set one up with backups, hardened security, "unlimied" privated repos, and more. </p> <p> I'm a huge fan of Digital Ocean and their services, and I highly recommend that you use them. GitHub is really worth every penny, but if you're in need of a ton of private repos on a tight budget, GitLab might be the best solution for you. Some other ways you could inexpensively manage your Git repos online are: </p> <ul> <li> <a href="http://bitbucket.com">BitBucket</a> </li> <li> <a href="https://education.github.com/">GitHub Education</a> </li> </ul> </div> </div>