Difference between revisions of "Gitlab"

From ArchWiki
Jump to: navigation, search
(Required packages)
(Start and test GitLab)
(37 intermediate revisions by 8 users not shown)
Line 6: Line 6:
 
{{Article summary wiki|Ruby on Rails}}
 
{{Article summary wiki|Ruby on Rails}}
 
{{Article summary end}}
 
{{Article summary end}}
{{Merge|Gitlab2|Most of the article is duplicated.}}
 
{{Out of date|As of version 5.0,Gitlab will no longer depend on gitolite. Also redis is replaced by sidekiq. A rewrite is scheduled when 5.0 comes out on March 22nd.}}
 
 
 
[http://gitlab.org/ Gitlab] is a free git repository management application based on [[Ruby on Rails]]. It is distributed under the MIT License and its source code can be found on [https://github.com/gitlabhq/gitlabhq Github]. It is a very active project with a monthly release cycle and ideal for businesses that want to keep their code private. Consider it as a self hosted Github but open source. You can try a demo [http://demo.gitlabhq.com/ here].
 
[http://gitlab.org/ Gitlab] is a free git repository management application based on [[Ruby on Rails]]. It is distributed under the MIT License and its source code can be found on [https://github.com/gitlabhq/gitlabhq Github]. It is a very active project with a monthly release cycle and ideal for businesses that want to keep their code private. Consider it as a self hosted Github but open source. You can try a demo [http://demo.gitlabhq.com/ here].
 +
{{Note|Throughout the article, sudo is heavily used, assuming that the user that is running the commands is root or someone with equal privileges. There is no need to edit the sudoers file whatsoever. It is only used to change to the appropriate user. For more info read {{ic|man sudo}}.}}
  
==Required packages==
+
== Installation ==
 
+
Simply install the {{aur|gitlab}} package from the [[AUR]].
Install the packages below as they are needed to proceed further.
+
 
+
# pacman -Syu --noconfirm --needed sudo base-devel zlib libyaml openssl gdbm readline ncurses libffi curl git openssh redis libxml2 libxslt icu python2 mysql postgresql
+
 
+
 
{{Note| In order to receive mail notifications, make sure to install a mail server. By default, Archlinux does not ship with one. The recommended mail server is [[postfix]], but you can use others such as [[SSMTP]], [[msmtp]], [[sendmail]], [https://wiki.archlinux.org/index.php/Category:Mail_Server etc].}}
 
{{Note| In order to receive mail notifications, make sure to install a mail server. By default, Archlinux does not ship with one. The recommended mail server is [[postfix]], but you can use others such as [[SSMTP]], [[msmtp]], [[sendmail]], [https://wiki.archlinux.org/index.php/Category:Mail_Server etc].}}
 
== PKGBUILDs for Gitlab and Gitlab-shell ==
 
There are some (not fully working) PKGBUILDs available to create installable packages:
 
 
[https://github.com/mtorromeo/archlinux-packages/tree/master/gitlab Gitlab PKGBUILD on GitHub.com]
 
 
[https://github.com/mtorromeo/archlinux-packages/tree/master/gitlab-shell Gitlab-shell PKGBUILD on GitHub.com]
 
 
(Please extend/rename this section with further instructions)
 
 
==Ruby==
 
 
GitLab supports [[ruby]] >= {{ic|1.9.3}} and {{ic|2.0.0}}, but some dependencies gems work better with ruby {{ic|1.9.3}}. Install it from the official repositories and if you bump into any trouble use [[rvm]] with ruby {{ic|1.9.3-p392}}.
 
 
 
{{Note|If you want to use rvm be sure to check out [[Gitlab#Running GitLab with rvm]] before starting with the installation}}
 
{{Note|If you want to use rvm be sure to check out [[Gitlab#Running GitLab with rvm]] before starting with the installation}}
  
==User accounts==
+
== Configuration ==
 
+
Add {{ic|git}} user:
+
 
+
# useradd -U -m -d /home/git git
+
 
+
{{Note| {{ic|git}} user must have its initial group set to {{ic|git}} (not {{ic|users}}). If the initial group is not {{ic|git}}, then all files created by the {{ic|git}} user will be owned by {{ic|git:users}} which will prevent GitLab from showing you a newly created repository (it will get stucked at the page where it tells you how to push to the new repository).}}
+
 
+
==gitlab-shell==
+
 
+
GitLab Shell is an ssh access and repository management software developed specially for GitLab.
+
 
+
Login as git:
+
+
# su - git
+
 
+
Clone gitlab shell:
+
+
$ git clone https://github.com/gitlabhq/gitlab-shell.git
+
$ cd gitlab-shell
+
 
+
Switch to the right version:
+
 
+
$ git checkout v1.4.0
+
 
+
Edit {{ic|config.yml}} and replace gitlab_url with something like {{ic|http://domain.com/}}:
+
 
+
$ cp config.yml.example config.yml
+
 
+
Setup the environment:
+
 
+
$ ./bin/install
+
 
+
You should see this result:
+
 
+
{{hc|Example output|<nowiki>
+
mkdir -p /home/git/repositories: true
+
mkdir -p /home/git/.ssh: true
+
chmod 700 /home/git/.ssh: true
+
touch /home/git/.ssh/authorized_keys: true
+
chmod 600 /home/git/.ssh/authorized_keys: true
+
chmod -R ug+rwX,o-rwx /home/git/repositories: true
+
find /home/git/repositories -type d -print0 | xargs -0 chmod g+s: true
+
</nowiki>}}
+
 
+
==Database selection==
+
  
Currently GitLab supports [[MySQL]] and [[PostgreSQL]]. [[MariaDB]] has not been officially tested.
+
=== Database backend ===
 +
Currently GitLab supports [[MySQL]] and [[PostgreSQL]]. [[MariaDB]] has not been officially tested but it works just fine.
  
===MariaDB===
+
==== MariaDB ====
  
 
[[pacman|Install]] {{Pkg|mariadb}} and {{Pkg|libmariadbclient}} from the [[official repositories]] and start the [[daemon]]. Create the database and do not forget to replace {{ic|your_password_here}} with a real one.
 
[[pacman|Install]] {{Pkg|mariadb}} and {{Pkg|libmariadbclient}} from the [[official repositories]] and start the [[daemon]]. Create the database and do not forget to replace {{ic|your_password_here}} with a real one.
  
# su - git
+
{{bc|mysql -u root -p}}
$ mysql -u root -p
+
  
  mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
+
  mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production`;
 
  mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'your_password_here';
 
  mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'your_password_here';
 
  mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
 
  mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
Line 97: Line 32:
 
Try connecting to the new database with the new user:
 
Try connecting to the new database with the new user:
  
$ mysql -u gitlab -p -D gitlabhq_production
+
{{bc|mysql -u gitlab -p -D gitlabhq_production}}
  
===PostgreSQL===
+
==== PostgreSQL ====
  
[[pacman|Install]] {{Pkg|postgresql}} and {{Pkg|libpqxx}} from the [[official repositories]]. Follow [[PostgreSQL#Installing_PostgreSQL]] to set it up and start the [[daemon]].
+
[[pacman|Install]] {{Pkg|postgresql}} and {{Pkg|libpqxx}} from the [[official repositories]]. Follow [[PostgreSQL#Installing_PostgreSQL]] to set it up and start the [[daemon]]. Login to PostgreSQL and remember to change {{ic|your_password_here}} to a real one:
  
Login to PostgreSQL and remember to change {{ic|your_password_here}} to a real one:
+
{{bc|psql -d template1}}
  
# sudo -u postgres psql -d template1
+
  template1=# CREATE USER gitlab WITH PASSWORD 'your_password_here';
 
+
  template1=# CREATE DATABASE gitlabhq_production OWNER gitlab;
  template1=# CREATE USER git WITH PASSWORD 'your_password_here';
+
  template1=# CREATE DATABASE gitlabhq_production OWNER git;
+
 
  template1=# \q
 
  template1=# \q
  
 
Try connecting to the new database with the new user:
 
Try connecting to the new database with the new user:
  
# sudo -u git -H psql -d gitlabhq_production
+
{{bc|psql -d gitlabhq_production}}
  
===MySQL===
+
===Web server configuration===
  
If you are still in favor of {{AUR|mysql}}, follow the same commands as MariaDB.
+
====Nginx and unicorn====
  
==Gitlab==
+
[[pacman|Install]] {{Pkg|nginx}} from the [[official repositories]].
  
===Installation===
+
Run these commands to setup nginx:
  
Clone GitLab's repository:
+
{{bc|ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab}}
# su - git
+
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
+
$ cd gitlab
+
$ git checkout 5-2-stable
+
  
{{Note| You can change {{ic|5-2-stable}} to {{ic|master}} if you want the bleeding edge version, but do so with caution! Check github to see what is the latest stable version and replace above accordingly.}}
+
Edit {{ic|/etc/nginx/sites-enabled/gitlab}} and change YOUR_SERVER_IP and YOUR_SERVER_FQDN to the IP address and fully-qualified domain name of the host serving Gitlab. As you can see nginx needs to access {{ic|/home/gitlab/gitlab/tmp/sockets/gitlab.socket}} socket file. You have to be able to run {{ic|sudo -u http ls /home/gitlab/gitlab/tmp/sockets/gitlab.socket}} successfully. Otherwise setup access to the directory:
 
+
===Basic configuration===
+
 
+
First we need to rename the example file.
+
 
+
$ cp config/gitlab.yml.example config/gitlab.yml
+
 
+
The options are pretty straightforward. Open {{ic|config/gitlab.yml}} with your favorite editor and edit where needed.
+
Make sure to change {{ic|localhost}} to the fully-qualified domain name of your host serving GitLab where necessary.
+
 
+
Make sure GitLab can write to the {{ic|log/}} and {{ic|tmp/}} directories:
+
 
+
$ chown -R git log/
+
$ chown -R git tmp/
+
$ chmod -R u+rwX  log/
+
$ chmod -R u+rwX  tmp/
+
 
+
Create directory for satellites:
+
 
   
 
   
  $ mkdir /home/git/gitlab-satellites
+
  # chgrp http /home/gitlab
 +
# chmod u=rwx,g=rx,o= /home/gitlab
  
Create directories for sockets/pids and make sure GitLab can write to them:
+
Restart gitlab.service, resque.service and nginx.
  
$ mkdir tmp/{pids,sockets}
+
[http://unicorn.bogomips.org/ Unicorn] is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels. First we rename the example file and then we start unicorn:
$ chmod -R u+rwX  tmp/{pids,sockets}
+
  
Create the {{ic|public/uploads}} directory otherwise backup will fail:
+
# cd /home/gitlab/gitlab
 +
# sudo -u gitlab cp config/unicorn.rb.orig config/unicorn.rb
 +
# sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
  
$ mkdir public/uploads
+
====Apache and unicorn====
$ chmod -R u+rwX  public/uploads
+
  
Copy the example Puma config and edit to your liking:
+
[[pacman|Install]] {{Pkg|apache}} from the [[official repositories]].
  
$ cp config/puma.rb.example config/puma.rb
+
=====Configure Unicorn=====
  
Configure Git global settings for git user, useful when editing via web. Edit {{ic|user.email}} according to what is set in {{ic|gitlab.yml}}:
+
{{Note|If the default path is not {{ic|/home/git}} for your installation, change the below path accordingly}}
  
  $ git config --global user.name "GitLab"
+
As the official installation guide instructs, copy the unicorn configuration file:
$ git config --global user.email "gitlab@localhost"
+
  # sudo -u git -H cp /home/git/gitlab/config/unicorn.rb.example /home/git/gitlab/config/unicorn.rb
  
Configure GitLab database settings:
+
Now edit {{ic|config/unicorn.rb}} and add a listening port by uncommenting the following line:
 +
listen "127.0.0.1:8080"
  
* MariaDB:
+
{{Tip| You can set a custom port if you want. Just remember to also include it in Apache's virtual host. See below.}}
$ cp config/database.yml.mysql config/database.yml
+
  
* PostgreSQL:
+
=====Create a virtual host for Gitlab=====
$ cp config/database.yml.postgresql config/database.yml
+
  
Make sure to update {{ic|username}}/{{ic|password}} in {{ic|config/database.yml}}.
+
Create a configuration file for Gitlab’s virtual host and insert the lines below adjusted accordingly. For the ssl section see [[LAMP#SSL]]. If you do not need it, remove it. Notice that the SSL virtual host needs a specific IP instead of generic. Also if you set a custom port for Unicorn, do not forget to set it at the BalanceMember line.
  
 +
=====Enable host and start unicorn=====
  
===Install gems===
+
Enable your Gitlab virtual host and reload [[Apache]]:
 +
{{hc|/etc/httpd/conf/httpd.conf| Include /etc/httpd/conf/extra/gitlab.conf}}
  
{{Tip| If you do not want to download any gem documentation, add {{ic|gem: --no-rdoc --no-ri}} to {{ic|/home/git/.gemrc}}. Be sure to add it as the {{ic|git}} user in order to acquire the appropriate permissions.}}
+
Finally start unicorn:
{{Note|See bug #[https://bugs.archlinux.org/task/33327 33327] for about system-wide gems. As a temporary solution the following packages will be installed as {{ic|git}} user, make sure nano {{ic|~/.gemrc}} contains {{ic|gem: ... --user-install}}. And then add the {{ic|bin}} path to the {{ic|PATH}} variable like so {{ic|1=export PATH="${PATH}:~/.gem/ruby/2.0.0/bin"}}.}}
+
  
Install {{ic|bundler}} and {{ic|charlock_holmes}} under {{ic|$HOME/.gem/}} (normally system wide via sudo):
+
{{bc|systemctl start gitlab-unicorn}}
  
# su - git
+
===Basic configuration===
$ gem install charlock_holmes --version '0.6.9.4'
+
Open {{ic|/etc/gitlab/gitlab.yml}} with your favorite editor and edit where needed. The options are pretty straightforward. Make sure to change {{ic|localhost}} to the fully-qualified domain name of your host serving GitLab where necessary.
$ gem install bundler
+
 
+
Install gems from Gemfile:
+
 
+
$ cd gitlab/
+
 
+
{{Note|When executing the below and you recieve `Could not verify the SSL certificate for https://rubygems.org/` see bug #[https://github.com/gitlabhq/gitlabhq/issues/4095 GitHub-4095] most likely because you're behind a proxy that tries to inject a local certificate for SSL domains in order to verify its content}}
+
 
+
If you used MariaDB:
+
 
+
$ bundle install --deployment --without development test postgres
+
 
+
If you used PostgreSQL:
+
 
+
$ bundle install --deployment --without development test mysql
+
  
{{Note|1= Using {{ic|--without group_name}} in bundle command line will ignore required packages for the mentioned groups.}}
+
To configure GitLab database settings, make sure to update {{ic|username}}/{{ic|password}} in {{ic|/etc/gitlab/database.yml}}. If you planning to use PostgreSQL backend, you should copy its template file before configuring it:
 +
{{bc|cp /usr/share/doc/gitlab/database.yml.postgresql /etc/gitlab/database.yml}}
  
 
===Initialize Database===
 
===Initialize Database===
Line 214: Line 112:
 
Initialize database and activate advanced features:  
 
Initialize database and activate advanced features:  
 
  $ bundle exec rake gitlab:setup RAILS_ENV=production
 
  $ bundle exec rake gitlab:setup RAILS_ENV=production
 +
 +
You have to run these commands as the gitlab user from the gitlab directory:
 +
$ cd /usr/share/webapps/gitlab
 +
$ sudo -u gitlab bundle exec rake gitlab:check RAILS_ENV=production
  
 
{{Note|If you recieve a error {{ic|No such file or directory - /home/git/repositories/root}} then most likely you've changed the default configuration for {{ic|GitLab}} and you'll need to modify all static paths in {{ic|config/gitlab.yml}} and run the above command again to initialize the database!}}
 
{{Note|If you recieve a error {{ic|No such file or directory - /home/git/repositories/root}} then most likely you've changed the default configuration for {{ic|GitLab}} and you'll need to modify all static paths in {{ic|config/gitlab.yml}} and run the above command again to initialize the database!}}
Line 255: Line 157:
 
{{Note| {{ic|gitlab:check}} will complain about missing initscripts. Don't worry, we will use ArchLinux' [[systemd]] to manage server start (which GitLab does not recognize).}}
 
{{Note| {{ic|gitlab:check}} will complain about missing initscripts. Don't worry, we will use ArchLinux' [[systemd]] to manage server start (which GitLab does not recognize).}}
  
==Web server configuration==
+
== Start and test GitLab ==
 
+
  $ systemctl daemon-reload
 
+
After starting the database backend, simply run:
===Unicorn only===
+
  $ systemctl start redis mysqld gitlab-sidekiq gitlab-unicorn
 
+
To automatically launch GitLab at startup, run:
{{Note|As of GitLab 5.1 Unicorn is no longer the default server as it got replaced by Puma. You can therefore ignore this section.}}
+
  $ systemctl enable gitlab.target gitlab-sidekiq gitlab-unicorn
 
+
Edit {{ic|/home/gitlab/gitlab/config/unicorn.rb}} uncomment:
+
 
+
listen 8080 # listen to port 8080 on all TCP interfaces
+
 
+
Create {{ic|/etc/rc.d/unicorn-gitlab}}.
+
<pre>
+
#!/bin/bash
+
 
+
. /etc/rc.conf
+
. /etc/rc.d/functions
+
 
+
 
+
PID=`pidof -o %PPID /usr/bin/ruby`
+
case "$1" in
+
  start)
+
    stat_busy "Starting unicorn"
+
    [ -z "$PID" ] && sudo -u gitlab bash  -c  "source /home/gitlab/.bash_profile && cd /home/gitlab/gitlab/ && bundle exec unicorn_rails -c config/unicorn.rb -E production -D"
+
    if [ $? -gt 0 ]; then
+
      stat_fail
+
    else
+
      add_daemon unicorn
+
      stat_done
+
    fi
+
    ;;
+
  stop)
+
    stat_busy "Stopping unicorn"
+
    [ ! -z "$PID" ]  && kill $PID &> /dev/null
+
    if [ $? -gt 0 ]; then
+
      stat_fail
+
    else
+
      rm_daemon unicorn
+
      stat_done
+
    fi
+
    ;;
+
  restart)
+
    $0 stop
+
    sleep 1
+
    $0 start
+
    ;;
+
  *)
+
    echo "usage: $0 {start|stop|restart}"
+
esac
+
exit 0
+
</pre>
+
 
+
Start '''unicorn''':
+
 
+
# /etc/rc.d/unicorn-gitlab start
+
 
+
Test it http://localhost:8080
+
 
+
Add it to DAEMONS array in /etc/rc.conf
+
 
+
Redirect http port to unicorn server
+
 
+
# iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
+
 
+
And test again, now http://localhost
+
 
+
===Nginx and unicorn===
+
 
+
[[pacman|Install]] {{Pkg|nginx}} from the [[official repositories]].
+
 
+
Run these commands to setup nginx:
+
 
+
  # wget https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab -P /etc/nginx/sites-available/
+
# ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
+
 
+
Edit {{ic|/etc/nginx/sites-enabled/gitlab}} and change YOUR_SERVER_IP and YOUR_SERVER_FQDN to the IP address and fully-qualified domain name of the host serving Gitlab. As you can see nginx needs to access {{ic|/home/gitlab/gitlab/tmp/sockets/gitlab.socket}} socket file. You have to be able to run {{ic|sudo -u http ls /home/gitlab/gitlab/tmp/sockets/gitlab.socket}} successfully. Otherwise setup access to the directory:
+
   
+
# chgrp http /home/gitlab
+
# chmod u=rwx,g=rx,o= /home/gitlab
+
 
+
Restart gitlab.service, resque.service and nginx.
+
 
+
[http://unicorn.bogomips.org/ Unicorn] is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels. First we rename the example file and then we start unicorn:
+
 
+
# cd /home/gitlab/gitlab
+
# sudo -u gitlab cp config/unicorn.rb.orig config/unicorn.rb
+
# sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
+
 
+
===Apache and unicorn===
+
 
+
[[pacman|Install]] {{Pkg|apache}} from the [[official repositories]].
+
 
+
====Configure Unicorn====
+
 
+
{{Note|If the default path is not {{ic|/home/git}} for your installation, change the below path accordingly}}
+
 
+
As the official installation guide instructs, copy the unicorn configuration file:
+
# sudo -u git -H cp /home/git/gitlab/config/unicorn.rb.example /home/git/gitlab/config/unicorn.rb
+
 
+
Now edit {{ic|config/unicorn.rb}} and add a listening port by uncommenting the following line:
+
listen "127.0.0.1:8080"
+
 
+
{{Tip| You can set a custom port if you want. Just remember to also include it in Apache's virtual host. See below.}}
+
 
+
====Create a virtual host for Gitlab====
+
 
+
Create a configuration file for Gitlab’s virtual host and insert the lines below adjusted accordingly. For the ssl section see [[LAMP#SSL]]. If you do not need it, remove it. Notice that the SSL virtual host needs a specific IP instead of generic. Also if you set a custom port for Unicorn, do not forget to set it at the BalanceMember line.
+
 
+
# mkdir -pv /etc/httpd/conf/vhosts/
+
 
+
{{hc|/etc/httpd/conf/vhosts/gitlab|
+
<VirtualHost *:80>
+
  ServerName gitlab.myserver.com
+
  ServerAlias www.gitlab.myserver.com
+
  DocumentRoot /home/gitlab/gitlab/public
+
  ErrorLog /var/log/httpd/gitlab_error_log
+
  CustomLog /var/log/httpd/gitlab_access_log combined
+
 
+
  <Proxy balancer://unicornservers>
+
      BalancerMember http://127.0.0.1:8080
+
  </Proxy>
+
 
+
  <Directory /home/gitlab/gitlab/public>
+
    AllowOverride All
+
    Options -MultiViews
+
  </Directory>
+
 
+
  RewriteEngine on
+
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
+
  RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
+
 
+
  ProxyPass /uploads !
+
  ProxyPass / balancer://unicornservers/
+
  ProxyPassReverse / balancer://unicornservers/
+
  ProxyPreserveHost on
+
 
+
  <Proxy *>
+
      Order deny,allow
+
      Allow from all
+
  </Proxy>
+
</VirtualHost>
+
 
+
<VirtualHost MY_IP:443>
+
  ServerName gitlab.myserver.com
+
  ServerAlias www.gitlab.myserver.com
+
  DocumentRoot /home/gitlab/gitlab/public
+
  ErrorLog /var/log/httpd/gitlab_error_log
+
  CustomLog /var/log/httpd/gitlab_access_log combined
+
 
+
  <Proxy balancer://unicornservers>
+
      BalancerMember http://127.0.0.1:8080
+
  </Proxy>
+
 
+
  <Directory /home/gitlab/gitlab/public>
+
    AllowOverride All
+
    Options -MultiViews
+
  </Directory>
+
 
+
  RewriteEngine on
+
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
+
  RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
+
 
+
  ProxyPass /uploads !
+
  ProxyPass / balancer://unicornservers/
+
  ProxyPassReverse / balancer://unicornservers/
+
  ProxyPreserveHost on
+
 
+
  <Proxy *>
+
      Order deny,allow
+
      Allow from all
+
  </Proxy>
+
 
+
  SSLEngine on
+
  SSLCertificateFile /home/gitlab/gitlab/ssl.cert
+
  SSLCertificateKeyFile /home/gitlab/gitlab/ssl.key
+
</VirtualHost>
+
}}
+
 
+
====Enable host and start unicorn====
+
 
+
Enable your Gitlab virtual host and reload [[Apache]]:
+
{{hc|/etc/httpd/conf/httpd.conf|Include conf/vhosts/gitlab}}
+
 
+
Finally start unicorn:
+
 
+
  # cd /home/gitlab/gitlab
+
# sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
+
 
+
==systemd support==
+
 
+
Note that you don't need the systemd units to launch shell scripts as suggested by the gitlab authors. Just make sure the ExecStart line points to the full path of the **bundle** executable.
+
 
+
Create:
+
{{hc|gitlab.service|<nowiki>
+
 
+
[Unit]
+
Description=GitLab Puma Server
+
 
+
[Service]
+
User=git
+
WorkingDirectory=/home/git/gitlab
+
Environment=RAILS_ENV=production
+
SyslogIdentifier=gitlab-puma
+
Type=forking
+
TimeoutStartSec=600
+
PIDFile=/home/git/gitlab/tmp/pids/puma.pid
+
 
+
ExecStart=/usr/bin/bundle exec "puma -C /home/git/gitlab/config/puma.rb -e production"
+
ExecReload=/bin/kill -HUP $MAINPID
+
ExecStop=/bin/kill -QUIT $MAINPID
+
 
+
 
+
[Install]
+
WantedBy=gitlab.target
+
</nowiki>
+
}}
+
 
+
{{hc|gitlab-sidekiq.service|<nowiki>
+
[Unit]
+
Description=GitLab Sidekiq Server
+
 
+
[Service]
+
User=git
+
WorkingDirectory=/home/git/gitlab
+
Environment=RAILS_ENV=production
+
SyslogIdentifier=gitlab-sidekiq
+
Type=forking
+
PIDFile=/home/git/gitlab/tmp/pids/sidekiq.pid
+
 
+
 
+
ExecStart=/usr/bin/bundle exec rake sidekiq:start
+
ExecStop=/usr/bin/bundle exec rake sidekiq:stop
+
 
+
[Install]
+
WantedBy=gitlab.target</nowiki>
+
}}
+
 
+
Also see: https://github.com/gitlabhq/gitlab-recipes/issues/14
+
  
 
==Useful Tips==
 
==Useful Tips==
Line 529: Line 199:
 
  # sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:restore BACKUP=/home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740
 
  # sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:restore BACKUP=/home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740
  
{{Note| Backup folder is set in {{ic|conig.yml}}. Check [[#Application_specific_settings]].}}
+
{{Note| Backup folder is set in {{ic|config/gitlab.yml}}. GitLab backup and restore is documented [https://github.com/gitlabhq/gitlabhq/blob/master/doc/raketasks/backup_restore.md here].}}
  
 
===Update Gitlab===
 
===Update Gitlab===
Line 600: Line 270:
 
==See also==
 
==See also==
 
*[https://github.com/gitlabhq/gitlabhq/blob/stable/doc/install/installation.md Official Documentation]
 
*[https://github.com/gitlabhq/gitlabhq/blob/stable/doc/install/installation.md Official Documentation]
*[https://github.com/gitlabhq/gitlab-recipes Gitlab recipes for setup on different platforms, update etc.]
+
*[https://github.com/gitlabhq/gitlab-recipes Gitlab recipes with further documentation on running it with several webservers]
*[http://www.andmarios.com/en/2012/06/gitlab-on-an-ubuntu-10-04-server-with-apache/ GitLab on an Ubuntu 10.04 server with Apache]
+
*[http://blog.phusion.nl/2012/04/21/tutorial-setting-up-gitlab-on-debian-6/ Setting up gitlab on Debian 6]
+
*[http://howto.basjes.nl/linux/installing-gitlab-on-centos-6 Installing Gitlab on CentOS 6]
+
*[https://gist.github.com/2440768 Gist: Install Gitlab on Debian Squeeze]
+
*[https://gist.github.com/3305554 Gist: Install Gitlab on Archlinux]
+

Revision as of 16:32, 4 December 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end Gitlab is a free git repository management application based on Ruby on Rails. It is distributed under the MIT License and its source code can be found on Github. It is a very active project with a monthly release cycle and ideal for businesses that want to keep their code private. Consider it as a self hosted Github but open source. You can try a demo here.

Note: Throughout the article, sudo is heavily used, assuming that the user that is running the commands is root or someone with equal privileges. There is no need to edit the sudoers file whatsoever. It is only used to change to the appropriate user. For more info read man sudo.

Installation

Simply install the gitlabAUR package from the AUR.

Note: In order to receive mail notifications, make sure to install a mail server. By default, Archlinux does not ship with one. The recommended mail server is postfix, but you can use others such as SSMTP, msmtp, sendmail, etc.
Note: If you want to use rvm be sure to check out Gitlab#Running GitLab with rvm before starting with the installation

Configuration

Database backend

Currently GitLab supports MySQL and PostgreSQL. MariaDB has not been officially tested but it works just fine.

MariaDB

Install mariadb and libmariadbclient from the official repositories and start the daemon. Create the database and do not forget to replace your_password_here with a real one.

mysql -u root -p
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production`;
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'your_password_here';
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
mysql> \q

Try connecting to the new database with the new user:

mysql -u gitlab -p -D gitlabhq_production

PostgreSQL

Install postgresql and libpqxx from the official repositories. Follow PostgreSQL#Installing_PostgreSQL to set it up and start the daemon. Login to PostgreSQL and remember to change your_password_here to a real one:

psql -d template1
template1=# CREATE USER gitlab WITH PASSWORD 'your_password_here';
template1=# CREATE DATABASE gitlabhq_production OWNER gitlab;
template1=# \q

Try connecting to the new database with the new user:

psql -d gitlabhq_production

Web server configuration

Nginx and unicorn

Install nginx from the official repositories.

Run these commands to setup nginx:

ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

Edit /etc/nginx/sites-enabled/gitlab and change YOUR_SERVER_IP and YOUR_SERVER_FQDN to the IP address and fully-qualified domain name of the host serving Gitlab. As you can see nginx needs to access /home/gitlab/gitlab/tmp/sockets/gitlab.socket socket file. You have to be able to run sudo -u http ls /home/gitlab/gitlab/tmp/sockets/gitlab.socket successfully. Otherwise setup access to the directory:

# chgrp http /home/gitlab
# chmod u=rwx,g=rx,o= /home/gitlab

Restart gitlab.service, resque.service and nginx.

Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels. First we rename the example file and then we start unicorn:

# cd /home/gitlab/gitlab
# sudo -u gitlab cp config/unicorn.rb.orig config/unicorn.rb
# sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D

Apache and unicorn

Install apache from the official repositories.

Configure Unicorn
Note: If the default path is not /home/git for your installation, change the below path accordingly

As the official installation guide instructs, copy the unicorn configuration file:

# sudo -u git -H cp /home/git/gitlab/config/unicorn.rb.example /home/git/gitlab/config/unicorn.rb

Now edit config/unicorn.rb and add a listening port by uncommenting the following line:

listen "127.0.0.1:8080"
Tip: You can set a custom port if you want. Just remember to also include it in Apache's virtual host. See below.
Create a virtual host for Gitlab

Create a configuration file for Gitlab’s virtual host and insert the lines below adjusted accordingly. For the ssl section see LAMP#SSL. If you do not need it, remove it. Notice that the SSL virtual host needs a specific IP instead of generic. Also if you set a custom port for Unicorn, do not forget to set it at the BalanceMember line.

Enable host and start unicorn

Enable your Gitlab virtual host and reload Apache:

/etc/httpd/conf/httpd.conf
 Include /etc/httpd/conf/extra/gitlab.conf

Finally start unicorn:

systemctl start gitlab-unicorn

Basic configuration

Open /etc/gitlab/gitlab.yml with your favorite editor and edit where needed. The options are pretty straightforward. Make sure to change localhost to the fully-qualified domain name of your host serving GitLab where necessary.

To configure GitLab database settings, make sure to update username/password in /etc/gitlab/database.yml. If you planning to use PostgreSQL backend, you should copy its template file before configuring it:

cp /usr/share/doc/gitlab/database.yml.postgresql /etc/gitlab/database.yml

Initialize Database

Note: Make sure the redis daemon is enabled and started, otherwise the following command will fail. To check the status and see if it's running execute systemctl status redis, if it's dead start it as per usual via systemctl start redis

Initialize database and activate advanced features:

$ bundle exec rake gitlab:setup RAILS_ENV=production

You have to run these commands as the gitlab user from the gitlab directory:

$ cd /usr/share/webapps/gitlab
$ sudo -u gitlab bundle exec rake gitlab:check RAILS_ENV=production
Note: If you recieve a error No such file or directory - /home/git/repositories/root then most likely you've changed the default configuration for GitLab and you'll need to modify all static paths in config/gitlab.yml and run the above command again to initialize the database!

Check status

With the following commands we check if the steps we followed so far are configured properly.

$ bundle exec rake gitlab:env:info RAILS_ENV=production
$ bundle exec rake gitlab:check RAILS_ENV=production
Example output of gitlab:env:info
System information
System:		Arch Linux
Current User:	git
Using RVM:	yes
RVM Version:	1.20.3
Ruby Version:	2.0.0p0
Gem Version:	2.0.0
Bundler Version:1.3.5
Rake Version:	10.0.4

GitLab information
Version:	5.2.0.pre
Revision:	4353bab
Directory:	/home/git/gitlab
DB Adapter:	mysql2
URL:		http://gitlab.arch
HTTP Clone URL:	http://gitlab.arch/some-project.git
SSH Clone URL:	git@gitlab.arch:some-project.git
Using LDAP:	no
Using Omniauth:	no

GitLab Shell
Version:	1.4.0
Repositories:	/home/git/repositories/
Hooks:		/home/git/gitlab-shell/hooks/
Git:		/usr/bin/git
Note: gitlab:check will complain about missing initscripts. Don't worry, we will use ArchLinux' systemd to manage server start (which GitLab does not recognize).

Start and test GitLab

$ systemctl daemon-reload

After starting the database backend, simply run:

$ systemctl start redis mysqld gitlab-sidekiq gitlab-unicorn

To automatically launch GitLab at startup, run:

$ systemctl enable gitlab.target gitlab-sidekiq gitlab-unicorn

Useful Tips

Hook into /var

 sudo mkdir -m700 /var/log/gitlab /var/tmp/gitlab
 sudo chown gitlab:gitlab /var/log/gitlab /var/tmp/gitlab
 sudo -u gitlab -i
 cd ~/gitlab
 d=log; mv $d/* /var/$d/gitlab; rm -f $d/.gitkeep; rm -r $d && ln -s /var/$d/gitlab $d
 d=tmp; mv $d/* /var/$d/gitlab; rm -f $d/.gitkeep; rm -r $d && ln -s /var/$d/gitlab $d

Hidden options

Go to Gitlab's home directory

# cd /home/gitlab/gitlab

and run

# rake -T | grep gitlab

These are the options so far:

rake gitlab:app:backup_create      # GITLAB | Create a backup of the gitlab system
rake gitlab:app:backup_restore     # GITLAB | Restore a previously created backup
rake gitlab:app:enable_automerge   # GITLAB | Enable auto merge
rake gitlab:app:setup              # GITLAB | Setup production application
rake gitlab:app:status             # GITLAB | Check gitlab installation status
rake gitlab:gitolite:update_hooks  # GITLAB | Rewrite hooks for repos
rake gitlab:gitolite:update_keys   # GITLAB | Rebuild each key at gitolite config
rake gitlab:gitolite:update_repos  # GITLAB | Rebuild each project at gitolite config
rake gitlab:test                   # GITLAB | Run both cucumber & rspec

Backup and restore

Create a backup of the gitlab system:

# sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:create

Restore the previously created backup file /home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740_gitlab_backup.tar:

# sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:restore BACKUP=/home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740
Note: Backup folder is set in config/gitlab.yml. GitLab backup and restore is documented here.

Update Gitlab

When a new version is out follow the instructions at Github wiki. A new release is out every 22nd of a month.

Migrate from sqlite to mysql

Get latest code as described in #Update_Gitlab. Save data.

# cd /home/gitlab/gitlab
# sudo -u gitlab bundle exec rake db:data:dump RAILS_ENV=production

Follow #Mysql instructions and then setup the database.

# sudo -u gitlab bundle exec rake db:setup RAILS_ENV=production

Finally restore old data.

# sudo -u gitlab bundle exec rake db:data:load RAILS_ENV=production

Running GitLab with rvm

To run gitlab with rvm first you have to set up an rvm:

 curl -L https://get.rvm.io | bash -s stable --ruby=1.9.3
Note: Version 1.9.3 is currently recommended to avoid some compatibility issues.

For the complete installation you will want to be the final user (e.g. git) so make sure to switch to this user and activate your rvm:

 su - git
 source "$HOME/.rvm/scripts/rvm"

Then continue with the installation instructions from above. However, the systemd scripts will not work this way, because the environment for the rvm is not activated. The recommendation here is to create to separate shell scripts for puma and sidekiq to activate the environment and then start the service:

gitlab.sh
#!/bin/sh
source `/home/git/.rvm/bin/rvm 1.9.3 do rvm env --path`
RAILS_ENV=production bundle exec puma -C "/home/git/gitlab/config/puma.rb"
sidekiq.sh
#!/bin/sh
source `/home/git/.rvm/bin/rvm 1.9.3 do rvm env --path`
case $1 in
    start)
        bundle exec rake sidekiq:start RAILS_ENV=production
        ;;
    stop)
        bundle exec rake sidekiq:stop RAILS_ENV=production
        ;;
    *)
        echo "Usage $0 {start|stop}"
esac

Then modify the above systemd files so they use these scripts. Modify the given lines:

gitlab.service
ExecStart=/home/git/bin/gitlab.sh
sidekiq.service
ExecStart=/home/git/bin/sidekiq.sh start
ExecStop=/home/git/bin/sidekiq.sh stop

Troubleshooting

Sometimes things may not work as expected. Be sure to visit the Trouble Shooting Guide.

See also