Friday, May 24, 2013

GitLab installation on linux

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Initially designed and developed by Linus Torvalds for Linux kernel development.

Here I will explain how to install,
       
Git - version control system
GitLab - Self hosted Git management software
Gitclient - TortoiseGit

For this I am using a fresh Ubuntu based system and the steps are explained below ..

Install Redis-server

Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

Download the latest package from the link below,

wget http://redis.googlecode.com/files/redis-2.6.13.tar.gz



tar -zxvf redis-2.6.13.tar.gz
cd redis-2.6.13
make
make install

cd src/
./redis-server &      ## Started redis-server and will be listening at port 6379.


Now we are going to install latest Git 1.8.2.3, before that we need to install some dependencies, for that just issue the below command.

apt-get install  build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev gettext openssh-server

In order to receive mail notifications, make sure to install a
mail server,

apt-get install postfix


Now download the Git software from the link below,

wget http://code.google.com/p/git-core/downloads/detail?name=git-1.8.2.3.tar.gz&can=2&q=

tar -zxvf git-1.8.2.3.tar.gz
cd git-1.8.2.3
./configure --prefix=/usr/ --without-tcltk
make
make install


GitLab works on Ruby On Rails, so download and Install ruby,

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz

tar -zxvf ruby-1.9.3-p0.tar.gz
cd ruby-1.9.3-p0
./configure
make
make install


Now Install the gem bundler,

gem install bundler


If you are  getting an error like this,


/usr/local/lib/ruby/1.9.1/yaml.rb:56:in `':

It seems your ruby installation is missing psych (for YAML output).

To eliminate this warning, please install libyaml and reinstall your ruby.

ERROR:  Loading command: install (LoadError)

    cannot load such file -- zlib

ERROR:  While executing gem ... (NameError)

    uninitialized constant Gem::Commands::InstallCommand

Then, (from the ruby install folder)
For yaml support

cd ext/psych

rubyextconf.rb
make
make install

For zlib support

cd ext/zlib

ruby extconf.rb
make
make install

And for openssl support if error promted,
cd ext/openssl
ruby extconf.rb
make
make install

Finally, gem install bundler

Now create git user ..

adduser --disabled-login --gecos 'GitLab' git


Install GitLab shell

GitLab Shell is a ssh access and repository management software developed specially for GitLab.

Login as git
su git
cd /home/git
git clone https://github.com/gitlabhq/gitlab-shell.git  ### Clone gitlab shell
cd gitlab-shell
git checkout v1.4.0                 #### switch to right version


cp config.yml.example config.yml

vim config.yml
change the gitlab_url:              ### Url to gitlab instance. Used for api calls. Should be ends with slash.

Now setup
./bin/install


Installing GitLab

cd /home/git

clone from github

git clone https://github.com/gitlabhq/gitlabhq.git gitlab

cd github
git checkout 5-2-stable    ### Checkout to stable release

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

vim config/gitlab.yml
change the host:
verify the git: bin_path:

cp config/puma.rb.example config/puma.rb

mkdir tmp/pids tmp/sockets public/uploads
chmod 755 log tmp public/uploads -R

Create directory for satellites

mkdir /home/git/gitlab-satellites

Edit user.email according to what is set in gitlab.yml

git config --global user.name "GitLab"
git config --global user.email "gitlab@localhost"


chown git.git /home/git -R

Configure GitLab DB

sudo -u git cp config/database.yml.mysql config/database.yml

vim config/database.yml

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: gitlab
  pool: 5
  username: lab
  password: lab.pass
  port: 3306
  host: localhost

edit this accordingly ..

Install Gems
cd /home/git/gitlab
gem install charlock_holmes --version '0.6.9.4'

sudo -u git -H bundle install --deployment --without development test postgres


Initialise Database,

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production


will show this at last,

Administrator account created:

login.........admin@local.host
password......5iveL!fe

Install the Init Script,

wget https://raw.github.com/gitlabhq/gitlabhq/5-2-stable/lib/support/init.d/gitlab
cp gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab

Start at boot,
update-rc.d gitlab defaults

Check the Application,

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production


System information
System:         Ubuntu 10.04
Current User:   git
Using RVM:      no
Ruby Version:   1.9.3p0
Gem Version:    1.8.25
Bundler Version:1.3.5
Rake Version:   10.0.4

GitLab information
Version:        5.2.0.rc1
Revision:       143a03e
Directory:      /home/git/gitlab
DB Adapter:     mysql2
URL:            http://192.168.2.101
HTTP Clone URL: http://192.168.2.101/some-project.git
SSH Clone URL:  git@192.168.2.101:some-project.git
Using LDAP:     no
Using Omniauth: no

GitLab Shell
Version:        1.3.0
Repositories:   /home/git/repositories/
Hooks:          /home/git/gitlab-shell/hooks/
Git:            /usr/local/bin/git


Run a more thorough check with,

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production


will show an error,
Init script up-to-date? ... no ## neglect it.

Start Your GitLab,
/etc/init.d/gitlab start


Install Nginx

apt-get install nginx


wget https://raw.github.com/gitlabhq/gitlabhq/5-2-stable/lib/support/nginx/gitlab

cat gitlab > /etc/nginx/sites-enabled/default

listen <server-ip>:80;
#server_name YOUR_SERVER_FQDN;  #### comment this line

/etc/init.d/nginx restart

Its done, visit your GitLab http://<server-ip>

log in:

username - admin@local.host
password - 5iveL!fe

Now you are logged in as Administrator. You can create new users and groups.

Every users can create public and private repos and assign a team of members for each projects.

You need to Add you public key to the add key session of your profile for access the repository via ssh ( git@192.168.2.101:publicproject.git )

Linux Clients Side Setup

Install git client, then
Git global setup:
git config --global user.name "Administrator"
git config --global user.email "admin@local.host"

Create Repository

mkdir publicproject
cd publicproject
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@192.168.2.101:publicproject.git
git push -u origin master


Windows Client Side Setup

Download and install msysgit from the link below,
http://msysgit.googlecode.com/files/Git-1.8.1.2-preview20130201.exe

Then install TortoiseGit from the link below,
http://tortoisegit.googlecode.com/files/TortoiseGit-1.8.3.0-64bit.msi

From TortoiseGit Clone existing repo to a directory or Create a directory with a repo url, Add, Commit and Push.

Now login with your user, you can track all your Files, Commits and Diffs ..

Thanks for reading ..

Cheers /-

No comments:

Post a Comment