Gerrit: различия между версиями

Материал из noname.com.ua
Перейти к навигацииПерейти к поиску
Строка 53: Строка 53:
 
First step is get deb package for ubuntu and install it. <BR>
 
First step is get deb package for ubuntu and install it. <BR>
 
Deb package is configured in wrong way, so we need only install is, stop gerrit service and configure it before continue.
 
Deb package is configured in wrong way, so we need only install is, stop gerrit service and configure it before continue.
  +
===Download and install===
 
 
* Download gerrit deb package
 
* Download gerrit deb package
 
<PRE>
 
<PRE>
Строка 63: Строка 63:
 
dpkg -i gerrit-2.11.8-1.noarch.deb
 
dpkg -i gerrit-2.11.8-1.noarch.deb
 
</PRE>
 
</PRE>
  +
===Cleanup data created by post-install===
 
 
* Remove data from $site_dir. <BR>
 
* Remove data from $site_dir. <BR>
 
By-default installer use /var/gerrit as $site_dir, but can be changed in /etc/default/gerritcodereview file
 
By-default installer use /var/gerrit as $site_dir, but can be changed in /etc/default/gerritcodereview file
Строка 97: Строка 97:
 
rm -rf ./cache ./data ./db ./git ./index ./lib ./logs ./static ./tmp
 
rm -rf ./cache ./data ./db ./git ./index ./lib ./logs ./static ./tmp
 
</PRE>
 
</PRE>
  +
===Configure gerrit====
 
 
Before initialize we need to prepare gerrit confg files. All config files are stored in /etc/gerrit (which is symbolic link to /var/gerrit/etc)
 
Before initialize we need to prepare gerrit confg files. All config files are stored in /etc/gerrit (which is symbolic link to /var/gerrit/etc)
 
<BR>
 
<BR>

Версия 16:56, 24 марта 2016

Gerrit

Gerrit is a free, web-based collaborative code review tool that integrates with Git. It has been developed at Google by Shawn Pearce (co-author of Git, founder of JGit) for the development of the Android project.

Starting from a set of patches for Rietveld, it became a fork and evolved into a full blown project when ACL patches wouldn't be merged into Rietveld by its author, Guido van Rossum.

Originally written in Python like Rietveld, it is now written in Java (Java EE Java Servlet) with SQL since version 2.


Installation

Gerrit installation and configuration is complicated so it will be described as detailed as it possible.

Prerequisites

By-default gerrit use HB database, but MySQL also supported and we will use it. Also, Java is required (already installed). For demo we install MySQL on the same server but of course it is possible to use external MySQL / Postres /Oracle
Also git is required for gerrit

Install git

apt-get  install git git-man git-review  liberror-perl

Install MySQL

apt-get  install mysql-server-5.6  mysql-common-5.6  mysql-client-core-5.6  mysql-client-5.6  mysql-source-5.6  mysql-testsuite-5.6 

Configure empty root password. (for demo only!)
Gerrit1.png

Check MySQL

# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 5.6.28-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

deb package

First step is get deb package for ubuntu and install it.
Deb package is configured in wrong way, so we need only install is, stop gerrit service and configure it before continue.

Download and install

  • Download gerrit deb package
wget  http://deb.gerritforge.com/dists/gerrit/contrib/binary-amd64/gerrit-2.11.8-1.noarch.deb
  • Install downloaded package.
dpkg -i gerrit-2.11.8-1.noarch.deb

Cleanup data created by post-install

  • Remove data from $site_dir.

By-default installer use /var/gerrit as $site_dir, but can be changed in /etc/default/gerritcodereview file

cat /etc/default/gerritcodereview
GERRIT_SITE=/var/gerrit

deb installer creates and initialized gerrit with wrong parameter, so we need to delete all folders except bin

cd /var/gerrit
ls -1
bin
cache
data
db
etc
git
index
lib
logs
plugins
static
tmp

Remove dirs we do not need:

rm -rf  ./cache  ./data   ./db  ./git  ./index  ./lib  ./logs  ./static  ./tmp

Configure gerrit=

Before initialize we need to prepare gerrit confg files. All config files are stored in /etc/gerrit (which is symbolic link to /var/gerrit/etc)
There are 2 configuration files:

  • gerrit.config
  • secure.config

gerrit.config

gerrit.config is main gerrit configuration file.

[gerrit]
	basePath = git
	canonicalWebUrl = http://192.168.56.102:8081/r/

[database]
	type = mysql
	database = gerrit
	hostname = localhost
	username = gerrit
	password = gerritpass

[auth]
	type = LDAP

[sendemail]
	smtpServer = localhost

[sshd]
	listenAddress = *:29418

