GitWeb 설치 및 Gerrit과의 연동 설정

1 - GitWeb 소개

GitWeb는 웹 페이지에서 코드와 커밋 정보를 볼 수 있게 지원하는 도구입니다. GitWeb 도구를 설치하고 Gerrit에 통합하면 Gerrit의 프로젝트 목록에서 직접 프로젝트의 코드 정보를 확인할 수 있습니다.

2 - GitWeb 설치

Gerrit 서비스를 시작합니다:

[gerrit@mt101 ~]$ sudo gerrit_testsite/bin/gerrit.sh start
Gerrit Code Review 시작: OK
[gerrit@mt101 ~]$ 
[gerrit@mt101 ~]$ sudo service nginx start
/bin/systemctl start nginx.service로 리디렉션
[gerrit@mt101 ~]$

yum을 사용하여 GitWeb를 설치합니다:

[gerrit@mt101 ~]$ sudo yum -y install gitweb
Loaded plugins: fastestmirror, langpacks
캐시된 호스트 파일에서 미러 속도 로딩 중
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                          | 3.6 kB  00:00:00     
extras                                                                        | 2.9 kB  00:00:00     
mongodb-org-4.0                                                               | 2.5 kB  00:00:00     
nginx-stable                                                                  | 2.9 kB  00:00:00     
updates                                                                       | 2.9 kB  00:00:00     
의존성 확인 중
--> 트랜잭션 확인 실행
---> Package gitweb.noarch 0:1.8.3.1-20.el7 will be installed
--> 의존성 확인 완료

의존성 확인됨

=====================================================================================================
 패키지               아키텍처                  버전                        저장소           크기
=====================================================================================================
설치 중:
 gitweb                noarch                1.8.3.1-20.el7                base                112 k

트랜잭션 요약
=====================================================================================================
설치  1 패키지

총 다운로드 크기: 112 k
설치된 크기: 320 k
패키지 다운로드 중:
gitweb-1.8.3.1-20.el7.noarch.rpm                                              | 112 kB  00:00:07     
트랜잭션 확인 실행
트랜잭션 테스트 실행
트랜잭션 테스트 성공
트랜잭션 실행 중
  설치 중 : gitweb.noarch 0:1.8.3.1-20.el7                                                      1/1 
  확인 중  : gitweb.noarch 0:1.8.3.1-20.el7                                                      1/1 

설치됨:
  gitweb.noarch 0:1.8.3.1-20.el7                                                                     
                                                                
완료!
[gerrit@mt101 ~]$

3 - projectroot 디렉토리 설정

설정 파일: `/etc/gitweb.conf`

[gerrit@mt101 ~]$ sudo vim /etc/gitweb.conf
[gerrit@mt101 ~]$ sudo cat /etc/gitweb.conf |grep -v "#" |grep -Ev "^$"
our $projectroot = "/home/gerrit/gerrit_testsite/git"
[gerrit@mt101]$

4 - GitWeb의 httpd 서비스 설정

4.1 GitWeb 경로 설정

GitWeb는 httpd 서비스 기반으로 작동하며, 설정 파일은 `/etc/httpd/conf.d/git.conf`입니다.

[gerrit@mt101 ~]$ sudo cat /etc/httpd/conf.d/git.conf
Alias /git /var/www/git

<Directory /var/www/git>
  Options +ExecCGI
  AddHandler cgi-script .cgi
  DirectoryIndex gitweb.cgi
</Directory>
[gerrit@mt101 ~] 
[gerrit@mt101 ~]$ sudo vim /etc/httpd/conf.d/git.conf
[gerrit@mt101 ~] 
[gerrit@mt101 ~]$ sudo cat /etc/httpd/conf.d/git.conf
Alias /gitweb /var/www/git
SetEnv GITWEB_CONFIG /etc/gitweb.conf
<Directory /var/www/git>
  Options +ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
  AllowOverride All
  order allow,deny
  Allow from all
  AddHandler cgi-script .cgi
  DirectoryIndex gitweb.cgi
</Directory>
[gerrit@mt101 ~]

4.2 서비스 포트 설정

`/etc/httpd/conf/httpd.conf`에서 서비스 포트를 설정합니다:

