Quote:
|
This tutorial explains the installation and configuration of the Gerrit code review system . |
Quote:
|
Gerrit is a web based code review system, facilitating online code reviews for projects using the Git version control system. The user interface of Gerrit is based on Google Web Toolkit and its Git implementation is based on JGit. A contributor can use Gerrit to suggest a code change. Other developers can review the code change and suggest improvements. If a Gerrit change request needs improvement, it is possible to update it with a new set of changes. Once the suggested changes are accepted by the reviewers, they can be applied via Gerrit to the underlying Git repository. |
Gerrit v2.10 online documentation:
You find detailed information about Gerrit at: Gerrit Code Review - A Quick Introduction.
- Installation of Gerrit
Packages Requirements - Initialize the Site
Create Directory
Download Gerrit
Install Gerrit
Setup the database and user - Troubleshooting
Plugins
GitHub authentication
Gravatar Provider Plugin
Delete Project Plugin - Themes
- TIPS
Quote:
|
Installation of Gerrit |
Install Java 1.7
Code:
sudo apt-get install openjdk-7-jreCode:
sudo update-alternatives --config javaCode:
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-6-oracle/jre/bin/java 67 auto mode
1 /usr/lib/jvm/java-6-oracle/jre/bin/java 67 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
* 3 /usr/lib/jvm/java-7-oracle/jre/bin/java 66 manual modeCode:
java -version
java version "1.7.0_21"
...Code:
sudo apt-get install gitwebInitialize the Site
1. Create Directory
you can create the directory wherever you want but i will use global path
Code:
mkdir ~/gerrit/Code:
cd ~/gerrit/Download the latest Gerrit release from Gerrit download page. The download is a
Code:
.warCode:
wget https://gerrit-releases.storage.googleapis.com/gerrit-2.10-rc0.warSetup the database and user
Code:
CREATE USER 'gerrit'@'localhost' IDENTIFIED BY 'yourpassword';
CREATE DATABASE reviewdb;
GRANT ALL ON reviewdb.* TO 'gerrit'@'localhost';
FLUSH PRIVILEGES;
exit;Its time to run the initialization
Code:
java -jar gerrit*.war initCode:
java -jar gerrit*.war init -d ~/gerrit/subfolderTable 1. Gerrit setup options
Location of Git repositories
Location of Git repositories, default is the
Code:
gitDatabase server type
Gerrit supports several databases, by default it uses a preconfigured H2 database, but we will use mysql
Listen on port
Allows you to configure the port Gerrit is listening to, Gerrit by default listens on port 29418 for SSH access and on port 8080 for web access. This can be changed if the ports are already used.
Authentication method
The easiest way of configuring access to Gerrit is to use Github instead of OpenID Single Sign-on
Processing 2. Gerrit setup options
Code:
Setting up gerrit (2.10-rc0) ...
Starting Gerrit Code Review : gerrit
No Gerrit site found. Will Initialize Gerrit first...
*** Gerrit Code Review 2.10
***
Create '/root/gerrit/review_site' [Y/n]?
*** Git Repositories
***
Location of Git repositories [git]:
*** SQL Database
***
Database server type [H2/?]: mysql
Gerrit Code Review is not shipped with MySQL Connector/J 5.1.10
** This library is required for your configuration. **
Download and install it now [Y/n]?
Downloading http://repo2.maven.org/maven2/mysql/mysql-connector-java/5.1.10/mysql-connector-java-5.1.10.jar ... OK
Checksum mysql-connector-java-5.1.10.jar OK
Server hostname [localhost]:
Server port [(MYSQL default)]:
Database name [reviewdb]:
Database username [gerrit2]: gerrit
gerrit2's password : yourpassword
confirm password : yourpassword
*** User Authentication
***
Authentication method [OPENID/?]: http
Get username from custom HTTP header [y/N]? y
SSO logout URL :
*** Email Delivery
***
SMTP server hostname [localhost]: smtp.gmail.com
SMTP server port [(default)]: 587
SMTP encryption [NONE/?]: TLS
SMTP username : yourproject@gmail.com
SMTP password : you_password
*** Container Process
***
Run as [gerrit]:
Java runtime [/usr/lib/jvm/java-7-oracle/jre]: /usr/lib/jvm/java-7-oracle/jre
Copy gerrit.war to /root/gerrit/bin/gerrit.war [Y/n]? Y
Copying gerrit.war to /root/gerrit/bin/gerrit.war
*** SSH Daemon
***
Listen on address[*]:
Listen on port [29418]:
Gerrit Code Review is not shipped with Bouncy Castle Crypto v144
If available, Gerrit can take advantage of features
in the library, but will also function without it.
Download and install it now [Y/n]?
Downloading http://www.bouncycastle.org/download/bcprov-jdk16-144.jar ... OK
Checksum bcprov-jdk16-144.jar OK
Generating SSH host key ... rsa... dsa... done
*** HTTP Daemon
***
Behind reverse proxy [y/N]? y
Proxy uses SSL (https://) [y/N]? n
Listen on address[*]:
Listen on port [8081]:
Canonical URL [http://review.probam.net/]: https://your-domain.com/Code:
~/gerrit/bin/gerrit.sh startTroubleshooting:
some time you will facing some issues and you got FAILD when trying to start Gerrit
"gc.startTime" is not configured
Code:
INFO com.google.gerrit.server.config.ScheduleConfig : gc schedule parameter "gc.startTime" is not configuredExamples:
Code:
[gc]
startTime=Fri 12:00
interval =2 dayCode:
com.google.gerrit.server.cache.h2.H2CacheFactory : Enabling disk cache /.../cacheCode:
java -jar gerrit*.war reindexPlugins :
built-in plugins you can setup during installation
- commit-message-length-validator v2.10-rc0
- download-commands v2.10-rc0
- replication v2.10-rc0
- reviewnotes v2.10-rc0
- singleusergroup v2.10-rc0
Additional Plugins (pre-compiled) we going to install them
- github 2.10-SNAPSHOT (github-oauth && github-plugin)
- gravatar-avatar-provider v2.9-rc1-315-g375f3bf
- deleteproject v2.9-rc2-619-g4afa3f5
GitHub authentication
The Gerrit GitHub plugin can be found under the Gerrit plugins/github repository on https://gerrit-review.googlesource.c...plugins/github. It is open source under the Apache 2.0 license and can be cloned and built using the Java 6 JDK or higher and Maven.
Download (github-oauth*.jar, the GitHub OAuth library for authenticating Gerrit users)
Install the GitHub OAuth filter into the Gerrit libraries (/lib under the Gerrit site directory)
The GitHub OAuth JAR file needs to copied to the Gerrit /lib directory; this is required to allow Gerrit to use it for filtering all HTTP requests and enforcing the GitHub three-step authentication process:
Download (github-plugin*.jar, the Gerrit plugin for integrating with GitHub repositories and pull requests)
Install the GitHub Plugin into the Gerrit plugins (/plugins under the Gerrit site directory)
The GitHub plugin includes the additional support for the overall configuration, the advanced GitHub repositories replication, and the integration of pull requests into the Code Review process.
Register Gerrit as a GitHub OAuth application
Before going through the Gerrit init, we need to tell GitHub to trust Gerrit as a partner application. This is done through the generation of a ClientId/ClientSecret pair associated to the exact Gerrit URLs that will be used for initiating the 3-step OAuth authentication.
We can register a new application in GitHub through the URL https://github.com/settings/applications/new, where the following three fields are requested:
- Application name : It is the logical name of the application authorized to access GitHub, for example, Gerrit.
- Main URL : The Gerrit canonical web URL used for redirecting to GitHub OAuth authentication, for example, https://myhost.mydomain:port.
- Callback URL : The URL that GitHub should redirect to when the OAuth authentication is successfully completed, for example, https://myhost.mydomain:port/#/.
Running Gerrit init to configure GitHub OAuth
Code:
$ ~/gerrit/bin/gerrit.sh stop
Stopping Gerrit Code Review: OK
$ cd /opt/gerrit
$ java -jar gerrit.war init
[...]
*** User Authentication
***
Authentication method []:
HTTP RETURN
Get username from custom HTTP header [Y/n]?
Y RETURN
Username HTTP header []:
GITHUB_USER RETURN
SSO logout URL :
/oauth/reset RETURN
*** GitHub Integration
***
GitHub URL [https://github.com]:
RETURN
Use GitHub for Gerrit login ? [Y/n]?
Y RETURN
ClientId []:
384cbe2e8d98192f9799 RETURN
ClientSecret []:
f82c3f9b3802666f2adcc4 RETURN
Initialized ~/gerritCode:
~/gerrit/bin/gerrit.sh restartGerrit is now fully configured to register and authenticate users through GitHub OAuth. When opening the browser to access any Gerrit web pages, we are automatically redirected to the GitHub for login.
The best part in this tutorial you will able to open Gerrit pages for anonymous users !!
(put in etc/gerrit.config)
Code:
[auth]
type=HTTP
httpHeader=GITHUB_USER
httpDisplayNameHeader=GITHUB_NAME
httpEmailHeader=GITHUB_EMAIL
loginUrl=/login
loginText=GitHub Sign-in
registerPageUrl=/plugins/github-plugin/static/account.html
gitBasicAuth=trueCheck Installed Plugins :
Code:
ssh <user>@<host> -p29418 gerrit plugin lsCode:
ssh <user>@<host> -p29418 gerrit plugin install -n gravatar.jar \
http://ci.gerritforge.com/view/Plugins-master/job/Plugin_gravatar_master/lastSuccessfulBuild/artifact/gravatar.jarCode:
ssh <user>@<host> -p29418 gerrit plugin install -n delete-project.jar \
http://ci.gerritforge.com/view/Plugins-master/job/Plugin_delete-project_master/lastSuccessfulBuild/artifact/delete-project.jarThemes :
Code:
[theme]
backgroundColor=FCFEEF
textColor=000000
trimColor=D4E9A9
selectionColor=FFFFCC
topMenuColor=D4E9A9
changeTableOutdatedColor=F08080
[theme "signed-in]
backgroundColor=FFFFFFif you are using gerrit on remote server and you need to work with Gerrit remotely , you can enable allowRemoteAdmin
Code:
[plugins]
allowRemoteAdmin=true;- http://gerrit-review.googlesource.com/Documentation/
- https://www.packtpub.com/books/conte...-gerrit-github
- http://www.vogella.com/tutorials/Gerrit/article.html
Regards,
Hany alsamman