[httpd]
	listenUrl = proxy-http://127.0.0.1:8081/r/

[cache]
	directory = cache

[cache "ldap_groups"]
        maxAge = 1 min

[cache "ldap_usernames"]
        maxAge = 1 min

[cache "accounts"]
        maxAge = 5 min

[cache "accounts_byemail"]
        maxAge = 5 min

[cache "diff"]
        maxAge = 5 min

[cache "groups"]
        maxAge = 5 min

[cache "projects"]
        maxAge = 5 min

[cache "sshkeys"]
        maxAge = 5 min

[receive]
	enableSignedPush = false

[container]
	user = gerrit
	javaHome = /usr/lib/jvm/java-7-openjdk-amd64/jre

[plugins]
    allowRemoteAdmin = true

[ldap]
	server = ldap://127.0.0.1
	username = cn=admin,dc=demo
	password = r00tme
	accountBase = ou=cicd,dc=demo
        accountFullName = ${givenName} ${SN}
	accountEmailAddress = mail
	groupBase = ou=cicd,dc=demo
        groupPattern = (cn=${groupname})
        groupMemberPattern = (memberUid=${username})
        groupQuery = true
        groupsVisibleToAll = true
        localUsernameToLowerCase = true

[index]
	type = LUCENE

[download]
        command = checkout
        command = cherry_pick
        command = pull
        command = format_patch
        scheme = ssh
        scheme = http
  • gerrit: General gerrit options
    • canonicalWebUrl: Canonical url. All links in gerrit are related to this URL
  • database: Database-related options like host, password, username.
  • auth: gerrit auth method (we use LDAP)
  • sshd: ssh listener address
  • httpd: httpd listener address, proxy-http configured because we will use apache as proxy for gerrit. Using apache is optional.
  • cache: Cache options.
  • container: Java options
  • plugins: Allow remote plugin management.
  • ldap: Ldap options
    • username = cn=admin,dc=demo, LDAP admin username
    • password = r00tme LDAP admin password
    • accountBase = ou=cicd,dc=demo Organization unit where to search for accounts
    • groupBase = ou=cicd,dc=demo OU for groups
    • groupMemberPattern = (memberUid=${username}) Group membership query.



As you can see in config file, we need mysql database configured:

CREATE DATABASE gerrit;
GRANT ALL on gerrit.* to 'gerrit'@'localhost' IDENTIFIED BY 'gerritpass';
GRANT ALL on gerrit.* to 'gerrit'@'%' IDENTIFIED BY 'gerritpass';
FLUSH PRIVILEGES;


=Init

Next step is Re-Initialize Gerrit with LDAP and MySQL

java -jar /var/gerrit/bin/gerrit.war  init -d  /var/gerrit


java -jar /var/gerrit/bin/gerrit.war  init -d  /var/gerrit
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore

*** Gerrit Code Review 2.11.8
***


*** Git Repositories
***

Location of Git repositories   [git]:

*** SQL Database
***

Database server type           [mysql]:

Gerrit Code Review is not shipped with MySQL Connector/J 5.1.21
**  This library is required for your configuration. **
Download and install it now [Y/n]? Y
Downloading http://repo2.maven.org/maven2/mysql/mysql-connector-java/5.1.21/mysql-connector-java-5.1.21.jar ... OK
Checksum mysql-connector-java-5.1.21.jar OK
Server hostname                [localhost]:
Server port                    [(mysql default)]:
Database name                  [gerrit]:
Database username              [gerrit]:
gerrit's password              :
              confirm password :

*** Index
***

Type                           [LUCENE/?]:

The index must be rebuilt before starting Gerrit:
  java -jar gerrit.war reindex -d site_path

*** User Authentication
***

