在生产环境中部署gerrit
docker-compose.yaml
version: '3'
services:
gerrit:
image: 10.4.0.233:5000/gerritcodereview/gerrit:3.10.0-ubuntu22
container_name: gerrit
ports:
- "29418:29418"
#- "8080:8080"
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/admin/infra/gerrit/review_site/etc:/var/gerrit/etc
- /home/admin/infra/gerrit/review_site/git:/var/gerrit/git
- /home/admin/infra/gerrit/review_site/db:/var/gerrit/db
- /home/admin/infra/gerrit/review_site/index:/var/gerrit/index
- /home/admin/infra/gerrit/review_site/cache:/var/gerrit/cache
- /home/admin/infra/gerrit/review_site/plugins:/var/gerrit/plugins
environment:
- CANONICAL_WEB_URL=http://10.4.35.39:8080
- HTTPD_LISTENURL=proxy-http://*:8080
# command: init --install-all-plugins
httpd:
container_name: httpd
image: 10.4.0.233:5000/httpd:latest
restart: unless-stopped
ports:
- 8080:8080
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/admin/infra/gerrit/apache/passwords:/etc/apache2/passwords
- /home/admin/infra/gerrit/apache/httpd.conf:/usr/local/apache2/conf/httpd.conf
Example of /external/gerrit/etc/gerrit.config
[gerrit]
basePath = git
canonicalWebUrl = http://10.4.XX.XX:8080
serverId = XX
[container]
user = root
[index]
type = lucene
[auth]
type = http
# 配置所有项目启动 jira 集成
[plugin "its-phabricator"]
enabled = true
association = SUGGESTED
# 制定git提交策略
# MANDATORY:commit message 需要包含一个或多个 issue-id,否则 git 推送将被拒绝
# SUGGESTED:commit message 不包含任何 issue-id 时,会在客户端上显示一条警告消息作为建议。
# OPTIONAL:在 commit message 中检测到 issue-id 时,就会和 jira 上的 issue 关联;没检测到也不会报错。
[commentLink "its-phabricator"]
match = (T[1-9][0-9]{1,5})
link = http://10.4.XX.XX:81/$1
# 配置 phabricator 凭据
[its-phabricator]
url = http://10.4.XX.XX:81
token = XXX
# 配置所有项目启动 jira 集成
[plugin "its-jira"]
enabled = true
association = SUGGESTED
# 制定git提交策略
# MANDATORY:commit message 需要包含一个或多个 issue-id,否则 git 推送将被拒绝
# SUGGESTED:commit message 不包含任何 issue-id 时,会在客户端上显示一条警告消息作为建议。
# OPTIONAL:在 commit message 中检测到 issue-id 时,就会和 jira 上的 issue 关联;没检测到也不会报错。
[commentLink "its-jira"]
match = ([A-Z]+[0-9]*[A-Z]*[0-9]*-[0-9]+)
link = http://10.4.XX.XX:8090/browse/$1
html = <a href=\"http://10.4.XX.XX:8090//browse/$1\">$1</a>
# 配置 jira 凭据
[its-jira]
url = http://10.4.XX.XX:8090
username = admin
password = XXX
connectTimeout = 120000 ms
readTimeout = 30000 ms
[lfs]
plugin = lfs
[receive]
enableSignedPush = false
[sendemail]
smtpServer = localhost
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = http://*:8080/
[cache]
directory = cache
[storage]
backend = fs
directory = /var/gerrit/data/lfs
http.conf
ServerRoot "/usr/local/apache2"
Listen 8080
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
ServerAdmin you@example.com
ServerName localhost
<Proxy *:8080>
Order deny,allow
Allow from all
</Proxy>
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
<Files ".ht*">
Require all denied
</Files>
<IfModule unixd_module>
User www-data
Group www-data
</IfModule>
ErrorLog /proc/self/fd/2
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog /proc/self/fd/1 common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/usr/local/apache2/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule headers_module>
RequestHeader unset Proxy early
</IfModule>
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
<Location "/login/">
AuthType Basic
AuthName "Gerrit Code Review"
Require valid-user
AuthUserFile /etc/apache2/passwords
</Location>
AllowEncodedSlashes On
ProxyPass "/" "http://gerrit:8080/" nocanon
ProxyPassReverse "/" "http://gerrit:8080/"
ProxyPass "/info/lfs" "http://gerrit:8080/info/lfs"
ProxyPassReverse "/info/lfs" "http://gerrit:8080/info/lfs"
ProxyPass "/git-lfs" "http://gerrit:8080/git-lfs"
ProxyPassReverse "/git-lfs" "http://gerrit:8080/git-lfs"
用Docker初始化Gerrit DB和Git存储库
依次创建review_site/etc、review_site/git 、review_site/db、review_site/index、review_site/cache、review_site/plugins、review_site/data、review_site/logs
目录。
mkdir -p review_site/{etc,git,db,index,cache,plugins,data,logs}
chown -R 1000:1000 review_site/
Step-1: Run Gerrit docker init setup from docker
取消docker-compose.yaml
中command: init
选项的注释。
docker compose up gerrit
等待,直到您在输出中看到消息Initialized /var/gerrit
,然后容器将退出。
Step-2: Start Gerrit in daemon mode
注释掉docker-compose.yaml
中的command: init
选项,并启动所有节点:
docker compose up -d
安装插件
核心插件被打包在Gerrit war
文件中,可以在Gerrit
初始化期间通过参数--install-all-plugins
来轻松安装。
其他插件可以在https://gerrit-ci.gerritforge.com/view/Plugins-stable-3.10/
下载。
插件
- lfs
- its-jira
- its-phabricator
https://gerrit-ci.gerritforge.com/plugin-manager
https://gerrit-googlesource.proxy.ustclug.org/plugins/
创建用户
# 第一次创建用户时,使用-c
sudo htpasswd -c /home/admin/infra/gerrit/apache/passwords admin
#sudo chmod 755 /home/admin/infra/gerrit/apache/passwords
后续创建其他用户使用 -m
htpasswd -m /home/admin/infra/gerrit/apache/passwords user
遇到的问题:
1、commit msg
包含T498102
时,提交失败
报错信息如下
[2024-07-22T10:23:11.774Z] [SSH git-receive-pack /test (admin)] ERROR com.google.gerrit.server.git.receive.AsyncReceiveCommits : error while processing push
java.util.concurrent.ExecutionException: java.lang.NumberFormatException: For input string: "T498102"
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at com.google.gerrit.server.git.receive.AsyncReceiveCommits.preReceive(AsyncReceiveCommits.java:407)
at com.google.gerrit.server.git.receive.AsyncReceiveCommits.lambda$asHook$0(AsyncReceiveCommits.java:351)
at org.eclipse.jgit.transport.ReceivePack.service(ReceivePack.java:2287)
at org.eclipse.jgit.transport.ReceivePack.receive(ReceivePack.java:2200)
at com.google.gerrit.sshd.commands.Receive.runImpl(Receive.java:98)
at com.google.gerrit.sshd.AbstractGitCommand.service(AbstractGitCommand.java:109)
at com.google.gerrit.sshd.AbstractGitCommand$1.run(AbstractGitCommand.java:74)
at com.google.gerrit.sshd.BaseCommand$TaskThunk.run(BaseCommand.java:492)
at com.google.gerrit.server.logging.LoggingContextAwareRunnable.run(LoggingContextAwareRunnable.java:113)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at com.google.gerrit.server.git.WorkQueue$Task.run(WorkQueue.java:703)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.NumberFormatException: For input string: "T498102"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:668)
at java.base/java.lang.Integer.parseInt(Integer.java:786)
at com.googlesource.gerrit.plugins.its.phabricator.PhabricatorItsFacade.exists(PhabricatorItsFacade.java:68)
at com.googlesource.gerrit.plugins.its.base.validation.ItsValidateComment.validCommit(ItsValidateComment.java:74)
at com.googlesource.gerrit.plugins.its.base.validation.ItsValidateComment.onCommitReceived(ItsValidateComment.java:162)
at com.google.gerrit.server.git.validators.CommitValidators$PluginCommitValidationListener.runValidator(CommitValidators.java:650)
at com.google.gerrit.server.git.validators.CommitValidators$PluginCommitValidationListener.lambda$onCommitReceived$0(CommitValidators.java:659)
at com.google.gerrit.server.plugincontext.PluginContext.runLogExceptions(PluginContext.java:280)
at com.google.gerrit.server.plugincontext.PluginSetContext.runEach(PluginSetContext.java:170)
at com.google.gerrit.server.git.validators.CommitValidators$PluginCommitValidationListener.onCommitReceived(CommitValidators.java:658)
at com.google.gerrit.server.git.validators.CommitValidators.validate(CommitValidators.java:271)
at com.google.gerrit.server.git.receive.BranchCommitValidator.validateCommit(BranchCommitValidator.java:188)
at com.google.gerrit.server.git.receive.BranchCommitValidator.validateCommit(BranchCommitValidator.java:120)
at com.google.gerrit.server.git.receive.ReceiveCommits.selectNewAndReplacedChangesFromMagicBranch(ReceiveCommits.java:2450)
at com.google.gerrit.server.git.receive.ReceiveCommits.processCommandsUnsafe(ReceiveCommits.java:814)
at com.google.gerrit.server.git.receive.ReceiveCommits.processCommands(ReceiveCommits.java:698)
at com.google.gerrit.server.git.receive.AsyncReceiveCommits.lambda$preReceive$2(AsyncReceiveCommits.java:386)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at com.google.gerrit.server.util.RequestScopePropagator.lambda$cleanup$1(RequestScopePropagator.java:187)
at com.google.gerrit.server.util.RequestScopePropagator.lambda$context$0(RequestScopePropagator.java:174)
at com.google.gerrit.server.util.ThreadLocalRequestScopePropagator.lambda$wrapImpl$0(ThreadLocalRequestScopePropagator.java:45)
at com.google.gerrit.server.util.RequestScopePropagator$1.call(RequestScopePropagator.java:85)
at com.google.gerrit.server.util.RequestScopePropagator$2.run(RequestScopePropagator.java:116)
... 8 more
解决:更新3.10.0
版本为3.9.5
参考:
https://www.gerritcodereview.com/
https://gerrit.googlesource.com/docker-gerrit
https://hub.docker.com/r/gerritcodereview/gerrit
https://github.com/openfrontier/docker-gerrit/issues/29