Skip to Content

What is Gerrit

“Gerrit is a web based code review system, facilitating online code reviews for projects using the Git version control system.” [1] Gerrit allows carrying out code reviews before or after committing it. Therefore, it is a tool that helps to identify possible problems and ensure that code is written in a common way by different developers. It falls into the quality assurance category. [2]

Download Gerrit

Gerrit is distributed as a WAR file. [3] Installation can be done by simply configure and run Gerrit using the embedded Gerrit server (will only work painless under Linux) or make use of the fact that Gerrit is a J2EE application and run it under a servlet container like Tomcat. This document explains how to run Gerrit in Tomcat under Windows. The setup explained in this document is for Tomcat 7, MySQL 5.5 and Windows 7 64bit.

Installation

The official Gerrit homepage contains the necessary information on how to install Gerrit.

Database Configuration

1st step to install Gerrit is to prepare the database. The database used by Gerrit has by default the name ReviewDb. The documentation gives a SQL to run on MySQL server. That SQL should be adjusted to ensure the Gerrit user can log on to the db. For this, run the script once for localhost and once for the name of the computer where Gerrit will run.

CREATE DATABASE ReviewDB;
ALTER DATABASE ReviewDB charset=latin1;
CREATE USER 'gerrit'@'localhost' IDENTIFIED BY 'gerrit';
GRANT ALL ON ReviewDB.* TO 'gerrit'@'localhost';
FLUSH PRIVILEGES;
CREATE USER 'gerrit'@'<hostname>' IDENTIFIED BY 'gerrit';
GRANT ALL ON ReviewDB.* TO 'gerrit'@'<hostname>';
FLUSH PRIVILEGES;


Where <hostname> is the name of the computer.

Gerrit site

Gerrit uses the concept of a site to store configuration for a specific setup. With this, you can run several Gerrit installations on the same computer / tomcat. Think of a nice name like: ciserver. Create a folder with that will serve as gerrit’s home directory. Inside this directory the site will be created.

Gerrit HOME: C:\Users\Tobias\Applications\CIServer\programs\gerrit

Copy the WAR file to Gerrit home directory. Initialize the configuration wizard. [4]

java -jar gerrit.war init -d /path/to/your/gerrit_application_directory

Note: The DB used is MySQL. During the initial configuration Gerrit will create tables and also store the initial configuration needed to make use of the site. For this to work, Gerrit needs access to the DB in form of the MySQL JDBC driver. In case the MySQL driver cannot be downloaded, the script will end with an error.

/wp-content/uploads/2013/06/gerritinstall1_225867.jpg

In that case, download the MySQL JDBC driver and copy it into the lib directory of the site.

Enter the entire configuration for your site. In case something goes wrong, no worry, Gerrit is well educated and uses the parameters entered the last time as new defaults. In the end, Gerrit will give this message, indicating that everything worked fine:

/wp-content/uploads/2013/06/gerritinstall2_225868.jpg

The test if the installation was successful from a DB perspective, check that the table are created:

/wp-content/uploads/2013/06/gerritinstall3_225917.jpg

It is important to note that the table system_config is used by Gerrit to find the location of the site. When run from tomcat, Gerrit checks the column site_path to know where to look for the information.

/wp-content/uploads/2013/06/gerritinstall4_225918.jpg

In case the location of the site changes, you`ll also have to change this value. The Gerrit home directory now looks like:

/wp-content/uploads/2013/06/gerritinstall5_225919.jpg

The directory ciserver contains all the information used by Gerrit:

/wp-content/uploads/2013/06/gerritinstall6_225920.jpg

The etc directory contains the configuration as a plain text file: gerrit.config.

[gerrit]
    basePath = [Githome]
    canonicalWebUrl = http://localhost:8080/gerrit
[database]
    type = mysql
    hostname = localhost
    port = 3309
    database = reviewdb
    username = gerrit
[auth]
    type = LDAP
[ldap]
    server = ldap://localhost
    username = [username]
    accountBase = [base]
    groupBase = [base]
[sendemail]
    smtpServer = localhost
[container]
    user = Tobias
    javaHome = C:\\Program Files\\Java\\jre7
[sshd]
    listenAddress = *:29418
[httpd]
    listenUrl = http://*:8080/
[cache]
    directory = cache

Prepare Gerrit for tomcat

Create a folder named gerrit-2.7 in the Gerrit home directory

/wp-content/uploads/2013/06/gerritinstall7_225921.jpg

Extract the Gerrit WAR file (<gerrit-home>\gerrit-2.7.war) \ to <gerrit-home>\gerrit-2.7. This places the content of the WAR file into a folder that will later be used by Tomcat to run the web application from.

/wp-content/uploads/2013/06/gerritinstall8_225922.jpg

Tomcat configuration

Download Tomcat 7 or use an existing tomcat instance. To make Tomcat deploy Gerrit from the folder location created above, named gerrit.xml needs to be created in the directory <tomcat-home>/conf/Catalina/localhost.

Content of gerrit.xml:

<?xml version="1.0" encoding="utf-8"?>
<Context path="" docBase="<gerrit_home>/gerrit-2.7"/>

This makes Tomcat aware that a web application is available at the above created folder. The application will be deployed under the context /gerrit. Make sure that this matches the canonicalWebUrl defined in gerrit.conf:

canonicalWebUrl = http://localhost:8080/gerrit


Create the DB resource

As Gerrit is configured to use MySQL and a database named ReviewDb, a JDBC resource pointing to the database needs to be created in tomcat. The resource needs to be added to the file <apache-home>/conf/context.xml

<Resource
     name="jdbc/ReviewDb"
     type="javax.sql.DataSource"
     driverClassName="com.mysql.jdbc.Driver"
     username="gerrit"
     password="gerrit"
     url="jdbc:mysql://localhost:3309/ReviewDB?autoReconnect=true"
     auth="Container"
 />

Before the ReviewDb can now be used by Gerrit, the MySQL JDBC driver needs to be made available in Tomcat. Copy the JAR file to the lib directory.

Run Gerrit

Now tomcat is ready to be started and to run Gerrit. Run startup.bat. The console should give you

/wp-content/uploads/2013/06/gerritinstall9_225923.jpg

This means that tomcat found the Gerrit context description and deployed the application. As Gerrit did not throw an error, the application continues to start (cache, SSH). Gerrit can now be access using the URL http://localhost:8080/gerrit

/wp-content/uploads/2013/06/gerritinstall10_225924.jpg

Appendix

Gerrit is not very talk active. This keeps the Tomcat log clean, but makes it hard to find any evidence why the startup failed. To enhance logging messages during startup in Tomcat, create file logging.properties and put it into WEB-INF/classes.

Content of file:

org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = java.util.logging.ConsoleHandler

References

[1] Gerrit home page http://code.google.com/p/gerrit/

[2] http://en.wikipedia.org/wiki/Quality_assurance

[3] http://code.google.com/p/gerrit/downloads/detail?name=gerrit-2.7-rc1.war

[4] http://gerrit-documentation.googlecode.com/svn/Documentation/2.6/install.html

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply