Important: You are required to change your passwords used for Gentoo services and set an email address for your Wiki account if you haven't done so. See the full announcement and Wiki email policy change for more information.

GitLab

From Gentoo Wiki
(Redirected from Gitlab)
Jump to: navigation, search
IconInformation.png
This article is a stub. You can help Gentoo Wiki by expanding it.

Disclaimer

This guide is a rough port from the official guide and various internet references.
Some of the steps have been consolidated and obviously customized to the standard Gentoo environment.
If something is missing, please make a point of updating this article, with special attention to dependencies please.


If you don’t like long installation guides likes this, you can use unofficial www-apps/gitlabhq ebuild from CVUT Overlay. There’s also a short guide for dummies how to install it and configure your web server.

Prerequisites/Dependencies

root # echo "dev-lang/tk threads" >> /etc/portage/package.use
root # emerge --ask openssl icu ruby git redis
root # rc-service redis start
root # rc-update add redis default

Prepare the Necessary Users

root # eselect ruby set ruby19
root # eselect python set python2.7

Gitlab uses the git user, so add it:

root # useradd -m -s /bin/bash -c 'Git Version Control' -d /home/git git
root # echo 'export PATH=$(ruby -rubygems -e "puts Gem.user_dir")/bin:/usr/local/bin:$PATH' >> /home/git/.bashrc

Gitlab Shell

root # su git
git cd
git ~ git clone https://github.com/gitlabhq/gitlab-shell.git
git ~ cd gitlab-shell
git ~/gitlab-shell git checkout v1.8.0
git ~/gitlab-shell cp config.yml.example config.yml
Important
edit config.yml with your own domain information or "localhost"
git ~/gitlab-shell nano config.yml
git ~/gitlab-shell ./bin/install

GitLab

root # su git
git $ cd
git ~ $ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
git ~ $ cd gitlab
git ~/gitlab $ git checkout 6-3-stable


Prepare the Database

MySQL/MariaDB

Merge mysql if you have not already.

root # emerge --ask mysql

Setup root mysql password.

Important
your config version will probably be different, read emerge output to get your exact command to run
root # emerge --config =dev-db/mysql-5.1.67

Turn on mysql.

root # rc-service mysql start

Set mysql to start upon reboot.

root # rc-update add mysql default

Create the database and user:

Important
set your own passwords for lines 2 and 3
root # mysql -u root -p
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'changeme aka gitlabdbpass';
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost' IDENTIFIED BY 'gitlabdbpass';
mysql> quit


Test connecting to the databases with the new user:

root # mysql -u gitlab -p -D gitlabhq_production
Enter Password:
git /home/git/gitlab $ cp config/database.yml.mysql config/database.yml
git /home/git/gitlab $
nano config/database.yml
Note
add your database password to this config file
root /home/git/gitlab $ chmod o-rwx config/database.yml

PostgreSQL

Merge postgresql-server, or postgresql-base if you have PostgreSQL on another server.

root # emerge --ask postgresql-server


For PostgreSQL there are different methods of authentification. For a installation on the local machine I prefer using the local account when connecting trough a socket. By default this is enabled.

Create a database and a new user without a password and give him ownership of it. Remember, when connecting trough the socket the shell user is used for authentification, so its name must be gitlab.

root # su postgres -c "psql -d template1"
template1=# CREATE USER git;
template1=# CREATE DATABASE gitlabhq_production OWNER git;
template1=# \q


The gitlab user will need access to the PostgreSQL socket, so it's required to add him to the postgres group

root # gpasswd -a git postgres

And a little test, just to be sure everything went fine:

git /home/git/gitlab# psql -l


Copy the example database configuration file:

git /home/git/gitlab# cp config/database.yml.postgresql config/database.yml


  • Edit the new configuration file and add the database credentials just created:
git /home/git/gitlab# nano config/database.yml
#
# PRODUCTION
#
production:
  adapter: postgresql
  encoding: unicode
  database: gitlabhq_production
  pool: 5
  username: gitlab
  # password:
  # host: localhost
  # port: 5432
  socket: /run/postgresql/.s.PGSQL.5432
root /home/git/gitlab $ chmod o-rwx config/database.yml

Configure Gitlab

git ~/gitlab $ cp config/gitlab.yml.example config/gitlab.yml
Note
edit this file with your domain name (or localhost) & edit your email sent from settings
git ~/gitlab $ nano config/gitlab.yml

Deploy Directories

root /home/git/gitlab $
chown -R git log/
chown -R git tmp/
chmod -R u+rwX  log/
chmod -R u+rwX  tmp/
git ~/gitlab $
mkdir /home/git/gitlab-satellites
mkdir tmp/pids/
mkdir tmp/sockets/
mkdir public/uploads
cp config/unicorn.rb.example config/unicorn.rb
nano config/unicorn.rb
cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
nano config/initializers/rack_attack.rb
git config --global user.name "GitLab"
git config --global user.email "gitlab@localhost"
git config --global core.autocrlf input
Note
add workers for higher loads and higher ram counts 3 for 2gb is default example
root /home/git/gitlab # chmod -R u+rwX tmp/pids/
root /home/git/gitlab #
chmod -R u+rwX tmp/sockets/
root /home/git/gitlab #
chmod -R u+rwX public/uploads

Install Needed Gems

Note that charlock_holmes has a bug on gentoo, so we have to use this workaround:

git /home/git/gitlab $ bundle config build.charlock_holmes --with-ldflags='-L. -Wl,-O1 -Wl,--as-needed -rdynamic -Wl,-export-dynamic'
  • mysql
git /home/git/gitlab $ bundle install --deployment --without development test postgres
  • postgresql
git /home/git/gitlab $ bundle install --deployment --without development test mysql
Note
If you are having problems installing because of Github's SSL cert, use export GIT_SSL_NO_VERIFY=true


Initialize Database and Activate Advanced Features

git /home/git/gitlab $ bundle exec rake gitlab:setup RAILS_ENV=production
Note
Config files seems to be indentation sensitive, so check your files for typos.

Download and Start the Initscript

At the time of writing, this init script is confirmed to work with Gitlab versions 6, just edit the user and home directory:

root # wget https://gist.github.com/limansky/6330226/raw/f77ae1f417b0574813cf0f6914bd4196b2665cfe/gitlab -O /etc/init.d/gitlab
root #
chmod +x /etc/init.d/gitlab
root #
/etc/init.d/gitlab start
root #
rc-update add gitlab default

Web Frontend

Nginx

Download the official template and activate it:

root # wget http://raw.github.com/gitlabhq/gitlab-recipes/4-1-stable/nginx/gitlab -O /etc/nginx/sites-available/git.domain.tld
root #
ln -s /etc/nginx/sites-available/git.domain.tld /etc/nginx/sites-enabled/


Use your favorite text editor to change the relevant portions:

root # nano /etc/nginx/sites-available/git.domain.tld
...
  listen 0.0.0.0:80 default_server;
  server_name git.domain.tld;
...
root # /etc/init.d/nginx restart

Apache/Passenger

go over to the rails page, and fix up passenger...

You need to deviate on the configuration of /etc/apache2/vhosts.d/00_default_vhost.conf file, to adapt DocumentRoot and <Directory> directives to use /home/gitlab/gitlab/public. Thus, add the following virtual host to manage gitlab :

root # mv /etc/apache2/vhosts.d/00_default_vhost.conf /etc/apache2/vhosts.d/00_default_vhost.conf.example
File/etc/apache2/vhosts.d/00_default_vhost.conf

<IfDefine DEFAULT_VHOST>
Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
        DocumentRoot /home/git/gitlab/public
        <Directory /home/git/gitlab/public>
        </Directory> 
</VirtualHost>
</IfDefine>

dont forget to

root # /etc/init.d/apache2 restart

&&

root # rc-update add apache2 default

Finish Installing

root # usermod -s /sbin/nologin git

Use your favorite web browser to navigate to the new host you set up
If everything loads properly, the installer has made an admin account for you.

git.domain.tld

admin@local.host
5iveL!fe

Testing

Diagnostics

Run this command to get your full diagnostic.

git /home/git/gitlab# bundle exec rake gitlab:env:info RAILS_ENV=production
git /home/git/gitlab#
bundle exec rake gitlab:check RAILS_ENV=production

Push, Pull, Clone

Users to push, pull, clone generate ssh-rsa key.

Using the GitLab web page interface, add your user key to your user, & create new repository.

Many commands will show up, they need to be run on your users computer.

The command 'git push -u origin master' will activate the repository created and allow cloning.

clone using the url the web interface gives you. (replace localhost with IP address, or fully qualified domain name)

user $ git clone git@localhost:user/test.git test


Omniauth

In the file /home/gitlab/gitlab/config/gitlab.yml there's a section that controls login from remote sites such as Google, Twitter, and GitHub. change enabled: false to enabled: true. then scroll down and remove all ## marks from

File/home/gitlab/gitlab/config/gitlab.yml

#    - { name: 'google_oauth2', app_id: 'YOUR APP ID',
#        app_secret: 'YOUR APP SECRET',

and ensure to leave the leading - on the first line.