2016-02-14

GitLab CE Quick Installation Guide on Ubuntu 14.04


Here's a short write up of how I installed GitLab CE on one of my homelab servers

Install GitLab


First add gitlab repository, key and install it with 'apt-get' thru the script 'gitlab_ubuntu1404_setup.sh'

File: gitlab_ubuntu1404_setup.sh

#!/bin/bash
#
# GitLab CE Quick Installation Guide on Ubuntu 14.04
#
# @NorSoulx 2016
#

if [ "$EUID" != 0 ] ; then echo "Please run as root"; exit ; fi

#####################
# 1) Add GitLab Repos
#
APTSRC=/etc/apt/sources.list.d/gitlab_gitlab-ce.list
BACKUPFILE=/tmp/gitlab.apt.source.bak.$(date '+%Y%m%d-%H%M%S').$$
if [ -f $APTSRC ]; then cp $APTSRC $BACKUPFILE ; fi

cat << APTEND > $APTSRC
#GitLab
deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ trusty main
deb-src https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ trusty main
APTEND


#####################
# 2) Add GitLab key
#
wget -qO - https://packages.gitlab.com/gpg.key | apt-key add -

#####################
# 3) Install packages
#
PKGS="openssh-server ca-certificates postfix gitlab-ce"

apt-get update
for PKG in $PKGS; do
  apt-get install $PKG
done

#####################
# 4) Configure
#
gitlab-ctl reconfigure

# 5) Summary
#
cat << DIREND
GITLAB DIRS
-----------
/opt/gitlab             application code
/var/opt/gitlab         application data and configuration files (gitlab-ctl)   DO NOT EDIT
/etc/gitlab             configuration files (omnibus-gitlab).                   EDIT MANUALLY
/var/log/gitlab         log data (omnibus-gitlab)
DIREND




Installed by running:

mygitlab$ sudo ./gitlab_ubuntu1404_setup.sh


Configure GitLab


I have multiple bonding interfaces and subnets configured on this homelab server, so I  put GitLab on a new ip alias.

Add alias IP


To manually add the alias ip, I did (I've also added this IP to my boot-startup-script)

mygitlab$ sudo ip addr add 10.11.12.13/32 dev bond0


Added new alias IP to local DNS or /etc/hosts.

mygitlab$ grep mygitlab /etc/hosts
10.11.12.13 mygitlab


Create certificate


Created local certificate for https:

mygitlab$ sudo mkdir -p /etc/gitlab/ssl
mygitlab$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/gitlab/ssl/mygitlab.key -out /etc/gitlab/ssl/mygitlab.crt


Edit /etc/gitlab/gitlab.rb


Made changes to /etc/gitlab/gitlab.rb.
Change url and ssh host, move backups and datadir, configure ssl.

Set:

external_url 'https://mygitlab'
gitlab_rails['gitlab_ssh_host'] = 'mygitlab'
gitlab_rails['backup_path'] = "/data02/gitlab/backups"
git_data_dir "/data01/gitlab/git-data"
nginx['ssl_certificate'] = "/etc/gitlab/ssl/mygitlab.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/mygitlab.key"
nginx['listen_addresses'] = ['mygitlab']


Reconfigure


Ran gitlab-ctl reconfigure for changes to take effect:

mygitlab$ sudo gitlab-ctl reconfigure


Login and change default root password

Login with web-browser: https://mygitlab

Default:
Username: root
Password: 5iveL!fe (change to something else)


Next add users and create projets via web-interface.

Git repositories are located under directory:

/var/opt/gitlab/git-data/repositories