Authentication method          [LDAP/?]:
LDAP server                    [ldap://127.0.0.1]:
LDAP username                  [cn=admin,dc=demo]:
cn=admin,dc=demo's password    :
              confirm password :
Account BaseDN                 [ou=cicd,dc=demo]:
Group BaseDN                   [ou=cicd,dc=demo]:

*** Review Labels
***

Install Verified label         [y/N]?

*** Email Delivery
***

SMTP server hostname           [localhost]:
SMTP server port               [(default)]:
SMTP encryption                [NONE/?]:
SMTP username                  :

*** Container Process
***

Run as                         [gerrit]:
Java runtime                   [/usr/lib/jvm/java-7-openjdk-amd64/jre]:
Upgrade /var/gerrit/bin/gerrit.war [Y/n]? n

*** SSH Daemon
***

Listen on address              [*]:
Listen on port                 [29418]:

*** HTTP Daemon
***

Behind reverse proxy           [Y/n]?
Proxy uses SSL (https://)      [y/N]?
Subdirectory on proxy server   [/r/]:
Listen on address              [127.0.0.1]:
Listen on port                 [8081]:
Canonical URL                  [http://192.168.56.102:8081/r/]:

*** Plugins
***

Installing plugins.
Install plugin singleusergroup version v2.11.8 [y/N]?
Install plugin commit-message-length-validator version v2.11.8 [y/N]?
Install plugin reviewnotes version v2.11.8 [y/N]?
Install plugin replication version v2.11.8 [y/N]?
Install plugin download-commands version v2.11.8 [y/N]? y
Initializing plugins.
No plugins found with init steps.

Initialized /var/gerrit

Links

Plugins:


 251  wget  http://deb.gerritforge.com/dists/gerrit/contrib/binary-amd64/gerrit-2.11.8-1.noarch.deb


# java -jar /var/gerrit/bin/gerrit.war  init -d  /var/gerrit
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore

*** Gerrit Code Review 2.11.8
***


*** Git Repositories
***

Location of Git repositories   [git]:

*** SQL Database
***

Database server type           [mysql]:

Gerrit Code Review is not shipped with MySQL Connector/J 5.1.21
**  This library is required for your configuration. **
Download and install it now [Y/n]? Y
Downloading http://repo2.maven.org/maven2/mysql/mysql-connector-java/5.1.21/mysql-connector-java-5.1.21.jar ... OK
Checksum mysql-connector-java-5.1.21.jar OK
Server hostname                [localhost]:
Server port                    [(mysql default)]:
Database name                  [gerrit]:
Database username              [gerrit]:
Change gerrit's password       [y/N]?

*** Index
***

Type                           [LUCENE/?]:

root@jenkins-demo:/var/gerrit#
The index must be rebuilt before starting Gerrit:
  java -jar gerrit.war reindex -d site_path

root@jenkins-demo:/var/gerrit#
*** User Authentication
***

Authentication method          [LDAP/?]:
LDAP server                    [ldap://127.0.0.1]:
LDAP username                  [cn=admin,dc=demo,dc=com]:
Change cn=admin,dc=demo,dc=com's password [y/N]?
Account BaseDN                 [ou=gerrit,dc=demo,dc=com]:
Group BaseDN                   [ou=gerrit,dc=demo,dc=com]:

*** Review Labels
***

Install Verified label         [y/N]?

*** Email Delivery
***

SMTP server hostname           [localhost]:
SMTP server port               [(default)]:
SMTP encryption                [NONE/?]:
SMTP username                  :

*** Container Process
***

Run as                         [gerrit]:
Java runtime                   [/usr/lib/jvm/java-7-openjdk-amd64/jre]:
Upgrade /var/gerrit/bin/gerrit.war [Y/n]? n

*** SSH Daemon
***

Listen on address              [*]:
Listen on port                 [29418]:

Gerrit Code Review is not shipped with Bouncy Castle Crypto SSL v151
  If available, Gerrit can take advantage of features
  in the library, but will also function without it.
Download and install it now [Y/n]? n
Generating SSH host key ... rsa(simple)... done

*** HTTP Daemon
***

Behind reverse proxy           [Y/n]?
Proxy uses SSL (https://)      [y/N]?
Subdirectory on proxy server   [/r/]:
Listen on address              [127.0.0.1]:
Listen on port                 [8081]:
Canonical URL                  [http://192.168.59.103:8081/r/]:

*** Plugins
***

Installing plugins.
Install plugin singleusergroup version v2.11.8 [y/N]?
Install plugin commit-message-length-validator version v2.11.8 [y/N]?
Install plugin reviewnotes version v2.11.8 [y/N]?
Install plugin replication version v2.11.8 [y/N]?
Install plugin download-commands version v2.11.8 [y/N]? y
Initializing plugins.
No plugins found with init steps.


sudo -H -u gerrit java -jar /var/gerrit/bin/gerrit.war  reindex



apt-get install git-review



root@jenkins-demo:~/demo-jenkins-jobs/demo/builders/test-jenkins-jobs# ssh jenkins-demo@192.168.59.103 -p 29418 gerrit stream-events

root@jenkins-demo:~/demo-jenkins-jobs# ssh jenkins-demo@192.168.59.103 -p 29418 'gerrit review 3,4 --message "Build 3 Started nulljob/test-jenkins-jobs/11/ " --label "Verified=0" --code-review 0'


http://stackoverflow.com/questions/25478344/adding-gerrit-label-but-not-able-to-see-it-properly-in-review-page https://gerrit-review.googlesource.com/Documentation/config-labels.html#label_Verified