gerrit安装配置

1 - 前言

Code Review 代码评审是指在软件开发过程中,对源代码的系统性检查,改进代码质量,查找系统缺陷,保证软件总体质量和提高开发者自身水平。
简单的说,Code Review是用来确认方案设计和代码实现的质量保证机制。

2 - Gerrit简介

Gerrit 是建立在Git版本控制系统之上并且基于Web的一个免费开源的轻量级代码审查工具。
作为开发者和Git之间的一层屏障,不允许直接将本地修改内容同步到远程仓库中。
与Jenkins集成后,可以在每次提交代码后,人工审核代码前,通过Jenkins任务自动运行单元测试、构建以及自动化测试,如果Jenkins任务失败,会自动打回本次提交。

一般Git、Gerrit和Jenkins集成后的使用流程

1.开发者提交代码到Gerrit
2.触发对应的Jenkins任务,通过以后Verified加1
3.人工审核,审核通过后code review加2,触发对应的Jenkins任务
4.通过以后确认本次提交,Gerrit执行与Git仓库的代码同步操作
5.代码进入Git仓库

2.1 官网信息

HomePage:https://www.gerritcodereview.com/
Downloads:https://gerrit-releases.storage.googleapis.com/index.html
Docs:https://gerrit-review.googlesource.com/Documentation/
Quickstart:https://gerrit-review.googlesource.com/Documentation/linux-quickstart.html
Issues List:https://bugs.chromium.org/p/gerrit/issues/list

2.2 Training Slides

The following slides explain Git and Gerrit concepts and workflows and are meant for self-studying how Git and Gerrit work:

Git explained: Git Concepts and Workflows:https://docs.google.com/presentation/d/1IQCRPHEIX-qKo7QFxsD3V62yhyGA9_5YsYXFOiBpgkk/
Gerrit explained: Gerrit Concepts and Workflows:https://docs.google.com/presentation/d/1C73UgQdzZDw0gzpaEqIC6SPujZJhqamyqO1XOHjH-uk/

3 - 安装准备

3.1 Linux、Java、Git

[Anliven@mt101 ~]$ cat /etc/system-release
CentOS Linux release 7.5.1804 (Core) 

[Anliven@mt101 ~]$ uname -a
Linux mt101 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

[Anliven@mt101 ~]$ java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

[Anliven@mt101 ~]$ git --version
git version 1.8.3.1 

3.2 创建Gerrit账户

[Anliven@mt101 ~]$ sudo adduser gerrit
[Anliven@mt101 ~]$ sudo passwd gerrit
Changing password for user gerrit.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

[Anliven@mt101 ~]$ su - gerrit
Password: 
[gerrit@mt101 ~]$ git config --global core.quotepath false
[gerrit@mt101 ~]$ git config --global i18n.logoutputencoding utf8
[gerrit@mt101 ~]$ git config --global i18n.commitencoding utf8
[gerrit@mt101 ~]$ git config --list
core.quotepath=false
i18n.logoutputencoding=utf8
i18n.commitencoding=utf8

[gerrit@mt101 ~]$ exit
logout

[Anliven@mt101 ~]$ sudo cat /etc/sudoers |grep gerrit
gerrit    ALL=(ALL)    NOPASSWD: ALL

4 - Gerrit安装

4.1 官网信息

https://gerrit-releases.storage.googleapis.com/gerrit-3.1.0.war
https://gerrit-documentation.storage.googleapis.com/Documentation/3.1.0/index.html
Quickstart for Installing Gerrit on Linux:https://gerrit-documentation.storage.googleapis.com/Documentation/3.1.0/linux-quickstart.html

4.2 安装并启动

  • 将下载好的gerrit-3.1.0.war拷贝至服务器的/home/gerrit目录下
  • su - gerrit切换至gerrit用户,并执行安装运行命令
[gerrit@vm192-168-2-77 ~]$ java -jar gerrit-3.1.0.war init -d ~/gerrit-review

将会逐个出现配置选项,填写如下选项配置,其余默认。

Authentication method [openid/?]: HTTP
Listen on address [*]: 192.168.16.101
Listen on port [8080]: 8083
后续可以通过配置文件(/home/gerrit/gerrit-review/etc/gerrit.config)来更新配置。

[gerrit@vm192-168-2-77 ~]$ java -jar gerrit-3.1.0.war init -d ~/gerrit-review
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2021-04-06 16:16:30,271] [main] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /home/gerrit/gerrit-review/etc/gerrit.config; assuming defaults

*** Gerrit Code Review 3.1.0
***

Create '/home/gerrit/gerrit-review' [Y/n]? y

*** Git Repositories
***

Location of Git repositories   [git]: git

*** Index
***

Type                           [lucene]:

*** User Authentication
***

Authentication method          [openid/?]: HTTP
Get username from custom HTTP header [y/N]?
SSO logout URL                 :
Enable signed push support     [y/N]?

*** 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/local/java/jdk1.8.0_211/jre]:
Copy gerrit-3.1.0.war to /home/gerrit/gerrit-review/bin/gerrit.war [Y/n]?
Copying gerrit-3.1.0.war to /home/gerrit/gerrit-review/bin/gerrit.war

*** SSH Daemon
***

Listen on address              [*]:
Listen on port                 [29418]:
Generating SSH host key ... rsa... ed25519... ecdsa 256... ecdsa 384... ecdsa 521... done

*** HTTP Daemon
***

Behind reverse proxy           [y/N]?
Use SSL (https://)             [y/N]?
Listen on address              [*]:
Listen on port                 [8080]: 8083
Canonical URL                  [http://vm192-168-2-77:8083/]:

*** Cache
***


*** Plugins
***

Installing plugins.
Install plugin codemirror-editor version v3.1.0 [y/N]?
Install plugin commit-message-length-validator version v3.1.0 [y/N]?
Install plugin delete-project version v3.1.0 [y/N]?
Install plugin download-commands version v3.1.0 [y/N]?
Install plugin gitiles version v3.1.0 [y/N]?
Install plugin hooks version v3.1.0 [y/N]?
Install plugin plugin-manager version v3.1.0 [y/N]?
Install plugin replication version v3.1.0 [y/N]?
Install plugin reviewnotes version v3.1.0 [y/N]?
Install plugin singleusergroup version v3.1.0 [y/N]?
Install plugin webhooks version v3.1.0 [y/N]?
Initializing plugins.
No plugins found with init steps.


Initialized /home/gerrit/gerrit-review
Reindexing projects:    100% (2/2) with: reindex --site-path /home/gerrit/gerrit-review --threads 1 --index projects
Reindexed 2 documents in projects index in 0.1s (33.3/s)
Executing /home/gerrit/gerrit-review/bin/gerrit.sh start
Starting Gerrit Code Review: WARNING: Could not adjust Gerrit's process for the kernel's out-of-memory killer.
         This may be caused by /home/gerrit/gerrit-review/bin/gerrit.sh not being run as root.
         Consider changing the OOM score adjustment manually for Gerrit's PID=30522 with e.g.:
         echo '-1000' | sudo tee /proc/30522/oom_score_adj
OK
Waiting for server on vm192-168-2-77:8083 ... OK
Opening http://vm192-168-2-77:8083/#/admin/projects/ ...FAILED
Open Gerrit with a JavaScript capable browser:
  http://vm192-168-2-77:8083/#/admin/projects/
posted @ 2021-04-06 16:24  一尾  阅读(1522)  评论(0编辑  收藏  举报