Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Gitlab Cookbook

You're reading from   Gitlab Cookbook Over 60 hands-on recipes to efficiently self-host your own Git repository using GitLab

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher
ISBN-13 9781783986842
Length 172 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Jeroen van Baarsen Jeroen van Baarsen
Author Profile Icon Jeroen van Baarsen
Jeroen van Baarsen
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Introduction and Installation 2. Explaining Git FREE CHAPTER 3. Managing Users, Groups, and Permissions 4. Issue Tracker and Wiki 5. Maintaining Your GitLab Instance 6. Webhooks, External Services, and the API 7. Using LDAP and OmniAuth Providers 8. GitLab CI A. Tips and Tricks Index

Installing GitLab from source

In this recipe, I will help you install GitLab from source. Installing from source means that we will take the source code from gitlab.com and use that to code in order to install it on our server.

At the time of writing, 7.4 is the latest version. If you want to be sure that you have the latest version, please check https://gitlab.com/gitlab-org/gitlab-ce/blob/master/VERSION.

If you want the latest bleeding edge version, you can change 7.4 to master in this recipe.

Getting ready

To install GitLab on your own server, you need to have a few things installed already. Here is a list of prerequisites:

  • A server running Debian or Ubuntu; preferably one of the latest versions, and running as 64-bit
  • Git Version 1.7 or higher
  • A text editor; in the examples, I'll be using Vim
  • Sudo; on Debian this is not installed by default
  • A working mail server
  • You have to set up the database
  • You have to install all the server dependencies

How to do it…

Follow these steps to install GitLab from source:

  1. Download the source code:
    $ cd /home/git
    $ sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-9-stable gitlab
    
  2. In config/gitlab.yml, we need to change the host to the fully-qualified domain name of your GitLab instance. Also change the email_from to the e-mail address you want to use as a from address for all the e-mails that are sent by GitLab:
    $ cd /home/git/gitlab
    $ sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
    $ sudo -u git -H editor config/gitlab.yml
    
  3. Make sure that GitLab can write to the necessary folders using the following command lines:
    $ sudo chown -R git log/ 
    $ sudo chown -R git tmp/ 
    $ sudo chmod -R u+rwX log/ 
    $ sudo chmod -R u+rwX tmp/
    $ sudo chmod -R u+rwX tmp/pids/ 
    $ sudo chmod -R u+rwX tmp/sockets/
    $ sudo chmod -R u+rwX  public/uploads
    
  4. Create the directory for the GitLab satellites:
    $ sudo -u git -H mkdir /home/git/gitlab-satellites 
    $ sudo chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites
    
  5. Copy the Unicorn config file:
    $ sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
    
  6. Copy the Rack attack config file:
    $ sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
    
  7. Copy the init script and make GitLab start on boot:
    $ sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
    $ sudo update-rc.d gitlab defaults 21
    
  8. Set up Logrotate:
    $ sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
    
  9. Set up the Git user. This helps when editing files via the GitLab web interface. Make sure that the user.email is the same as the e-mail address you entered in step 8:
    $ sudo -u git -H git config --global user.name "GitLab" 
    $ sudo -u git -H git config --global user.email "example@example.com" 
    $ sudo -u git -H git config --global core.autocrlf input
    
  10. Configure your GitLab database:
    $ sudo -u git -H cp config/database.yml.postgresql config/database.yml
    
  11. Make sure that the database.yml file is only readable for the git user:
    $ sudo -u git -H chmod o-rwx config/database.yml
    
  12. Install the GitLab dependencies:
    $ sudo -u git -H bundle install --deployment --without development test mysql aws
    
  13. Install the GitLab shell:
    $ sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.4] REDIS_URL=redis://localhost:6379 RAILS_ENV=production
    
  14. Initialize the database:
    $ sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production force=yes
    
  15. Compile all the assets:
    $ sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
    
  16. Start your GitLab instance:
    $ sudo /etc/init.d/gitlab restart
    

How it works…

We have just installed GitLab on our server. We have done this by downloading the source code from gitlab.com and performing the preceding steps.

Let's take a look at what we did in every step.

In step 1, we downloaded the source code for GitLab. We haven't done anything with it yet, just downloaded it.

In step 2, we done the basic configuration of GitLab. We have changed the hostname to the fully-qualified domain name you want to access your GitLab on, for example, gitlab.example.com. Also, we have configured the e-mail addresses that GitLab will send mails from. The email_from will be used as the from address of all the e-mails that are sent via GitLab.

Next was the setup for the satellite directory. Satellites are used when you create a merge request, and GitLab has to check whether it is mergeable, and perform the actual merge. A satellite is just checking out of the repository that GitLab has access to.

We then went on to copy some files. The first file was the Unicorn configuration file. Unicorn was used as the application server and we copied the Rack Attack files. Rack Attack is used in order to prevent abusive requests to your GitLab server. One way to make sure that no harmful requests make it to your server is by request throttling. This means that we only allow 10 requests per 60 seconds to certain URLs.

The next important step is the configuration of the database. As we are using PostgreSQL on the same machine, the configuration is really straightforward: just copy the right database.yml file and we are done, well almost; we also need to protect our database.yml file so that it's only readable for the Git user.

The dependency installation is done via Bundler. Bundler is the package manager for Ruby. We have passed the flags --deployment and --without development test mysql aws. The first flag is passed to make sure that the dependencies are installed in the context of GitLab and not in a system-wide context. The second flag is passed to make sure that only the necessary dependencies are installed. If you want to learn more about Bundler, take a look at www.bundler.io.

GitLab has its own Git wrapper to perform Git commands on the server. This wrapper is called GitLab Shell. In step 11, we tell GitLab to fetch the code for GitLab Shell and install it.

In step 12, we set up the database. We create the database and load the database schema. We also create the first user, so that you can log in to your server.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime