Published : 2013-12-08

Gitlab 6 on FreeBSD

Gitlab is a powerful tool to build a github-style infrastructure on your own premises. Gitlab can hook into a corporate LDAP directory so users are recognized automatically. In terms of features, Gitlab lets you create git repositories, fork, create branches, commit over HTTP(S), and share projects between users. This article explains how to install Gitlab on a FreeBSD server.

Prerequisites

To use Gitlab, install the following packages:

pkg install git icu libxml2 libxslt postfix python27 logrotate py27-docutils rubygem-bundler rubygem-passenger sudo gmake rubygem-rake

Databases

Gitlab needs two databases: a Redis database and a MySQL/PostgreSQL database. We will use an existing PostgreSQL 9.2 here. You can install PostgreSQL and Redis on the server, but we will point at an external server.

Installing and Configuring Redis

Install the Redis package, enable the service, and start it:

pkg install redis
echo "redis_enable=\"yes\"" > /etc/rc.conf
service redis start

Creating the PostgreSQL Database and User

Assuming PostgreSQL is already running, add a database and a user:

su - pgsql
createdb gitlab
psql gitlab
CREATE USER gitlab WITH PASSWORD 'dbpwd';
GRANT ALL PRIVILEGES ON DATABASE gitlab TO gitlab;
\q

Preparing the Environment

We need a dedicated user and group:

pw addgroup git
pw adduser git -g git -m -d /usr/local/www/gitlab -c "GitLab"
ln -s /usr/local/bin/git /usr/bin/git

Gitlab-shell

Installation

We install the gitlab shell, which interfaces Gitlab with git. Switch to the git user and clone the sources:

su - git
git clone https://github.com/gitlabhq/gitlab-shell.git
git checkout v1.9.4

Configuration

Still as the git user, copy the example configuration:

cp config.yml.example config.yml

Three things need to be changed here:

  • Change the URL of your site (gitlab_url).
  • Replace any /home/git paths with /usr/local/www/gitlab.
  • Configure redis by setting the binary path (/usr/local/bin/redis-cli) and the address of your Redis server.

Finally run /usr/local/www/gitlab/gitlab-shell/bin/install.

Gitlab

Installation

As the git user, clone the gitlab repository and check out the version you want:

su - git
git clone https://github.com/gitlabhq/gitlabhq.git gitlab
git checkout 6-8-stable

Configuration

As the git user, copy the gitlab configuration and edit it:

cp config/gitlab.yml.example config/gitlab.yml

First, change the web server name, host, and port:

host: gitlab.unix-experience.fr
port: 443
https: true

Then the notification and support email addresses:

email_from: gitlab@unix-experience.fr
support_email: support@unix-experience.fr

Change the git path:

bin_path: /usr/local/bin/git

Replace all paths containing /home/git with /usr/local/www/gitlab/. Then copy the unicorn configuration and update the paths too:

cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

Also add the following listen line:

listen "/usr/local/www/gitlab/gitlab/tmp/sockets/gitlab.socket"

Finally copy and edit the database configuration:

cp config/database.yml.postgresql config/database.yml
vi config/database.yml

Then install the gem and set up the database:

gem install charlock_holmes --version '0.6.9.4'
bundle install --deployment --without development test mysql aws

Finally, still as the git user in the gitlab installation directory, finish the installation by precompiling the assets:

bundle exec rake assets:precompile RAILS_ENV=production

Init Script

Gitlab uses a service running on the machine. Copy the init script to FreeBSD’s rc.d and start it:

cp lib/support/init.d/gitlab /usr/local/etc/rc.d/gitlab
chmod +x /usr/local/etc/rc.d/gitlab
service gitlab start

Apache Configuration

After installing rubygem-passenger (in the prerequisites list), you need to compile the Apache module. Simply run:

/usr/local/lib/ruby/gems/1.9/gems/passenger-4.0.41/bin/passenger-install-apache2-module

Select ruby, validate, and wait for the compilation to finish. Then add the following lines to your Apache configuration:

LoadModule passenger_module /usr/local/lib/ruby/gems/1.9/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
        PassengerRoot /usr/local/lib/ruby/gems/1.9/gems/passenger-4.0.41
        PassengerDefaultRuby /usr/local/bin/ruby19
</IfModule>

Workaround: Underscore Library Issue

If your Gitlab throws an error (in 6.8 it does) when you connect through the web UI, check the application logs in /usr/local/www/gitlab/gitlab/log/production.log. If you see the following error:

couldn't find file 'underscore'

Edit the file /usr/local/www/gitlab/gitlab/app/assets/javascripts/application.js.coffee and remove the line about underscore.

Conclusion

You now have a working Gitlab instance, adding value to your organization by offering a github-quality service while keeping full control over your data.

Source

This article is based on the following tutorial, which I adapted to modernize the Gitlab install: https://github.com/chadliu23/Installation-guide-for-GitLab6-on-Freebsd