As software developers and devops engineers one of the most important tools in your continuous integration and deployment workflow is the source control management (SCM) system. SCM's have a long and storied history, there is a great overview covering 1972-2010 here (codicesoftware.blogspot.com). My favorite graphic from this article shows a timeline of SCM systems overlayed on the current state-of-the-art cell phone technology:
A short history of Git
From the website git-scm.com: As with many great things in life, Git began with a bit of creative destruction and fiery controversy. The Linux kernel is an open source software project of fairly large scope. For most of the lifetime of the Linux kernel maintenance (1991–2002), changes to the software were passed around as patches and archived files. In 2002, the Linux kernel project began using a proprietary DVCS system called BitKeeper.
In 2005, the relationship between the community that developed the Linux kernel and the commercial company that developed BitKeeper broke down, and the tool’s free-of-charge status was revoked. This prompted the Linux development community (and in particular Linus Torvalds, the creator of Linux) to develop their own tool based on some of the lessons they learned while using BitKeeper. Some of the goals of the new system were as follows:
- Simple design
- Strong support for non-linear development (thousands of parallel branches)
- Fully distributed
- Able to handle large projects like the Linux kernel efficiently (speed and data size)
Since its birth in 2005, Git has evolved and matured to be easy to use and yet retain these initial qualities. It’s incredibly fast, it’s very efficient with large projects, and it has an incredible branching system for non-linear development. With the popularity of Git within the open source development community arose a hosted service to store repositories and encourage collaborative development, this is the popular site GitHub. Seeing a need for a similar solution that could be hosted within a company's firewall GitLab was created, and is available as an open source Community Edition as well as a commercially supported product.
GitLab Community Edition Features
A high level view of the features of the GitLab Community Edition server:
- Completely free and open source (MIT license)
- Unlimited users, collaborators and repositories
- Keep your code secure on your own server
- Manage repositories, users and access permissions
- Perform code reviews with merge requests
- Extended permission system with 5 access levels and branch protection
- Efficient user management by creating groups of projects and teams of users
- Use the ticketing system included in GitLab or integrate your existing system
- Each project has a wiki backed up by a separate git repository
Installing GitLab on the CenturyLink Cloud
We are going to install a complete GitLab CE server on the CenturyLink Cloud. It will be based on Ubuntu 14.04 (Trusty) and Ruby 2.1.2. To get started, build a CenturyLink Cloud server and bring it up to date by installing Ubuntu Trusty. You should now have a running Trust server and be logged in as root.
Installing the GitLab CE Server Dependencies
We will now install the dependencies:
$ apt-get update $ apt-get install cmake $ sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev && \ libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server && \ redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev && \ libicu-dev logrotate python-docutils libsqlite3-dev sqlite3 && \ python-software-properties
Now, we need to install git and ensure it it the correct version:
$ apt-get install -y git-core # Check to see that the version of git is 1.7.10 or higher $ git --version
An important aspect of a distributed SCM is to be able to send email notifications. Since Ubuntu doesn't have a default mailer, let's install postfix:
$ sudo apt-get install -y postfix
When asked, select Internet Site and hit enter to select the default server name.
Install Ruby 2.1.2
GitLab CE assumes that you have version 2.1.2 of Ruby installed. By default the Ruby version in Trusty is 1.9.3, so we will first remove the older version and then install the correct version of Ruby.
$ sudo apt-get remove ruby1.9
Get Ruby, compile and install it:
$ mkdir /tmp/ruby && cd /tmp/ruby $ curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz | tar xz $ cd ruby-2.1.2 $ ./configure --disable-install-doc $ make $ sudo make install
And, install the Bundler gem:
$ gem install bundler --no-ri --no-rdoc
Finalize system database
The last thing we need to do before actually installing the GitLab server is to install and configure the database the system will use. It is recommended that PostgreSQL be use, and that is what we will install. First, create a user git for use with GitLab:
$ sudo adduser --disabled-login --gecos 'GitLab' git
Next, we are going to install PostgreSQL to the latest version (as of right now it is version 9.3):
$ sudo apt-get install -y postgresql postgresql-client libpq-dev # Login to PostgreSQL $ sudo -u postgres psql -d template1 # Create a user for GitLab template1=# CREATE USER git CREATEDB; # Create the GitLab production database & grant all privileges template1=# CREATE DATABASE gitlabhq_production OWNER git; # Quit the database session template1=# q # Try connecting to the new database with the new user $ sudo -u git -H psql -d gitlabhq_production
Install the GitLab CE System
We will be installing into the home directory of the user git
$ cd /home/git $ sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-1-stable gitlab $ cd /home/git/gitlab
Now we need to configure the system. Copy the example GitLab config, then we will edit it for our purposes.
$ sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
Edit the config/gitlab.yml file and change references to "localhost" to the public IP assigned to your server. Additionally, there are several permissions related and example installations that need to be done:
$ sudo chown -R git log/ $ sudo chown -R git tmp/ $ sudo chmod -R u+rwX log/ $ sudo chmod -R u+rwX tmp/ $ sudo -u git -H mkdir /home/git/gitlab-satellites $ sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites $ sudo chmod -R u+rwX tmp/pids/ $ sudo chmod -R u+rwX tmp/sockets/ $ sudo chmod -R u+rwX public/uploads $ sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb $ sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
# Configure Git global settings for git user, useful when editing via web # Edit user.email according to what is set in gitlab.yml $ sudo -u git -H git config --global user.name "GitLab" $ sudo -u git -H git config --global user.email "email@example.com" $ sudo -u git -H git config --global core.autocrlf input
Since we have chosen to use the PostgreSQL database, let's copy over the example config file and then edit it. Note that the database user on the production database should be git with no password (this should be the default).
$ sudo -u git cp config/database.yml.postgresql config/database.yml # Make config/database.yml readable to git only $ sudo -u git -H chmod o-rwx config/database.yml
Install the required gems:
$ sudo -u git -H bundle install --deployment --without development test mysql aws
GitLab shell is an SSH access and repository management software developed specially for GitLab. To install run the following:
$ sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.6] REDIS_URL=redis://localhost:6379 RAILS_ENV=production
We now have just a few housekeeping items to complete before GitLab is installed and we can validate that it is running correctly.
# Initialize the database (answer 'yes' to continue) $ sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production # Install the Init scripts $ sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab # Make GitLab start on boot $ sudo update-rc.d gitlab defaults 21 # Set up logrotate $ sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
In order to check if GitLab and all of its environments are set up correctly:
$ sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
You should see system information from System Information (OS, Ruby, etc.), GitLab Information, and GitLab Shell Information.
Finally, we will compile all of the application assets and start an instance of GitLab.
$ sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production $ sudo /etc/init.d/gitlab start
You should see a response that looks like this:
Congratulations, you now have GitLab CE edition up and running on the CenturyLink Cloud. However, in order to complete the install we have one last task to accomplish. Nginx is the officially supported web server for GitLab so let's install and configure it. To install:
$ sudo apt-get install -y nginx
And to configure:
$ sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab $ sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab # Again, edit the config file and change "YOUR_SERVER_FQDN" to the **private** IP of your server. Also, change the '*' on the "listen" to the private IP as well # Restart Nginx $ sudo service nginx restart
At this point the entire system should be installed and running, to double check:
$ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
All the items should be green. If so, you have successfully installed the Community Edition of GitLab on the CenturyLink Cloud. Point your browser at the public IP of the server and you should see the login screen:
Login with user: root and password: 5iveL!fe and have fun exploring GitLab!