Gerrit 공식 가이드

Gerrit의 공식 가이드는 https://www.gerritcodereview.com/ 상단의 Docs > Latest 에서 볼 수 있다.

이 페이지의 설치 방법은 공식 가이드 중 Qucickstart for Installing Gerrit on Linux 을 따른다.

Quickstart 설치는 Gerrit을 간단히 설치하고 맛보는 용도이다.

 

Gerrit 설치

Gerrit 다운로드

Gerrit 설치를 위해서 먼저 다운로드를 받아야 한다.

여기에서 다운로드된 Gerrit 버전이 설치 디렉토리에 복사되므로, 최신 버전인 3.5.1을 다운로드 받았다.

junggu.lee@bungslxubu51:~$ cd bin
junggu.lee@bungslxubu51:~/bin$ wget https://gerrit-releases.storage.googleapis.com/gerrit-3.5.1.war

 

Gerrit 설치 명령어

Quickstart 가이드 문서처럼 --batch --dev -d 옵션을 사용하면, 기본설정을 기본으로 가정하고 빠르게 설치가 가능하다.

Quickstart 가이드 문서에서 사용하는 옵션은 다음과 같다.

  • --batch : 기본 구성 옵션을 사용
  • --dev : 인증시 DEVELOPMENT_BECOME_ANY_ACCOUNT 을 사용
  • -d : 설치할 디렉토리 지정
junggu.lee@bungslxubu51:~$ java -jar ~/bin/gerrit-3.5.1.war init --batch --dev -d ~/work/gerrit_quickstart

설치 후 자동으로 Gerrit이 실행되며, Web Browser에서 Gerrit 창이 열린다.

 

설정 문제가 있는 경우에, 실행시 에러가 발생할 수 있다.

이 때는 로그 파일을 살펴보고, 설정 파일인 etc/gerrit.config을 수정하여 Gerrit을 실행하면 된다.

내 경우에는 8080 포트의 충돌로 인해서 에러가 발생하였다. ( 문제가 발생했을때는 etc/logs/error_log 파일로 확인 가능하다 )

etc/gerrit.configgerrit.canonicalWebUrlhttpd.listenUrl 의 8080을 8081로 변경하였다.

[gerrit]
        basePath = git
        canonicalWebUrl = http://bungslxubu51:8081/
        serverId = c5b60791-8a32-4d6f-850e-4698ef8ddde9
[container]
        javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
        javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
        user = junggu.lee
        javaHome = /usr/lib/jvm/java-11-openjdk-amd64
[index]
        type = lucene
[auth]
        type = DEVELOPMENT_BECOME_ANY_ACCOUNT
        userNameCaseInsensitive = true
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = localhost
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = http://*:8081/
[cache]
        directory = cache
[plugins]
        allowRemoteAdmin = true

이후에 다시 Gerrit을 실행한다.

junggu.lee@bungslxubu51:~/work/gerrit_quickstart$ bin/gerrit.sh start

 

또 다른 방법으로는 기본값으로 설정하는 옵션인 --batch 을 제거하면 각종 설정을 개별적으로 지정할 수 있다. ( Standalone 설치 ) 

내 경우에 8080 포트 충돌을 피하기 위해, Listen on port 부분을 8081 포트로 설정하고, 나머지 설정은 기본값으로 두었다.

junggu.lee@bungslxubu51:~$ java -jar ~/bin/gerrit-3.5.1.war init -d $GERRIT_SITE
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2022-04-20 04:52:39,628] [main] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /home/junggu.lee/work/gerrit_quickstart/etc/gerrit.config; assuming defaults

*** Gerrit Code Review 3.5.1
***

Create '/home/junggu.lee/work/gerrit_quickstart' [Y/n]?

*** Git Repositories
***

Location of Git repositories   [git]:

*** JGit Configuration
***

Auto-configured "receive.autogc = false" to disable auto-gc after git-receive-pack.

*** Index
***

Type                           [lucene]:

*** User Authentication
***

