Gerrit Server - Code Review Server on Linux

  1. 安裝java執行環境

  2. 安裝MySQL Server

    • (Ubuntu)可至Ubuntu軟體中心 ,下載並安裝MySQL伺服器與MySQL管理員進行管理

    • 設定MySQL

      mysql -u root -p
      CREATE USER 'gerrit'@'localhost' INDENTIFIED BY 'secret';
      CREATE DATABASE reviewdb;
      ALTER DATABASE reviewdb charset=latin1;
      GRANT ALL ON reviewdb.* TO 'gerrit'@'localhost';
      FLUSH PRIVILEGES;
      
  3. 安裝Apache Server

    • 安裝Apache Server

      sudo apt-get install apache2 apache2-dev
      
    • 安裝Apache proxy模組

      sudo a2nemod proxy
      sudo a2nemod proxy_http
      
    • 設定Apache Server代理登錄

      vim /etc/apache2/sites-available/default
      

      vim /etc/apache2/httpd.conf
      
      Listen 8082
      Listen 8083
      Listen 8084
      <VirtualHost *:8082>
        ServerName localhost
        ProxyRequests Off
        ProxyVia Off
        ProxyPreserveHost On
        <Proxy *>
           Order deny,allow
           Allow from all
        </Proxy>
        <Location /login/>
           AuthType Basic
           AuthName "Gerrit Code Review"
           AuthBasicProvider file
           AuthUserFile /home/gerrit/review_site/etc/gerrit.passwd
           Require valid-user
        </Location>
        AllowEncodedSlashes On
        ProxyPass / http://localhost:8081/ nocanon
      </VirtualHost>
      <VirtualHost *:8083>
        ServerName Redmine
        DocumentRoot /home/redmine/redmine_site/public/
        <Directory /home/redmine/redmine_site/public/>
           Options Indexes ExecCGI FollowSymLinks
           Order allow,deny
           Allow from all
           AllowOverride all
        </Directory>
      </VirtualHost>
      <VirtualHost *:8084>
        ServerName PhpMyAdmin
        DocumentRoot /usr/share/phpmyadmin
        <Directory /usr/share/phpmyadmin>
           Options Indexes ExecCGI FollowSymLinks
           Order allow,deny
           Allow from all
           AllowOverride all
        </Directory>
      </VirtualHost>
      
    • 啟動Apache Server

      sudo /etc/init.d/apache2 restart
      
  4. 安裝Gerrit Server

    • 建立Gerrit專用帳號

      sudo adduser gerrit
      sudo su gerrit
      cd ~gerrit

    • 安裝Gerrit V2.7 (下載Gerrit的.war包至/home/gerrit)

      java -jar gerrit-2.7.war init -d review_site

    • 設定Gerrit Server

      vim /home/gerrit/review_site/etc/gerrit.config
      
      [gerrit]
              basePath = git
              canonicalWebUrl = http://220.132.142.166:8082/
      [database]
              type = mysql
              hostname = localhost
              database = reviewdb
              username = gerrit
      [auth]
              type = HTTP
      [sendemail]
              smtpServer = smtp.gmail.com
              smtpServerPort = 465
              smtpEncryption = SSL
              smtpUser = xunyi.lee@gmail.com
      [container]
              user = gerrit
              javaHome = /usr/lib/jvm/java-7-oracle/jre
      [sshd]
              listenAddress = *:29418
      [httpd]
              listenUrl = proxy-http://localhost:8081/
      [cache]
              directory = cache
      [gitweb]
              cgi = /usr/share/gitweb/index.cgi
      
    • 增加Gerrit 用戶

      sudo htpasswd -c /home/gerrit/review_site/etc/gerrit.passwd 用戶名稱
      
    • 啟動Gerrir Server

      vim /home/gerrit/review_site/bin/gerrit.sh
      
      GERRIT_SITE=/home/gerrit/review_site
      NO_START=0
      
      /home/gerrit/review_site/bin/gerrit.sh restart
      sudo ln -s /home/gerrit/review_site/bin/gerrit.sh /etc/init.d/
      sudo /etc/init.d/gerrit.sh restart
      
  5. Gerrit用戶認證

    • 使用建立的Gerrit用戶帳號與密碼,登入Web,
    • 第一個登入的帳號為Administrator,
    • 進入setting填入Email認證,
    • 並加入Public SSH Key
  6. Gerrit增加Label-Verified

    mkdir tmp
    cd tmp
    git init
    git remote add origin ssh://admin@remote.site.com:29418/All-Projects
    git fetch origin refs/meta/config:refs/remotes/origin/meta/config
    git checkout meta/config
    vim project.config
    
    [label "Verified"]
            function = MaxWithBlock
            value = -1 Fails
            value = 0 No score
            value = +1 Verified
    
    git add *
    git config --global user.name "Neil Lee"
    git config --global user.email xunyi.lee@gmail.com
    git commit -m "Add label'verfied'"
    git push origin meta/config
    
  1. 設定Gerrit Web中使用中文註解

    • 設定Gerrit MySQL Server連線設定

      vim /home/gerrit/review_site/etc/gerrit.config
      
      [database]
              type = mysql
              url = jdbc:mysql://localhost:3306/reviewdb?user=gerrit&useUnicode=true&characterEncoding=utf8
      
    • 設定Gerrit database in MySQL Server

      mysql -u gerrit -p
      ALTER DATABASE reviewdb charset=utf8;
      use reviewdb;
      alter table account_diff_preferences engine=innodb;
      alter table account_external_ids engine=innodb;
      alter table account_group_id engine=innodb;
      alter table account_group_includes_by_uuid engine=innodb;
      alter table account_group_includes_by_uuid_audit engine=innodb;
      alter table account_group_members engine=innodb;
      alter table account_group_members_audit engine=innodb;
      alter table account_group_names engine=innodb;
      alter table account_groups engine=innodb;
      alter table account_id engine=innodb;
      alter table account_patch_reviews engine=innodb;
      alter table account_project_watches engine=innodb;
      alter table account_ssh_keys engine=innodb;
      alter table accounts engine=innodb;
      alter table change_id engine=innodb;
      alter table change_message_id engine=innodb;
      alter table change_messages engine=innodb;
      alter table changes engine=innodb;
      alter table patch_comments engine=innodb;
      alter table patch_set_ancestors engine=innodb;
      alter table patch_set_approvals engine=innodb;
      alter table patch_sets engine=innodb;
      alter table schema_version engine=innodb;
      alter table starred_changes engine=innodb;
      alter table submodule_subscriptions engine=innodb;
      alter table system_config engine=innodb;
      alter table tracking_ids engine=innodb;
      ALTER TABLE account_diff_preferences CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_external_ids CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_group_id CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_group_includes_by_uuid CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_group_includes_by_uuid_audit CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_group_members CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_group_members_audit CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_group_names CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_id CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_patch_reviews CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_project_watches CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE account_ssh_keys CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE accounts CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE change_id CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE change_message_id CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE change_messages CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE changes CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE patch_comments CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE patch_set_ancestors CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE patch_set_approvals CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE patch_sets CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE schema_version CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE starred_changes CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE submodule_subscriptions CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE system_config CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      ALTER TABLE tracking_ids CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
      
  2. 設定Gerrit提供gitweb瀏覽repo

    • 安裝gitweb

      sudo apt-get install gitweb
      
    • 設定gitweb

      vim /home/gerrit/review_site/etc/gerrit.config
      
      [gitweb]
              cgi = /usr/share/gitweb/index.cgi