Redmine + Gitolite integration

I’m a big fan of both Redmine, the project management web application and Git, the distributed version control system.

Recently, I learned that it’s possible to integrate Git into Redmine so that git repositories for a project can be created via the Redmine web interface. This is done using plugins which connect Redmine with git hosting software: either gitosis or more recently, gitolite.

Unfortunately, this is a deeply-confusing process for novices like myself. There are multiple forks of the plugins, long threads in the Redmine forums that discuss various hacks/tweaks to make things work and no one authoritative source of documentation. After much experimentation, this is what worked for me. I can’t guarantee success for you.

My setup
I manage a work server which is a virtual machine running an old version of Ubuntu:

cat /etc/motd
# Linux bioinformatics 2.6.35-31-server #62-Ubuntu SMP Tue Nov 8 14:36:53 UTC 2011 x86_64 GNU/Linux
# Ubuntu 10.10

Redmine version is 1.3.1.stable.8917.

1. Install gitolite

sudo apt-get install gitolite

On my machine, the system user gitolite was created automatically.

2. Create keys for gitolite user and run gl-setup
This is the important part. Ignore everything in the gitolite documentation about creating public keys on a client machine and copying them to the server. All that you want to do is create a public/private key pair on the server for the gitolite user.

sudo su - gitolite
mkdir .ssh
ssh-keygen -t rsa -f .ssh/gitolite_admin_id_rsa
gl-setup ~/.ssh/

3. Copy the gitolite user keys so as the webserver user can read them
My Redmine installation is in /var/www/rails/redmine-1.3, where I have read/write permissions as a normal user. If you don’t, use sudo where required. The webserver user is www-data on my system; some sources of documentation call this user redmine.

cd /var/www/rails/redmine-1.3
mkdir .ssh
sudo cp /var/lib/gitolite/.ssh/gitolite_admin_id_rsa* .ssh/
sudo chown -R www-data.www-data .ssh
sudo chmod 700 .ssh
sudo chmod 600 .ssh/gitolite_admin_id_rsa
sudo chmod 644 .ssh/

4. Install the redmine_git_hosting plugin
Assuming that you are still in the Redmine root directory:

./script/plugin install

Next, edit vendor/plugins/redmine_git_hosting/init.rb as described in the plugin documentation. However, note that you may have to edit the settings again later through the Redmine interface.

Finally, run the migration:

rake db:migrate_plugins RAILS_ENV=production

5. Edit sudoers file
Run visudo and add these lines:

www-data	ALL=(gitolite)	NOPASSWD:ALL
gitolite	ALL=(www-data)	NOPASSWD:ALL

6. Restart and configure Redmine
We’re almost there. Restart Redmine:

sudo service apache restart

Navigate to Administration->Plugins->Redmine Git Hosting Plugin->Configure and double-check the server settings and git user (gitolite).

7. Add keys, projects and repositories
In Redmine you should now be able to:

  1. Navigate to My Account
  2. Add a public key (copy/paste) and give it a name
  3. Create a project (or use an existing project)
  4. Select Git as the option under project->Settings->Repository and save
  5. Click Repository in the project menu and follow the instructions

A git-push from your local repository to the server should complete without error (or asking for a password). On the server, after the first push, you should see the repository in /var/lib/gitolite/repositories and your public key should be written to /var/lib/gitolite/.ssh/authorized_keys.

Remember: just ignore everything in the gitolite documentation about cloning the gitolite-admin repo to a client or adding public keys from a client. The idea here is that everything happens through Redmine, by giving the webserver user (www-data) privileges to add users, keys and repositories.