Gitlab
| Summary |
|---|
| This page gives guidelines for the installation and configuration of Gitlab on Archlinux. |
| Related |
| Gitolite |
| Ruby on Rails |
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.
Contents |
Installation
Simply install the gitlab package from the AUR.
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 git WITH PASSWORD 'your_password_here'; template1=# CREATE DATABASE gitlabhq_production OWNER git; template1=# \q
Try connecting to the new database with the new user:
psql -d gitlabhq_production
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 it's template file before configuring it:
cp /usr/share/doc/gitlab/database.yml.postgresql /etc/gitlab/database.yml
Initialize Database
Initialize database and activate advanced features:
$ bundle exec rake gitlab:setup RAILS_ENV=production
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
Start and test GitLab
After starting the database backend, simply run:
$ systemctl start redis $ systemctl start gitlab
To automatically launch GitLab at startup, run:
$ systemctl enable redis $ systemctl enable gitlab
Web server configuration
Nginx and unicorn
Install 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 /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
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"
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/
/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:
/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
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
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
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.