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/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM