HowTo configure Redmine for advanced git integration » History » Version 2

Felix Schäfer, 2010-07-13 12:55
Install grack

1 1 Felix Schäfer
h1. HowTo configure Redmine for advanced git integration
2 1 Felix Schäfer
3 1 Felix Schäfer
h2. Scope
4 1 Felix Schäfer
5 1 Felix Schäfer
This HowTo explains how to serve git repositories on apache through the http-based "git-smart-http protocol":http://progit.org/2010/03/04/smart-http.html introduced in git 1.6.6. The git-smart-http offers various advantages over ssh or git-based access: you can use redmine access control as-is, no need for extra ssh keys or whatnot, you can secure it through SSL as needed, and there's generally less problems with firewalls and https/https ports than exist with ssh and git ports. git-smart-http also doesn't have some of the drawbacks of its "dumb" predecessor, as it doesn't require any complex DAV setup.
6 1 Felix Schäfer
7 1 Felix Schäfer
This HowTo is mainly written from memory and was conducted on a setup which was already serving [[Repositories_access_control_with_apache_mod_dav_svn_and_mod_perl|svn repositories integrated with redmine]], so it might be possible that I forgot some things or take them for granted. This is a wiki page, feel free to correct or amend anything you find lacking :-)
8 1 Felix Schäfer
9 1 Felix Schäfer
h2. Prerequisites
10 1 Felix Schäfer
11 1 Felix Schäfer
* Apache with mod_perl (access control)
12 1 Felix Schäfer
* git (version at least 1.6.6)
13 1 Felix Schäfer
* A way to serve git-smart-http
14 1 Felix Schäfer
** mod_cgi (or mod_cgid) if you want to use the stock "git-http-backend":http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html
15 1 Felix Schäfer
** a rack server if you want to use "grack":http://github.com/schacon/grack (basically a rack wrapper around the right git commands)
16 1 Felix Schäfer
17 1 Felix Schäfer
You should already have a rack server to run redmine, and that's why I chose grack as the backend and which I will describe in this tutorial. Using the stock git-http-backend should be quite straightforward though.
18 2 Felix Schäfer
19 2 Felix Schäfer
h2. Install grack
20 2 Felix Schäfer
21 2 Felix Schäfer
My rack server of choice is "passenger":http://modrails.com/ and it is already configured on my system. As this is not within the scope of this HowTo, please refer to the "passenger documentation":http://modrails.com/documentation.html or to the passenger installation guide from your distribution.
22 2 Felix Schäfer
23 2 Felix Schäfer
Fetch grack from its "github repository":http://github.com/schacon/grack, I checked out mine to @/var/www/git.myhost.com@:
24 2 Felix Schäfer
25 2 Felix Schäfer
<pre><code class="bash">git http://github.com/schacon/grack.git /var/www/git.myhost.com</code></pre>
26 2 Felix Schäfer
27 2 Felix Schäfer
Edit the @config.ru@ file and adapt it to your local configuration. @project_root@ must contain the path to the directory containing your git repositories, @git_path@ must obviously contain the path to the git, mine looks like this (on gentoo):
28 2 Felix Schäfer
29 2 Felix Schäfer
<pre><code class="ruby">$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/lib')
30 2 Felix Schäfer
31 2 Felix Schäfer
use Rack::ShowExceptions
32 2 Felix Schäfer
33 2 Felix Schäfer
require 'lib/git_http'
34 2 Felix Schäfer
35 2 Felix Schäfer
config = {
36 2 Felix Schäfer
  :project_root => "/var/git/git.myhost.com",
37 2 Felix Schäfer
  :git_path => '/usr/libexec/git-core/git',
38 2 Felix Schäfer
  :upload_pack => true,
39 2 Felix Schäfer
  :receive_pack => true,
40 2 Felix Schäfer
}
41 2 Felix Schäfer
42 2 Felix Schäfer
run GitHttp::App.new(config)</code></pre>
43 2 Felix Schäfer
44 2 Felix Schäfer
There's a little more work to do here to get passenger to work with this, you will need to create the directories @public@ and @tmp@ in the grack directory. Please also be aware that in the standard configuration, passenger will run the grack application with the same user and group owning the @config.ru@ file. This user must have read- and write-access as needed to the git repositories!
45 2 Felix Schäfer
46 2 Felix Schäfer
The last step is to configure an apache vhost to serve the application:
47 2 Felix Schäfer
48 2 Felix Schäfer
<pre><code class="apache"><VirtualHost yo.ur.i.p:80>
49 2 Felix Schäfer
    ServerName git.myhost.com
50 2 Felix Schäfer
51 2 Felix Schäfer
    ServerAdmin root@myhost.com
52 2 Felix Schäfer
    DocumentRoot "/var/www/git.myhost.com/public"
53 2 Felix Schäfer
54 2 Felix Schäfer
    <Directory "/var/www/git.myhost.com/public">
55 2 Felix Schäfer
        Options None
56 2 Felix Schäfer
        AllowOverride None
57 2 Felix Schäfer
        Order allow,deny
58 2 Felix Schäfer
        Allow from all
59 2 Felix Schäfer
    </Directory>
60 2 Felix Schäfer
</VirtualHost></code></pre>
61 2 Felix Schäfer
62 2 Felix Schäfer
At this point, if you have a repository in @/var/git/git.myhost.com/myrepo@, you should be able to access it through @http://git.myhost.com/myrepo@, for example @git ls-remote http://git.myhost.com/myrepo@ should show you some information about the repository.