gerrit replication

All posts tagged gerrit replication

This tutorial explains the installation and configuration for Gerrit Code Review on Ubuntu 14.04

 

What is Gerrit Code Review?

Gerrit is a web based code review system, facilitating online code reviews for projects using the Git version control system.

Gerrit makes reviews easier by showing changes in a side-by-side display, and allowing inline comments to be added by any reviewer.

Gerrit simplifies Git based project maintainership by permitting any authorized user to submit changes to the master Git repository, rather than requiring all approved changes to be merged in by hand by the project maintainer. This functionality enables a more centralized usage of Git.

 

Official documentation is located here.

 

Necessary packages:

 

* p.s: you can use Apache, but I prefer Nginx.

 

You also need an SMTP server. You can use this tutorial

 

Create user for Gerrit:

 

Nginx Configuration:

 

1. Create a new site:

 

nano /etc/nginx/sites-available/gerrit

 

configuration:

server {
 listen 80;
 server_name gerrit.example.com; #site url

 error_log /home/gerrit/gerrit/logs/gerrit-proxy-error.log;
 root /home/gerrit/gerrit/;

 location @gerrit {
 sendfile off;
 proxy_pass http://127.0.0.1:8082;
 proxy_redirect default;
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_max_temp_file_size 0;

 #this is the maximum upload size
 client_max_body_size 10m;
 client_body_buffer_size 128k;
 proxy_connect_timeout 90;
 proxy_send_timeout 90;
 proxy_read_timeout 90;

 proxy_buffer_size 4k;
 proxy_buffers 4 32k;
 proxy_busy_buffers_size 64k;
 proxy_temp_file_write_size 64k;
 }

 location / { try_files $uri @gerrit; }

}

 

2. Enable site:

 

ln -s /etc/nginx/sites-available/gerrit /etc/nginx/sites-enabled/gerrit
service nginx restart

* Restarting nginx nginx                                                 [ OK ]

 

Create MySQL database:

 

mysql -p

Enter password: #mysql_root_password

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 5.5.43-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>

 

Insert these commands:

 

CREATE USER 'gerrit'@'localhost' IDENTIFIED BY 'chose_a_password';
CREATE DATABASE reviewdb;
GRANT ALL ON reviewdb.* TO 'gerrit'@'localhost';
FLUSH PRIVILEGES;
exit;

 

Gerrit Initialization:

 

1. Create a directory:

 

root@vps2:/# su gerrit
gerrit@vps2:/$ cd ~
gerrit@vps2:~$ mkdir gerrit
gerrit@vps2:~$ cd gerrit/
gerrit@vps2:~/gerrit$

 

2. Download Gerrit:

 

wget http://gerrit-releases.storage.googleapis.com/gerrit-2.11.3.war

You can get more recent builds (nightly), from HERE.

 

3. Install Gerrit/configuration:

 

java -jar gerrit-2.11.war init -d ~/gerrit

Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore

*** Gerrit Code Review 2.11
***
*** Git Repositories
***

Location of Git repositories [git]: #Press Enter

*** SQL Database
***

Database server type [h2]: mysql
Server hostname [localhost]: #Press Enter
Server port [(mysql default)]: #Press Enter
Database name [reviewdb]: #Press Enter
Database username [gerrit]: #Press Enter
gerrit's password : #Parola baza de date (reviewdb)
confirm password : 

*** Index
***

Type [LUCENE/?]: #Press Enter

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

*** User Authentication
***

Authentication method [OPENID/?]: #Press Enter

*** Review Labels
***

Install Verified label [y/N]? n

*** Email Delivery
***

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

*** Container Process
***

Run as [gerrit]: #Press Enter
Java runtime [/usr/lib/jvm/java-7-openjdk-amd64/jre]: #Press Enter
Copy gerrit-2.11.war to /home/gerrit/gerrit/bin/gerrit.war [Y/n]? #Press Enter
Copying gerrit-2.11.war to /home/gerrit/gerrit/bin/gerrit.war

*** SSH Daemon
***

Listen on address [*]: gerrit.example.com
Listen on port [29418]: #Press Enter

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]? y
Downloading http://www.bouncycastle.org/download/bcpkix-jdk15on-151.jar ... OK
Checksum bcpkix-jdk15on-151.jar OK