Authentication method          [openid/?]:
Enable signed push support     [y/N]?
Use case insensitive usernames [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                         [junggu.lee]:
Java runtime                   [/usr/lib/jvm/java-11-openjdk-amd64]:
Copy gerrit-3.5.1.war to /home/junggu.lee/work/gerrit_quickstart/bin/gerrit.war [Y/n]?
Copying gerrit-3.5.1.war to /home/junggu.lee/work/gerrit_quickstart/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]: 8081
Canonical URL                  [http://bungslxubu51:8081/]:

*** Cache
***


*** Plugins
***

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

============================================================================
Welcome to the Gerrit community

Find more information on the homepage: https://www.gerritcodereview.com
Discuss Gerrit on the mailing list: https://groups.google.com/g/repo-discuss
============================================================================
Initialized /home/junggu.lee/work/gerrit_quickstart
Init complete, reindexing accounts,changes,groups,projects with: reindex --site-path /home/junggu.lee/work/gerrit_quickstart --threads 1 --index accounts --index changes --index groups --index projects --disable-cache-statsReindexed 0 documents in accounts index in 0.0s (0.0/s)
Index accounts in version 11 is ready
Reindexing groups:      100% (2/2)
Reindexed 2 documents in groups index in 0.3s (6.3/s)
Index groups in version 8 is ready
Reindexing changes: Slicing projects: 100% (2/2), done
Reindexed 0 documents in changes index in 0.0s (0.0/s)
Index changes in version 71 is ready
Reindexing projects:    100% (2/2)
Reindexed 2 documents in projects index in 0.0s (40.8/s)
Index projects in version 4 is ready
Executing /home/junggu.lee/work/gerrit_quickstart/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/junggu.lee/work/gerrit_quickstart/bin/gerrit.sh not being run as root.
         Consider changing the OOM score adjustment manually for Gerrit's PID=870815 with e.g.:
         echo '-1000' | sudo tee /proc/870815/oom_score_adj
OK
Waiting for server on bungslxubu51:8081 ... OK
Opening http://bungslxubu51:8081/#/admin/projects/ ...OK

 

그리고 내부 테스트를 목적으로 하는 경우, 외부에서 Gerrit에 접속하는 것을 막을 수 있다.

이 경우, etc/gerrit.conifg 파일의 httpd.listenUrllocalhost로 수정하면 된다. ( Gerrit의 Quickstart 문서 참조 )

# 중략
[httpd]
        listenUrl = http://localhost:8081/
# 중략

Gerrit 실행

Gerrit 설치가 성공적으로 실행되면, 자동으로 Web Browser로 Gerrit 화면을 띄워준다.

Gerrit을 실행/중지/재실행은 다음 명령으로 가능하다.

junggu.lee@bungslxubu51:~$ cd work/gerrit_quickstart/bin/
junggu.lee@bungslxubu51:~/work/gerrit_quickstart/bin$ gerrit.sh start
junggu.lee@bungslxubu51:~/work/gerrit_quickstart/bin$ gerrit.sh stop
junggu.lee@bungslxubu51:~/work/gerrit_quickstart/bin$ gerrit.sh restart

 

Gerrit 삭제

우선 gerrit 실행을 중지한다.

junggu.lee@bungslxubu51:~$ work/gerrit_quickstart/bin/gerrit.sh stop

그리고, 혹시 실행되고 있는 프로세스가 있는지 확인한다.

junggu.lee@bungslxubu51:~$ ps -ef | grep gerrit
junggu.+  737432  707297  0 02:46 pts/0    00:00:00 grep --color=auto gerrit

설치 디렉토리를 제거한다.

junggu.lee@bungslxubu51:~$ rm -rf work/gerrit_quickstart/

 

Troubleshooting

Gerrit에 문제가 생겼을때는 에러 로그를 살펴본다. 에러 로그는 logs/error_log 이다.

다음은 내 에러 및 처리하는 과정을 표시하였다.

junggu.lee@bungslxubu51:~$ cat ~/work/gerrit_quickstart/logs/error_log
[2022-04-20T02:39:01.669Z] [main] INFO  com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SshCommandStart' queue
[2022-04-20T02:39:02.037Z] [main] INFO  com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SSH-Stream-Worker' queue
[2022-04-20T02:39:02.039Z] [main] INFO  com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SSH-Interactive-Worker' queue
[2022-04-20T02:39:02.039Z] [main] INFO  com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SSH-Batch-Worker' queue
[2022-04-20T02:39:02.040Z] [main] INFO  com.google.gerrit.server.git.WorkQueue : Adding metrics for 'MigrateExternalIdCase' queue
[2022-04-20T02:39:02.052Z] [main] WARN  com.google.gerrit.server.config.GitwebCgiConfig : gitweb not installed (no /usr/lib/cgi-bin/gitweb.cgi found)
[2022-04-20T02:39:02.726Z] [main] INFO  org.eclipse.jetty.util.log : Logging initialized @5624ms to org.eclipse.jetty.util.log.Slf4jLog
[2022-04-20T02:39:02.854Z] [main] INFO  com.google.gerrit.server.git.SystemReaderInstaller : Set JGit's SystemReader to read system config from /home/junggu.lee/work/gerrit_quickstart/etc/jgit.config
[2022-04-20T02:39:02.858Z] [main] INFO  com.google.gerrit.server.git.LocalDiskRepositoryManager : Defaulting core.streamFileThreshold to 1001m
[2022-04-20T02:39:03.261Z] [main] INFO  com.google.gerrit.server.plugins.PluginLoader : Loading plugins from /home/junggu.lee/work/gerrit_quickstart/plugins
[2022-04-20T02:39:03.275Z] [main] INFO  com.google.gerrit.server.config.ScheduleConfig : No schedule configuration for "accountDeactivation".
[2022-04-20T02:39:03.313Z] [main] INFO  com.google.gerrit.sshd.SshDaemon : Started Gerrit APACHE-SSHD-2.6.0 on *:29418
[2022-04-20T02:39:03.316Z] [main] INFO  org.eclipse.jetty.server.Server : jetty-9.4.36.v20210114; built: 2021-01-14T16:44:28.689Z; git: 238ec6997c7806b055319a6d11f8ae7564adc0de; jvm 11.0.14.1+1-Ubuntu-0ubuntu1.20.04
[2022-04-20T02:39:03.342Z] [main] INFO  org.eclipse.jetty.server.session : DefaultSessionIdManager workerName=node0
[2022-04-20T02:39:03.343Z] [main] INFO  org.eclipse.jetty.server.session : No SessionScavenger set, using defaults
[2022-04-20T02:39:03.344Z] [main] INFO  org.eclipse.jetty.server.session : node0 Scavenging every 600000ms
[2022-04-20T02:39:03.407Z] [main] INFO  org.eclipse.jetty.server.handler.ContextHandler : Started o.e.j.s.ServletContextHandler@75452b01{/,null,AVAILABLE}
[2022-04-20T02:39:03.412Z] [main] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
java.lang.IllegalStateException: Cannot start HTTP daemon
        at com.google.gerrit.pgm.http.jetty.JettyServer$Lifecycle.start(JettyServer.java:109)
        at com.google.gerrit.lifecycle.LifecycleManager.start(LifecycleManager.java:95)
        at com.google.gerrit.pgm.Daemon.start(Daemon.java:386)
        at com.google.gerrit.pgm.Daemon.run(Daemon.java:285)
        at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:61)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:224)
        at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:120)
        at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:65)
        at Main.main(Main.java:28)