[gerrit@mt101 ~]$ sudo cat /etc/httpd/conf/httpd.conf |grep -v "#" |grep -Ev "^$" |grep -i listen
Listen 80
[gerrit@mt101 ~] 
[gerrit@mt101 ~]$ sudo vim /etc/httpd/conf/httpd.conf
[gerrit@mt101 ~]$ sudo cat /etc/httpd/conf/httpd.conf |grep -v "#" |grep -Ev "^$" |grep -i listen
Listen 8084
[gerrit@mt101]$

4.3 httpd 서비스 재시작

[gerrit@mt101 ~]$ sudo systemctl restart httpd.service
[gerrit@mt101 ~]$ sudo systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-12-10 22:57:22 CST; 9s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 3432 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 3439 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
    Tasks: 7
   CGroup: /system.slice/httpd.service
           ├─3439 /usr/sbin/httpd -DFOREGROUND
           ├─3440 /usr/sbin/httpd -DFOREGROUND
           ├─3441 /usr/sbin/httpd -DFOREGROUND
           ├─3442 /usr/sbin/httpd -DFOREGROUND
           ├─3443 /usr/sbin/httpd -DFOREGROUND
           ├─3444 /usr/sbin/httpd -DFOREGROUND
           └─3445 /usr/sbin/httpd -DFOREGROUND

Dec 10 22:57:16 mt101 systemd[1]: Starting The Apache HTTP Server...
Dec 10 22:57:21 mt101 httpd[3439]: AH00558: httpd: Could not reliably determine the server's f...sage
Dec 10 22:57:22 mt101 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[gerrit@mt101 ~]

4.4 방화벽 열기

[gerrit@mt101 ~]$ sudo firewall-cmd --zone=public --permanent --add-port=8084/tcp
success
[gerrit@mt101 ~]$ sudo firewall-cmd --reload
success
[gerrit@mt101 ~]$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3 enp0s8
  sources: 
  services: ssh dhcpv6-client
  ports: 8080/tcp 80/tcp 83/tcp 8083/tcp 8084/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
    
[gerrit@mt101 ~]

5 - GitWeb 접속

6 - Gerrit과의 연동

6.1 Gerrit 설정 파일 업데이트

다음 부분을 추가합니다:

[gitweb]
       type = gitweb       
       cgi = /var/www/git/gitweb.cgi
[gerrit@mt101 ~]$ sudo vim gerrit_testsite/etc/gerrit.config 
[gerrit@mt101 ~]$ sudo cat gerrit_testsite/etc/gerrit.config 
[gerrit]
    basePath = git
    canonicalWebUrl = http://192.168.16.101:8083/
    serverId = 0b911b9e-195a-46b0-a5cd-b407b776b344
[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 = root
    javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre
[index]
    type = lucene
[auth]
    type = HTTP
[receive]
    enableSignedPush = false
[sendemail]
    smtpServer = localhost
[sshd]
    listenAddress = *:29418
[httpd]
    listenUrl = http://192.168.16.101:8083/
[cache]
    directory = cache
[gitweb]
       type = gitweb       
       cgi = /var/www/git/gitweb.cgi
[gerrit@mt101 ~] 

6.2 git 설정 수정

[gerrit@mt101 ~]$ git config --file /home/gerrit/gerrit_testsite/etc/gerrit.config gitweb.cgi /var/www/git/ gitweb.cgi
[gerrit@mt101 ~]$ git config --file /home/gerrit/gerrit_testsite/etc/gerrit.config --unset gitweb.url
[gerrit@mt101 ~]$

6.3 Gerrit 서비스 재시작

[gerrit@mt101 ~]$ sudo gerrit_testsite/bin/gerrit.sh restart
Gerrit Code Review 중지: OK
Gerrit Code Review 시작: OK
[gerrit@mt101 ~]$

6.4 다시 로그인하여 GitWeb 링크 확인

BROWSE---》Repositories---》Repository Browser---》gitweb 링크

All-Projects의 gitweb 링크를 클릭합니다.

6.5 GitWeb 접근 권한 설정

기본적으로 Gerrit 관리자 사용자만 GitWeb에 접근할 수 있습니다.

BROWSE---》Repositories---》All-Projects---》Access---》Reference: refs/meta/config

"refs/meta/config"의 Read 옵션에 "Registered Users"의 ALLOW 권한을 추가합니다.

태그: Gerrit GitWeb 코드 리뷰 버전 관리

6월 1일 18:19에 게시됨