Gerrit Code Review is not shipped with Bouncy Castle Crypto Provider v151
** This library is required by Bouncy Castle Crypto SSL v151. **
Download and install it now [Y/n]? y
Downloading http://www.bouncycastle.org/download/bcprov-jdk15on-151.jar ... OK
Checksum bcprov-jdk15on-151.jar OK
Generating SSH host key ... rsa... dsa... done

*** HTTP Daemon
***

Behind reverse proxy [y/N]? y
Proxy uses SSL (https://) [y/N]? #Press Enter
Subdirectory on proxy server [/]: #Press Enter
Listen on address [*]: 127.0.0.1
Listen on port [8081]: 8082
Canonical URL [http://null/]: http://gerrit.example.com/

*** Plugins
***

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

Initialized /home/gerrit/gerrit

 

4. Install GitHub/plugin:

 

wget -O ~/gerrit/plugins/github-plugin-2.11.jar https://ci.gerritforge.com/view/Plugins-stable-2.11/job/Plugin_github_stable-2.11/lastSuccessfulBuild/artifact/github-plugin/target/github-plugin-2.11.jarb-oauth-2.11.jar

wget -O ~gerrit/gerrit/lib/github-oauth-2.11.jar https://ci.gerritforge.com/view/Plugins-stable-2.11/job/Plugin_github_stable-2.11/lastSuccessfulBuild/artifact/github-oauth/target/github-oauth-2.11.jar

 

5. Activate GitHub plugin :

 

The application must be registered on the GitHub HERE.

Github application

java -jar gerrit-2.11.war init -d ~/gerrit 

Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore

*** Gerrit Code Review 2.11
***
*** Git Repositories
***

Location of Git repositories [git]: #Press Enter

*** SQL Database
***

Database server type [mysql]:#Press Enter
Server hostname [localhost]:#Press Enter
Server port [(mysql default)]:#Press Enter
Database name [reviewdb]:#Press Enter
Database username [gerrit]:#Press Enter
Change gerrit's password [y/N]?#Press Enter

*** Index
***

Type [LUCENE/?]:#Press Enter

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

*** User Authentication
***

Authentication method [OPENID/?]: HTTP
Get username from custom HTTP header [y/N]? Y
Username HTTP header [SM_USER]: GITHUB_USER
SSO logout URL : /oauth/reset

*** Review Labels
***

Install Verified label [y/N]?#Press Enter

*** Email Delivery
***

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

*** Container Process
***

Run as [gerrit]:
Java runtime [/usr/lib/jvm/java-7-openjdk-amd64/jre]:#Press Enter
Upgrade /home/gerrit/gerrit/bin/gerrit.war [Y/n]?#Press Enter
Copying gerrit-2.11.war to /home/gerrit/gerrit/bin/gerrit.war

*** SSH Daemon
***

Listen on address [gerrit.example.com]:
Listen on port [29418]:

*** HTTP Daemon
***

Behind reverse proxy [Y/n]?#Press Enter
Proxy uses SSL (https://) [y/N]?#Press Enter
Subdirectory on proxy server [/]:#Press Enter
Listen on address : 127.0.0.1 
Listen on port [8081]: 8082
Canonical URL [http://gerrit.example.com]: #Press Enter

*** Plugins
***

Installing plugins.
Install plugin download-commands version v2.11 [y/N]?#Press Enter
Install plugin reviewnotes version v2.11 [y/N]?#Press Enter
Install plugin singleusergroup version v2.11 [y/N]?#Press Enter
Install plugin replication version v2.11 [y/N]?#Press Enter
Install plugin commit-message-length-validator version v2.11 [y/N]?#Press Enter
Initializing plugins.

*** GitHub Integration
***

GitHub URL [https://github.com]:#Press Enter
GitHub API URL [https://api.github.com]:#Press Enter

NOTE: You might need to configure a proxy using http.proxy if you run Gerrit behind a firewall.

*** GitHub OAuth registration and credentials
***

Register Gerrit as GitHub application on:
https://github.com/settings/applications/new

Settings (assumed Gerrit URL: http://gerrit.example.com/)
* Application name: Gerrit Code Review
* Homepage URL: http://gerrit.example.com/
* Authorization callback URL: http://gerrit.example.com/oauth

After registration is complete, enter the generated OAuth credentials:
GitHub Client ID : #See Github
GitHub Client Secret : #See Github
confirm password :
Gerrit OAuth implementation [HTTP/?]:#Press Enter
HTTP Authentication Header [GITHUB_USER]:#Press Enter

Initialized /home/gerrit/gerrit

 

 

6. Activate git garbage collection:

 

Add in this file ~/gerrit/etc/gerrit.config:

 

[gc]
startTime = Fri 12:00
interval = 4 day

7. Reindex Gerrit:

java -jar gerrit-2.11.war reindex -d ~/gerrit
[2015-05-09 16:19:42,217] INFO com.google.gerrit.server.git.LocalDiskRepositoryManager : Defaulting core.streamFileThreshold to 124m
[2015-05-09 16:19:43,104] INFO com.google.gerrit.server.cache.h2.H2CacheFactory : Enabling disk cache /home/gerrit/gerrit/cache
Reindexing changes: done
Reindexed 0 changes in 0.0s (0.0/s)
[2015-05-09 16:19:45,626] INFO com.google.gerrit.server.cache.h2.H2CacheFactory : Finishing 4 disk cache updates

 

8. Start Gerrit:

 

~/gerrit/bin/gerrit.sh start

 

9. Replication (push to GitHub):

 

New projects needs to be created in this format: github_account_name/repository

Create a new file ~/gerrit/etc/replication.config with the following content:

 

[remote "github"]
url = git@github.com:${name}.git 
push = +refs/heads/*:refs/heads/*
push = +refs/tags/*:refs/tags/*
push = +refs/*:refs/*
timeout = 30
threads = 2
createMissingRepositories = false
replicationDelay = 1

10. Restart Gerrit:

~/gerrit/bin/gerrit.sh restart

 

If everything went according to this tutorial,  Gerrit should be working properly. 

 

 

Congratulations!!!

 

 

 

 

The tutorial is inspired from HERE

Credit to jmztaylor for Nginx’s configuration

Acest tutorial explică instalarea și configurarea aplicației Gerrit Code Review pe Ubuntu 14.04

 

Ce este Gerrit Code Review?

Gerrit este o aplicație web, pentru revizuirea codului. Dezvoltatorii de software dintr-o echipă pot examina fiecare modificările celorlați asupra codului sursă utilizând un browser web și având posibilitatea de a aproba sau a respinge modificările respective. Gerrit este intergat cu Git, un sistem de control al versiunilor.

 

Documentația oficială se află aici.

 

Pachete necesare:

 

openjdk-7-jre nginx mysql-server gitweb git git-core
*p.s: se poate folosi și Apache, dar eu am preferat Nginx.

 

Aveți nevoie și de un server SMTP funcțional. Puteți folosi acest tutorial

 

Creare user pentru Gerrit:

useradd -m -d /home/gerrit -s /bin/bash  -U gerrit
passwd gerrit
Enter new UNIX password: #parola
Retype new UNIX password: #parola
passwd: password updated successfully

 

Configurare Nginx:

 

1. Se creează un nou site :

 

nano /etc/nginx/sites-available/gerrit

configurație:

server {
 listen 80;
 server_name gerrit.exemplu.ro; #url-ul site-ului

 error_log /home/gerrit/gerrit/logs/gerrit-proxy-error.log;
 root /home/gerrit/gerrit/;

 location @gerrit {
 sendfile off;
 proxy_pass http://127.0.0.1:8082;
 proxy_redirect default;
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_max_temp_file_size 0;

 #this is the maximum upload size
 client_max_body_size 10m;
 client_body_buffer_size 128k;
 proxy_connect_timeout 90;
 proxy_send_timeout 90;
 proxy_read_timeout 90;

 proxy_buffer_size 4k;
 proxy_buffers 4 32k;
 proxy_busy_buffers_size 64k;
 proxy_temp_file_write_size 64k;
 }

 location / { try_files $uri @gerrit; }

}

 

2. Activare site:

 

ln -s /etc/nginx/sites-available/gerrit /etc/nginx/sites-enabled/gerrit
service nginx restart

* Restarting nginx nginx                                                 [ OK ]

 

Creare bază de date MySQL:

 

mysql -p

Enter password: #parola_root_mysql

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 5.5.43-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>

 

Inserați aceste comenzi:

 

CREATE USER 'gerrit'@'localhost' IDENTIFIED BY 'parola_baza_de_date';
CREATE DATABASE reviewdb;
GRANT ALL ON reviewdb.* TO 'gerrit'@'localhost';
FLUSH PRIVILEGES;
exit;

 

Inițializare Gerrit:

 

1.Creare director:

 

root@vps2:/# su gerrit
gerrit@vps2:/$ cd ~
gerrit@vps2:~$ mkdir gerrit
gerrit@vps2:~$ cd gerrit/
gerrit@vps2:~/gerrit$

 

2.Descărcare Gerrit:

 

wget http://gerrit-releases.storage.googleapis.com/gerrit-2.11.3.war

Compilările mai recente(nightly), le gasiți AICI.

 

3.Instalare / configurare Gerrit:

 

java -jar gerrit-2.11.war init -d ~/gerrit

Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore

*** Gerrit Code Review 2.11
***
*** Git Repositories
***

Location of Git repositories [git]: #Apasa Enter

*** SQL Database
***

Database server type [h2]: mysql
Server hostname [localhost]: #Apasa Enter
Server port [(mysql default)]: #Apasa Enter
Database name [reviewdb]: #Apasa Enter
Database username [gerrit]: #Apasa Enter
gerrit's password : #Parola baza de date (reviewdb)
confirm password : 

*** Index
***

Type [LUCENE/?]: #Apasa Enter

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

*** User Authentication
***

Authentication method [OPENID/?]: #Apasa Enter

*** Review Labels
***

Install Verified label [y/N]? n

*** Email Delivery
***

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

*** Container Process
***

Run as [gerrit]: #Apasa Enter
Java runtime [/usr/lib/jvm/java-7-openjdk-amd64/jre]: #Apasa Enter
Copy gerrit-2.11.war to /home/gerrit/gerrit/bin/gerrit.war [Y/n]? #Apasa Enter
Copying gerrit-2.11.war to /home/gerrit/gerrit/bin/gerrit.war

*** SSH Daemon
***

Listen on address [*]: gerrit.exemplu.ro
Listen on port [29418]: #Apasa Enter

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]? y
Downloading http://www.bouncycastle.org/download/bcpkix-jdk15on-151.jar ... OK
Checksum bcpkix-jdk15on-151.jar OK

Gerrit Code Review is not shipped with Bouncy Castle Crypto Provider v151
** This library is required by Bouncy Castle Crypto SSL v151. **
Download and install it now [Y/n]? y
Downloading http://www.bouncycastle.org/download/bcprov-jdk15on-151.jar ... OK
Checksum bcprov-jdk15on-151.jar OK
Generating SSH host key ... rsa... dsa... done

*** HTTP Daemon
***

Behind reverse proxy [y/N]? y
Proxy uses SSL (https://) [y/N]? #Apasa Enter
Subdirectory on proxy server [/]: #Apasa Enter
Listen on address [*]: 127.0.0.1
Listen on port [8081]: 8082
Canonical URL [http://null/]: http://gerrit.exemplu.ro/

*** Plugins
***

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

Initialized /home/gerrit/gerrit

 

4. Descarcăre / instalare plugin GitHub:

 

wget -O ~/gerrit/plugins/github-plugin-2.11.jar https://ci.gerritforge.com/view/Plugins-stable-2.11/job/Plugin_github_stable-2.11/lastSuccessfulBuild/artifact/github-plugin/target/github-plugin-2.11.jar

wget -O ~gerrit/gerrit/lib/github-oauth-2.11.jar https://ci.gerritforge.com/view/Plugins-stable-2.11/job/Plugin_github_stable-2.11/lastSuccessfulBuild/artifact/github-oauth/target/github-oauth-2.11.jar

 

5. Activare plugin GitHub:

 

Aplicația Gerrit trebuie inregistrată pe GitHub AICI.

gerrit_github

java -jar gerrit-2.11.war init -d ~/gerrit 

Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore

*** Gerrit Code Review 2.11
***
*** Git Repositories
***

Location of Git repositories [git]: #Apasa Enter

*** SQL Database
***

Database server type [mysql]:#Apasa Enter
Server hostname [localhost]:#Apasa Enter
Server port [(mysql default)]:#Apasa Enter
Database name [reviewdb]:#Apasa Enter
Database username [gerrit]:#Apasa Enter
Change gerrit's password [y/N]?#Apasa Enter

*** Index
***

Type [LUCENE/?]:#Apasa Enter

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

*** User Authentication
***

Authentication method [OPENID/?]: HTTP
Get username from custom HTTP header [y/N]? Y
Username HTTP header [SM_USER]: GITHUB_USER
SSO logout URL : /oauth/reset

*** Review Labels
***

Install Verified label [y/N]?#Apasa Enter

*** Email Delivery
***

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

*** Container Process
***

Run as [gerrit]:
Java runtime [/usr/lib/jvm/java-7-openjdk-amd64/jre]:#Apasa Enter
Upgrade /home/gerrit/gerrit/bin/gerrit.war [Y/n]?#Apasa Enter
Copying gerrit-2.11.war to /home/gerrit/gerrit/bin/gerrit.war

*** SSH Daemon
***

Listen on address [gerrit.exemplu.ro]:
Listen on port [29418]:

*** HTTP Daemon
***

Behind reverse proxy [Y/n]?#Apasa Enter
Proxy uses SSL (https://) [y/N]?#Apasa Enter
Subdirectory on proxy server [/]:#Apasa Enter
Listen on address : 127.0.0.1 Listen on port [8081]: 8082
Canonical URL [http://gerrit.exemplu.ro]:

*** Plugins
***

Installing plugins.
Install plugin download-commands version v2.11 [y/N]?#Apasa Enter
Install plugin reviewnotes version v2.11 [y/N]?#Apasa Enter
Install plugin singleusergroup version v2.11 [y/N]?#Apasa Enter
Install plugin replication version v2.11 [y/N]?#Apasa Enter
Install plugin commit-message-length-validator version v2.11 [y/N]?#Apasa Enter
Initializing plugins.

*** GitHub Integration
***

GitHub URL [https://github.com]:#Apasa Enter
GitHub API URL [https://api.github.com]:#Apasa Enter

NOTE: You might need to configure a proxy using http.proxy if you run Gerrit behind a firewall.

*** GitHub OAuth registration and credentials
***

Register Gerrit as GitHub application on:
https://github.com/settings/applications/new

Settings (assumed Gerrit URL: http://gerrit.exemplu.ro/)
* Application name: Gerrit Code Review
* Homepage URL: http://gerrit.exemplu.ro/
* Authorization callback URL: http://gerrit.exemplu.ro/oauth

After registration is complete, enter the generated OAuth credentials:
GitHub Client ID : #Vezi Github
GitHub Client Secret : #Vezi Github
confirm password :
Gerrit OAuth implementation [HTTP/?]:#Apasa Enter
HTTP Authentication Header [GITHUB_USER]:#Apasa Enter

Initialized /home/gerrit/gerrit

 

6. Activare git garbage collection:

 

Se adauga în fișierul ~/gerrit/etc/gerrit.config :

 

[gc]
startTime = Fri 12:00
interval = 4 day

 

7. Reindexare Gerrit:

 

java -jar gerrit-2.11.war reindex -d ~/gerrit
[2015-05-09 16:19:42,217] INFO com.google.gerrit.server.git.LocalDiskRepositoryManager : Defaulting core.streamFileThreshold to 124m
[2015-05-09 16:19:43,104] INFO com.google.gerrit.server.cache.h2.H2CacheFactory : Enabling disk cache /home/gerrit/gerrit/cache
Reindexing changes: done
Reindexed 0 changes in 0.0s (0.0/s)
[2015-05-09 16:19:45,626] INFO com.google.gerrit.server.cache.h2.H2CacheFactory : Finishing 4 disk cache updates

 

8. Pornire Gerrit:

 

~/gerrit/bin/gerrit.sh start

 

9.Replication (încarcăre pe GitHub):

 

Proiectele se creaza în Gerrit sub formatul: nume_cont_github/repository 

Se crează un fișier nou  ~/gerrit/etc/replication.config cu urmatorul conținut:

 

[remote "github"]
url = git@github.com:${name}.git 
push = +refs/heads/*:refs/heads/*
push = +refs/tags/*:refs/tags/*
push = +refs/*:refs/*
timeout = 30
threads = 2
createMissingRepositories = false
replicationDelay = 1

 

10. Repornire Gerrit:

~/gerrit/bin/gerrit.sh restart

 

Dacă totul a mers conform tutorialului, ar trebui ca Gerrit să funcționeze corespunzător.                                                                                     

 

Felicitări ! ! !

 

 

 

 

Tutorialul este inspirat de AICI