Caused by: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:8080
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:349)
        at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:310)
        at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
        at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:234)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
        at org.eclipse.jetty.server.Server.doStart(Server.java:401)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
        at com.google.gerrit.pgm.http.jetty.JettyServer$Lifecycle.start(JettyServer.java:95)
        ... 12 more
Caused by: java.net.BindException: Address already in use
        at java.base/sun.nio.ch.Net.bind0(Native Method)
        at java.base/sun.nio.ch.Net.bind(Net.java:459)
        at java.base/sun.nio.ch.Net.bind(Net.java:448)
        at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227)
        at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:80)
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
        ... 19 more

Gerrit에서는 기본 설치시에 8080포트를 사용하는데, 이미 8080포트를 사용하고 있어서 사용할 수가 없다.

8080 포트가 사용되고 있는지 확인해보았다.

junggu.lee@bungslxubu51:~$ netstat -nap | grep 8080
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:58080         127.0.0.1:9099          TIME_WAIT   -

Gerrit의 동작을 확인하기 위해서 가벼운 브라우저 ( light web browser )인 midori를 설치했는데, 이 midori에서 8080 포트를 사용하고 있었다.

Gerrit 설치시에 8081 포트를 사용하도록 재설치하여 문제를 해결하였다.

 

 

'Gerrit' 카테고리의 다른 글

