이 글에서는 기존에 설치되었던 Gerrit 3.1.10 (Docker)를 다른 곳으로 옮겨서 설치한 이력을 정리한다.

 

참고한 글은 다음과 같다.

 

기존에 Gerrit with HTTP authentication 을 참고로 하여, Gerrit 3.1.10을 설치하였다. (http 인증)

추후에 해당 서비스를 이전할 것을 대비하여, 이전 설치 방법을 정리한다.

 

설치 준비

mkdir gerrit_3.1.10 && cd gerrit_3.1.10
touch docker-compose.yml

mkdir gerrit
cp -r $SRC/gerrit/cache gerrit
cp -r $SRC/gerrit/db gerrit
cp -r $SRC/gerrit/etc gerrit
cp -r $SRC/gerrit/git gerrit
cp -r $SRC/gerrit/index gerrit
cp -r $SRC/gerrit/plugins gerrit

mkdir httpd
cp $SRC/httpd/httpd.conf httpd   # 설정파일, 원래 장소에서 복사
cp $SRC/httpd/.htpasswd httpd    # 계정과 암호파일, 원래 장소에서 복사

 

file: docker-compose.yml

version: '3'

services:
  gerrit:
    image: gerritcodereview/gerrit:3.1.10-ubuntu18
    user: root
    ports:
      - "29418:29418"
    volumes:
      - ./gerrit/db:/var/gerrit/db
      - ./gerrit/etc:/var/gerrit/etc
      - ./gerrit/git:/var/gerrit/git
      - ./gerrit/index:/var/gerrit/index
      - ./gerrit/plugins:/var/gerrit/plugins
    environment:
      - CANONICAL_WEB_URL=http://localhost:8100
        #    command: init

  apache:
    image: httpd
    volumes:
      - ./httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf
      - ./httpd/.htpasswd:/usr/local/apache2/conf/.htpasswd
    ports:
       - "8100:80"

시행착오:

  • user: root 로 설정하지 않으면 초기화 과정 중에 에러가 발생한다. 이 에러는 docker내 계정과 호스트 계정과의 공유 디렉토리의 권한 문제인데, 여러가지 시도를 했으나 다른 방법을 찾지 못했다. 이렇게 설정하는 경우에 공유디렉토리 수정시에 sudo 명령으로만 가능하다.
  • 처음에는 gerrit/etc와 gerrit/git만 백업&복구하였으나, Review history등이 복구되지 않아서 나머지 디렉토리도 백업하였다.
  • plugins은 추후에 설치하려고 하였으나, Gerrit 3.1.10에서는 웹 인터페이스에서 설치가 되지 않아, 기존 백업에서 복사하였다.
  • command: init 부분이 아주 중요하다. 이 부분이 없으면, 백업한 자료들을 모두 초기화한다. 기존 자료를 이용하여 초기화 하기 위해서는 주석을 풀고, 실행해주어야 한다. (1회성) 

 

file: gerrit/etc/gerrit.config

[gerrit]
        basePath = git
        canonicalWebUrl = http://localhost:8100/
        serverId = 5618f8c1-7707-41a7-be27-c2f23aa6790c
[index]
        type = lucene
[auth]
        type = http
        logoutUrl = http://aa:aa@localhost:8100/login
        trustContainerAuth = true  # remote로 plugin 설치위해
[receive]
        enableSignedPush = false
[sendemail]
        enable = true
        smtpServer = smtprelay.MYCOMPANY.COM
        smtpServerPort = 25
        smtpUser = SMTPUSER
        smtpPass = SMPTPASS
[user]
        email = no_reply@MYCOMPANY.COM
        anonymousCoward = COMPANY Gerrit
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = http://*:8080/
[cache]
        directory = cache
[commentLink "its-jira"]
        match = \\[([A-Z]+-[0-9]+)\\]
        html = <a href=\"https://jira.MYCOMPANY.COM/browse/$1\">[$1]</a>
        association = SUGGESTED
[its-jira]
        url = https://jira.MYCOMPANY
        username = JIRA-USER
        password = JIRA-PASS
[plugins]
        allowRemoteAdmin = true

시행착오:

  • Gerrit이 초기화하면서 gerrit.config파일에 필요한 사항이 추가된다. 따라서 위에서 설정한 내용을 제외하고는 모두 삭제하였다. 예를 들면 container 섹션은 서버마다 다를 것이므로.
  • gerrit.serverId는 랜덤한 값인데, 새로 셋업하는 경우는 상관이 없지만, 백업&복구하는 경우에는 기존 값을 가져와야 한다. (Gerrit- Invalid Server Id when)
  • auth.trustContainerAuth = true로 설정하지 않으면, 웹 인터페이스에서 플러그인을 설치할 수가 없다. (  Plugin Manager Auth Issue, plugin-manager request different user/password? )
  • sendmail 섹션은 review시에 알림 메일을 보내기 위해 설정하였다.
  • commentLink 섹션은 git message에 Jira Issue의 Link를 생성하는 용도이다.
  • its-jira 섹션은 리뷰 후 merge시에 Jira Issue에 comment를 추가하는 용도이다. comment 추가 사항은 its/actions.config에서 설정한다.
  • plugins.allowRemoteAdmin = true 해주어야 웹 인터페이스에서 플러그인을 관리할 수 있다.

 

file: gerrit/etc/its/actions.config

[rule "merged"]
    event-type = change-merged
    action = add-standard-comment

 

 

다음은  Gerrit with HTTP authentication 에서 참고한 http 인증에 관한 설정이다.

해당 내용의 설명 처럼 아래 부분이 적용되어 있어야 한다.

 

file: httpd/httpd.conf

...
LoadModule proxy_module modules/mod_proxy.so  # 주석제거
...
LoadModule proxy_http_module modules/mod_proxy_http.so # 주석제거
...

# 파일끝에 아래 추가
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
<VirtualHost *>
    ServerName gerrit
    ProxyRequests Off
    ProxyVia Off
    ProxyPreserveHost On

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
<Location "/">
AuthType Basic
AuthName "Gerrit Code Review"
AuthBasicProvider file
AuthUserFile '/usr/local/apache2/conf/.htpasswd'
Require valid-user
</Location>
AllowEncodedSlashes On
ProxyPass / http://gerrit:8080/ nocanon
</VirtualHost>

 

 

설치 실행

먼저 docker-compose.yml의 command 부분 주석을 제거하고 Gerrit의 초기화를 실행한다.

docker-compose up gerrit

 

초기화가 완료되면, 강제로 Ctrl+C으로 종료시킨다.

이후에 다시 docker-compose.yml의 command 부분을 주석처리하고 다시 Gerrit 및 httpd 서비스를 실행한다.

docker-compose up

이후에 Gerrit을 실행하면, 정상적으로 동작함을 확인할 수 있다.

 

Gerrit와 Jira의 연계 테스트를 위해서 하나의 commit을 merge했더니, Jira에 comment가 잘 추가되었다.

 

 

'Gerrit' 카테고리의 다른 글

Gerrit 3.1.10 -> 3.5.1 이전 설치 ( Migration, Docker )  (0) 2022.05.17
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