Nepal on Rails

millisami's rants!

Setup GitLab (Github Clone) Using Vagrant and Chef

Update: Nov 28, 2011: The box that is downloaded via vagrant might not work properly. Here is the box that I’d custom built to have chef pre-installed. You can download it here

This post is Part 1 of the series Rails app with distributed deployment playground

Here we’ll be installing GitlabHQ.

I won’t be showing on how to install Vagrant with VirtualBox here. If you’re not familiar with Vagrant and how to set it up, then first watch the Railscasts 292 and install the Vagrant with VirtualBox.

Then you can start with the following commands in the terminal. First of all, we have to have our own chef-repo to contain the cookbooks.

You can clone my repo or you can use your own or others. Here I’ll be using mine chef-repo

git clone git://

Now, lets start with the gitlabhq setup.

mkdir vagrants
cd vagrants
git clone git://
cd gitlabhq
vagrant init

Modify the Vagrantfile as below do |config| = "lucid32" ""

  config.vm.customize do |vm| = "GitlabHQ"
    vm.memory_size = 384

  config.vm.provision :chef_solo do |chef|
    chef.log_level = :debug
    chef.cookbooks_path = ["~/chef-repo/cookbooks"]
    chef.add_recipe "base"
    chef.add_recipe "rvm::install"
    chef.add_recipe "rvm::ruby_192"

    chef.json = {
      :base => {
        :system_packages => ["tree", "htop", "vim-nox"]

Then from the terminal, run the following commands.

vagrant up
vagrant ssh

Once you login, install these dependencies.

sudo apt-get install -y git-core sqlite3 libsqlite3-dev gitosis libcurl4-openssl-dev python-setuptools

sudo visudo

Add the following line at the VERY BOTTOM of the file, if not at the end, it can be nullified by later entries


Ctrl-X to leave, Y to save your changes. Logout logout and ssh vagrant ssh again to reflect the effect.

Lets install the gem dependencies.

cd /vagrant
rvmsudo gem install bundler --pre

# Seeding the database
RAILS_ENV=production bundle exec rake db:setup
RAILS_ENV=production bundle exec rake db:seed_fu

Write the admin account and its password which we’ve to use later while accessing gitlab.

Administrator account created:

Then, we have to setup the following:

sudo easy_install pygments
sudo echo export RAILS_ENV=production >> ~/.bash_profile
sudo adduser --system --shell /bin/sh --gecos git version control --group --disabled-password --home /home/git git
ssh-keygen -t rsa
sudo -H -u git gitosis-init < ~/.ssh/
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

echo "gem: --no-rdoc --no-ri" > ~/.gemrc
rvmsudo gem install passenger
rvmsudo passenger-install-nginx-module

Creating an Upstart file for nginx

sudo vim /etc/init/nginx.conf

description "Nginx HTTP Server"

start on filesystem
stop on runlevel [!2345]


exec /opt/nginx/sbin/nginx -g "daemon off;"

Restart the VM

sudo shutdown -r now

Verify nginx urnning

sudo initctl list | grep nginx

You should see:

nginx start/running, process 678

…Or use a browser and visit

Open nginx.conf to configure nginx

sudo vim /opt/nginx/conf/nginx.conf

Change the user to ‘vagrant’

Then inside the http {....}, add/replace a server block looking similar to this:

http {

    server {
    listen 80;
    server_name localhost;
    root /vagrant/public;
    passenger_enabled on;

Restart nginx to pick up the changes

sudo service nginx stop; sudo service nginx start

or just

sudo start|stop nginx

Setting up the first repository

  1. Access []( on the HOST machine’s browser
  2. Login in using and 5iveL!fe
  3. Add your HOST key at [](
  4. Create the first project, say (Myproject)
  5. Add a remote. git remote add vagrant-chef git@
  6. Push with tracking branch. git push -u vagrant-chef master

Dealing with the Git and SSH keys gotchas

  1. Added user vagrant to group git since /home/git/repositories directory is owned by git

  2. Did one clone in ~/tmp directory git clone git@localhost:gitosis-admin.git gitosis-copy to add the RSA key to the list of known hosts. So, that when later via browser, the webserver will try to create a new repo. Otherwise you might end up with the infamous 500 error page.

Thats it for this part. Hang-on for the part 2 of the series Rails app with distributed deployment playground