Gerrit 3.1.10 - 이전 설치 ( Migration, Docker )  (0) 2022.05.16
Gerrit 3.5.1 - 설치 ( Docker )  (0) 2022.05.11
Gerrit - LDAP 설정  (0) 2022.05.03
Gerrit - 설치 ( Standalone )  (0) 2022.04.22
Gerrit 변경사항을 적용하기  (0) 2021.11.18

tmux 3.2에서 마우스를 이용한 copy&paste 관련 부분을 깔끔하게 설정할 수 있게 되었다.

 

tmux 소스를 빌드한 이후에 tmux 파일을 ~/bin 에 복사하였다. ( https://github.com/tmux/tmux/wiki/Installing#installing-tmux )

 

git clone https://github.com/tmux/tmux.git
cd tmux
git checkout 3.2
sh autogen.sh
./configure
make

 

tmux 3.2에서는 copy&paste를 위한 copy-command 'xsel -i' 이 지원되었는데,

이전 버전까지 사용하던 copy&paste 관련 지저분한 설정을 set -g copy-command 'xsel -i' 한 줄로 명료하게 정리할 수 있다.

 

다음과 같이 .tmux.conf를 업데이트한다.

# Use symbolic link for version control
# ln -s settings/.tmux.conf .tmux.conf

# restart :
#': source-file ~/.tmux.conf'

# References
# - https://gist.github.com/spicycode/1229612
# - https://blog.outsider.ne.kr/699#footnote_link_699_1
# - https://unix.stackexchange.com/questions/1045/getting-256-colors-to-work-in-tmux

# set -g default-terminal "screen-256color"
# it should be added in .bashrc
#if [ "$TERM" != "xterm-256color" ]; then
#  export TERM=xterm-256color
#fi


# Set scrollback history
set -g history-limit 50000

# Set mouse on : windows, panes, scroll, copy & paste
set -g mouse on

# Set clipboard
set -g copy-command 'xsel -i'

# Set rebinding the action key
set -g prefix C-j
unbind C-b
bind C-j send-prefix

# Use Alt-arrow keys without prefix key to switch panes
bind -n M-Left  select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up    select-pane -U
bind -n M-Down  select-pane -D
bind -n M-q     display-panes

# Use Alt-number keys to switch windows
bind -n M-0 select-window -t 0
bind -n M-1 select-window -t 1
bind -n M-2 select-window -t 2
bind -n M-3 select-window -t 3
bind -n M-4 select-window -t 4
bind -n M-5 select-window -t 5
bind -n M-6 select-window -t 6
bind -n M-7 select-window -t 7
bind -n M-8 select-window -t 8
bind -n M-9 select-window -t 9

# Use Shift-arrow to switch windows
bind -n S-Left  previous-window
bind -n S-Right next-window

# Use | and - to split panes
bind | split-window -h
bind - split-window -v

#-------------------------------------------------------#
#Pane colours
#-------------------------------------------------------#
# set inactive/active window styles
set -g window-style 'fg=colour247,bg=colour236'
set -g window-active-style 'fg=colour250,bg=black'

#pane border
set -g pane-border-style bg=colour235
set -g pane-border-style fg=colour238
set -g pane-active-border-style bg=colour236
set -g pane-active-border-style fg=colour51
#-------------------------------------------------------#

# Set status bar
set -g status-bg black
set -g status-fg white
set -g status-left '#[fg=green](#S) #(whoami)'
set -g status-left-length 20
#set -g status-right '#[fg=yellow]#(cut -d " " -f 1-3 /proc/loadavg)#[default] #[fg=white]%H:%M#[default]'

# Set highlight active window
setw -g window-status-current-style fg=black,bg=white

# tmux logging : over tmux 1.9
#run-shell ~/clone/path/logging.tmux

'Linux' 카테고리의 다른 글

tmux 사용법  (0) 2014.03.13
makefile의 phony  (0) 2013.05.07

reference

 

Gerrit Trigger

This plugin integrates with <a href="http://code.google.com/p/gerrit/" target="_blank" rel="nofollow noopener noreferrer">Gerrit</a> code review.

plugins.jenkins.io

 

Gerrit Trigger Plugin을 이용하여, Review commit이 올라올때 마다 Jenkins를 이용하여 빌드를 하였다.

이 때, 변경사항을 다음과 같은 방식으로 적용하였다.

cd vendor/google/tv/broadcaststack
git fetch "ssh://gerrit@gerrit.mycompany.net:29418/broadcaststack" ${GERRIT_REFSPEC} && git checkout FETCH_HEAD

 

그런데, 하나의 저장소에 대해서는 잘 동작하였으나, 여러 개의 저장소의 변경사항에 대해서는 위와 같은 방식이 적절하지 않았다. 즉, 변경사항을 추적할 저장소는 broadcaststack, projects/apple 이었는데, Jenkins script에서는 어느 저장소의 Patchset을 적용할지 ( 어느 디렉토리안에서 get fetch를 사용할지 ) 확인할 수 가 없었다.

 

Gerrit Trigger 플러그인 홈페이지에는 다음과 같은 예제가 있었다. 

repo init -u git://gerrit.mycompany.net/mymanifest.git
repo sync
repo download $GERRIT_PROJECT $GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER

그런데, repo download 명령어는 이전에 사용한 경험이 없어서, help를 찾아보았다.

$ repo help download

Summary

Download and checkout a change

Usage: repo download {[project] change[/patchset]}...

Options:
  -h, --help         show this help message and exit
  -c, --cherry-pick  cherry-pick instead of checkout
  -r, --revert       revert instead of checkout
  -f, --ff-only      force fast-forward merge

Description

The 'repo download' command downloads a change from the review system
and makes it available in your project's local working directory. If no
project is specified try to use current directory as a project.

약간의 시행착오 끝에, 다음과 같이 사용 방법을 확인할 수 있었다.

아래 코드에서 broadcaststack은 저장소 이름이고, 934/9에서 934는 Gerrit의 Change number(리뷰요청번호), 9는 Patchset number 이다.

$ repo download broadcaststack 934/9
From ssh://gerrit.mycompany.net:29418/broadcaststack
 * branch              refs/changes/34/934/9 -> FETCH_HEAD
HEAD is now at 49a307e6 test

 

Jenkins script에서 특정 디렉토리로 이동해서 git fetch하던 방식을, 훨씬 단순하고도 직관적으로 개선할 수 있었다.

그리고, 다시 Patchset을 적용하기 전으로 돌아가기 위해서는 단순히 repo sync를 해주면 되었다.

# AS-IS
cd vendor/google/tv/broadcaststack
git fetch "ssh://gerrit@gerrit.mycompany.net:29418/broadcaststack" ${GERRIT_REFSPEC} && git checkout FETCH_HEAD


# TO-BE
repo download $GERRIT_PROJECT $GERRIT_CHANGE_NUMBER/$GERRIT_PATCHSET_NUMBER

 

'Gerrit' 카테고리의 다른 글

Gerrit 3.1.10 - 이전 설치 ( Migration, Docker )  (0) 2022.05.16
Gerrit 3.5.1 - 설치 ( Docker )  (0) 2022.05.11
Gerrit - LDAP 설정  (0) 2022.05.03
Gerrit - 설치 ( Standalone )  (0) 2022.04.22
Gerrit - 설치 ( Quickstart )  (0) 2022.04.20

+ Recent posts