Pages

Saturday, April 2, 2011

Its time to have some bug tracking tools - Installing Trac

We're in the stage where simple notes.txt isn't enough to track our project. I think we need a better bug/feature tracking tools. So, I'm going hunting for a few of the common bug tracking tools that's available on the market.

I narrow down my choice into two, Jira and Trac. I've used Bugzilla before, but it never clicked with me. And also Bugzilla and Mantis have their own horror story. Jira actually caught my attention with the $10 starter pack. But the next packet, 25 user for $1,200 is way out of my league.

So finally my decision goes to Trac. It was simple enough. People won't be distracted or hinder by the many fields they need to fill to submit a bug. Both Jira and Trac support mercurial. Just perfect. And although simple and minimalistic Trac have two very cool feature :
  • Timeline – shows current and past project events in order
  • Roadmap – shows the upcoming milestones to be achieved in the project

The only drawback in Trac is the interface, it has its way to annoy you when you look at it too long :P

Installation

I wont be installing this from scratch. I will be installing this at the last state of  my infastructure post.

You can install Trac with mercurial support using this three simple steps :
sudo apt-get install python-setuptools
sudo apt-get install python-genshi
sudo apt-get install trac-mercurial

But when i write this blog post the trac version in ubuntu repository is 0.11.7. Since i want to use trac 0.12, I'll be doing some of the things manually.

First I installed the setup tools using apt-get.
sudo apt-get install python-setuptools

Then I'm using setuptools easy_install to install Genshi and Trac
sudo easy_install Genshi
sudo easy_install Trac

And for the trac-mercurial plugin, you need to check out and build it manually. But first you need to install subversion.

sudo apt-get install subversion

check out the code, build the egg, and install it
mkdir trac-plugin
cd trac-plugin
svn co http://svn.edgewall.com/repos/trac/plugins/0.12/mercurial-plugin
cd mercurial-plugin
python setup.py bdist_egg
sudo easy_install dist/TracMercurial-0.12.0.28dev_r10657-py2.6.egg

After finished installing Trac, lets do some test. But first you need to create a database for Trac in mysql. Using mysql root user :
-- It is better to set the innodb as the default storage engine
mysql> create database trac;
mysql> grant all privileges on trac.* to 'trac'@localhost identified by 'mypassword';
mysql> flush privileges

Trying logging out and then loggin in using the new account.

Next, you need to install python library for connecting to mysql from python.
sudo apt-get install python-mysqldb

And the basic setup is complete.

Create A Trac Project

Now we need to create a trac project. Since i want it to be integrated with my mercurial server. I've created the project in my hguser account.
sudo su - hguser

create the directory for your project
mkdir -p ~/trac/myproject

init the project
trac-admin ~/trac/myproject initenv

If you're having a problem with trac-admin not in your path, try logging out and then relogin to your system.

The initenv command will ask some question. On the database connection string input this :
mysql://username:password@hostname:port/databasename

After finish with the environment, we need to modify the configuration file to support mercurial.
vi /home/hguser/trac/myproject/conf/trac.ini

modify the file with the line below :

[components]
tracext.hg.* = enabled[repositories]

[trac]
repository_dir = path_to_default_repository
repository_type = hg


You can start trac server and see the result by accessing http://yourserver:8000/myproject

tracd --port 8000 ~/trac/myproject

Integrating with apache

Mod_python is dead, so I'm choosing mod_wsgi to integrate trac with my apache server. First you need to install mod wsgi and restart the apache2 server
sudo apt-get install libapache2-mod-wsgi
sudo service apache2 restart

sudo to the hguser and create egg-cache directory under ~/trac/myproject

to create the wsgi file you can create it manually, or use the trac-admin deploy method like below :
trac-admin trac/myproject deploy /tmp/deploy

it will create the .cgi .fcgi .wsgi file under the cgi-bin directory. Then you can copy the file to the real cgi-bin directory
sudo mkdir /usr/lib/cgi-bin/trac
sudo cp /tmp/deploy/cgi-bin/trac.wsgi /usr/lib/cgi-bin/trac/myproject.wsgi
sudo chmod +x /usr/lib/cgi-bin/trac/myproject.wsgi

now you need to add the new location to your apache configuration file. Usually it's under site-enabled/000-default-file . I'm using port 8008 for this purpose but later will create a subdomain for trac :


ServerAdmin webmaster@localhost
DocumentRoot /var/www

#WSGI scrip for trac
WSGIScriptAlias /trac/myproject /usr/lib/cgi-bin/trac/myproject.wsgi

        <Directory /home/hguser/trac/myproject>
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Allow from all
        </Directory>

After restarting apache, you should be able to access your trac installation in http://yourlocalhost:8008/trac/myproject

While trying to integrate trac with apache, I keep stumbling to an error that said :

TimeoutError: Unable to get database connection within 0 seconds. (TracError: Database "/usr/www/trac/db/trac.db" not found.)

I'm using mysql so trac shouldn't need to create the embedded db. It seems that trac couldn't read the content of my trac.ini files. It turn out that I've stumble to this bug. As a work around I added group read-write permission ,
sudo chmod g+rw ~/trac/myproject/conf/trac.ini
but i wonder, will this create a security problem. Since the trac.ini contains the db access URL ?

Configuring Authentication

To add authentication method, I just added my mercurial hgusers file

        <location /trac/myproject/login>
                AuthType Basic
                AuthName "Trac"
                AuthUserFile /home/hguser/hgusers
                AuthGroupFile /home/hguser/hggroups
                Require group myproject
        </Location>

To be able to use the admin web page you need to add admin privileges to your user
trac-admin ~/trac/myproject permission add frodo TRAC_ADMIN

it is recomended to install the AccountManager plugin. To install it run

sudo easy_install https://trac-hacks.org/svn/accountmanagerplugin/trunk

and then go to the admin tab > plugin , and enable the features

Removing anonymous user access

You can disallow anonymous user access by


trac-admin ~trac/myproject permission remove anonymous '*'

No comments: