Redmine Git Hosting Setup on Ubuntu 12.04 LTS

Introduction

Redmine Git Hosting is a plugin for Redmine authored by Eric Bishop, further extended by John Kubiatowicz, which integrates the Git SCM system into Redmine’s project management system. At the end of this guide, you will have a server which can, from the Redmine GUI,

  • Create git repositories for projects
  • Serve git repositories via SSH, GIT, and HTTP(S)
  • Add users to git repositories

This guide is a continuation of the one here, which shows how to install and configure Redmine in Ubuntu with Virtualmin.

Step 1: Get Gitolite

Gitolite is in the Ubuntu repositories, so just apt-get it.

$ apt-get install gitolite

Step 2: Configure Gitolite

The gitolite package needs to be reconfigured in order for it to finish setup.

In order for the gitolite setup to work properly, we need to generate a key for the gitolite user before we actually set it up.

$ cd /tmp
$ ssh-keygen -t rsa -f /tmp/id_rsa

Do not give it a passphrase

$ dpkg-reconfigure gitolite

Use the default username and path, and give it /tmp/id_rsa.pub for the “Administrator’s SSH Key”

Copy the RSA keys into the gitolite user’s .ssh folder for safekeeping:

$ cp /tmp/id_rsa* /var/lib/gitolite/.ssh
$ chown gitolite:gitolite /var/lib/gitolite/.ssh/*
$ chmod 600 /var/lib/gitolite/.ssh/id_rsa
$ chmod 644 /var/lib/gitolite/.ssh/id_rsa.pub

Step 3: Configure redmine’s SSH keys

Copy the RSA keys into a place where redmine can handle them:

$ mkdir /usr/share/redmine/.ssh
$ cp /var/lib/gitolite/.ssh/id_rsa* /usr/share/redmine/.ssh/
$ cd /usr/share/redmine/
$ mv .ssh/id_rsa .ssh/gitolite_admin_id_rsa
$ mv .ssh/id_rsa.pub .ssh/gitolite_admin_id_rsa.pub
$ chown www-data:www-data -R .ssh
$ chmod 700 .ssh
$ chmod 600 .ssh/gitolite_admin_id_rsa
$ chmod 644 .ssh/gitolite_admin_id_rsa.pub

Step 4: Install the redmine_git_hosting plugin

Install the plugin

$ cd /usr/share/redmine
$ mkdir public/plugin_assets
$ chown -R www-data:www-data public/plugin_assets
$ chmod -R 777 public/plugin_assets
$ gem install lockfile net-ssh rdoc inifile
$ ./script/plugin install https://github.com/kubitron/redmine_git_hosting.git

Edit the init file at /usr/share/redmine/vendor/plugins/redmine_git_hosting/init.rb
Change ‘httpServer’ to ‘redmine.example.com’
Change ‘gitServer’ to ‘redmine.example.com’
Change ‘gitUser’ to ‘gitolite’

Migrate the databases

$ rake db:migrate_plugins RAILS_ENV=production

Link the plugin assets files

$ cd /usr/share/redmine/public/plugin_assets
$ ln -s ../../vendor/plugins/redmine_git_hosting/assets ./redmine_git_hosting

Step 5: Add www-data to the sudoers file

$ visudo

Add these lines:

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

Step 6: Restart Apache

$ service apache2 restart

Step 7: Configure redmine settings

Log in to redmine and navigate to Administration→Plugins→Redmine Git Hosting Plugin→Configure

Set Automatically Initialize Git Repositories if you want to automatically create a new git repository when you create a project. This conflicts with using redmine for other types of repositories, though, so use it with caution.

You’re done!

Yay, you’re done! You have a fully working project management system, which can integrate with git and provide you with a git repository accessible through read-only git://, SSH, and Smart HTTP. For SSH, public-key authentication is used: you can upload your public key as part of your redmine user profile. For those less inclined to use SSH (for whatever reason), Smart HTTP is also configured by default, and can be logged in with your Redmine user credentials.

If you have any issues, make sure that you restart apache (and with it, Rails):

$ service apache2 restart

before debugging—this has resolved many a configuration issue. Note that unless you have set up a proper SSL certificate, git will refuse to clone from your repository over HTTPS (it gives a TLS error), so just enable Smart HTTP hosting on both HTTP and HTTPS in the Project→Settings→Repositories section.

What’s next?

If you would also like to put together a fully functional SVN hosting solution, check out http://aeturnalus.com/software/svn-repository-management-redmine-ubuntu-12-04/

Note that you will have to resolve conflicts between the two plugins as per http://aeturnalus.com/software/hacking-scm-creator-redmine-git-hosting-cooperate/, but it’s a fairly simple fix.

23 Responses to “Redmine Git Hosting Setup on Ubuntu 12.04 LTS”

  1. ss814

    Hello and thank you for your great tutorial ! The first one that actually worked for me in more than a month.
    Actually, I still have a little problem. After creating my project and repo, I got an alert :

    which I don’t know if I have to execute them on my server or on local. Also the user gitolite requires a password, which I don’t have.

    Could you help me please ?

    Reply
    • ss814

      Excuse me for the typo, here is the alert :

      Repository is empty. Get started by following the instructions below.

      Git Setup:

      Download and Install Git
      git config –global user.name “xxx xxx”
      git config –global user.email [email protected]

      Repository Setup:

      mkdir project
      cd project
      git init
      touch readme.txt
      git add readme.txt
      git commit -m ‘Initializing project repository’
      git remote add origin [email protected]:project.git
      git push -u origin master

      Existing Git Repo?

      cd existing_git_repo
      git remote add origin [email protected]:project.git
      git push -u origin master

      Also, I enabled the option : “Automatically Initialize Git Repositories For New Projects”.

      Thanks in advance.

      Reply
      • Robert Ying

        With regards to the alert:

        Redmine will initialize a git repository for you, but the repository won’t have any files in it. You need to add a few files yourself. The instructions given (that you copied in) explain how you would go about adding in some files. In particular,

        $ git config –global user.name “xxx xxx”
        $ git config –global user.email [email protected]
        $ mkdir project
        $ cd project
        $ git init
        $ touch readme.txt
        $ git add readme.txt
        $ git commit -m ‘Initializing project repository’
        $ git remote add origin [email protected]:project.git
        $ git push -u origin master
        

        are the instructions for creating a new repository from the command line and adding a single file.

        You can execute these commands from any computer, as long as you’ve set up the private/public keys properly. Alternatively, instead of

        $ git remote add origin [email protected]:project.git
        

        You can add the Smart HTTP URL given in the project overview, which will use your Redmine username and login.

        Regarding the password for the user gitolite,

        The installation will not generate a password for gitolite, if you want to log in from the server side, use the command

        $ su gitolite
        

        from root, which will bypass the need for a password.

        From your own computer, if you encounter a password when trying to access the repository, it means that you haven’t set up your public keys properly. Add your public key in your account settings in Redmine, or use the Smart HTTP method.

        For the Smart HTTP method, remember that the HTTPS version will not work if you don’t have a valid SSL certiifcate for your server, so enable the HTTP access method as well in the project repository settings and use that link instead.

        Reply
  2. Conrad, this is great! I’ve been getting into git a lot lleaty myself and I love how I can have a faster workflow with git by having part of the IDE.Big question though is there a way to do a push origin master from inside Flash Builder? I know I can do commits and pushes, but I want to update the remote repository and it kinda sucks I have to go back to the terminal window to do it.Maybe you’ve figured out how to do this within Flash Builder as well?Keep up the good work!

    Reply
  3. Hi!! excellent post!!!!

    I have a problem when try to push, in the client terminal show:


    remote: Empty compile time value given to use lib at hooks/update line 6
    remote: Use of uninitialized value in require at hooks/update line 7.
    remote: Can't locate Gitolite/Hooks/Update.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at hooks/update line 7.
    remote: BEGIN failed--compilation aborted at hooks/update line 7.
    remote: error: hook declined to update refs/heads/master

    Do you have any idea to solve this?

    Thanks!!!!

    Reply
  4. Richard Zhao

    I have followed the this and the previous one to install Redmine. I can see “Redmine Git Hosting Plugin” in plugins.

    However once I go to configure, I get the following error:


    Internal error

    An error occurred on the page you were trying to access.
    If you continue to experience problems please contact your Redmine administrator for assistance.

    If you are the Redmine administrator, check your log files for details about the error.

    Any idea?

    Reply
    • Check the Redmine production.log file. You may see an error about access denied to /something/redmine/vendor/plugins/redmine_git_hosting/bin. I needed to give the web server user access to read this directory. That fixed the problem for me.

      Reply
  5. hi
    thx your post.
    but I get problem when I do “git push -u origin master”
    gitolite ask me password

    gitolite Administrator’s SSH Key is set
    user pubkey is set

    how to check config, I tried my best.

    Reply
    • same issue here, whenever I try to push or clone I get asked for gitolite password! what’s wrong? thanks

      Reply
  6. somnambula

    “Step 5: Add www-data to the sudoers file” Do you understand what you wrote?

    Reply
    • Robert Ying

      Wow, it’s been a while since I looked at this. The sudoers file controls whether a user can act as another user for the purposes of a given command, i.e. sudo -u [username]. In this case, you need to give your webserver user (www-data) the ability to execute commands as your git server user (gitolite), and vice versa. This is necessary because these two users are accessing a shared system, and are configured separately.

      Note that neither www-data nor gitolite have the ability to sudo as root.

      Reply
  7. Thanks for the great walkthrough. I managed to setup Redmine and GIT as outlined in your blog post. I am now struggling with the access control. As of now, I can clone any new repository I create with Redmine using the http://…repository.git URL, without providing any credentials. Is there a way to tell Redmine to only pass-through certain authenticated users?

    Reply

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>