GitWebで簡単にGitサーバーの情報を閲覧できるようにする

Gitサーバーを単純にたてただけだと、ソースコードの閲覧など Subversion でデフォルトでできていた、以下のような感じのWebページが存在しない。

subversion_browse

GitHub とか Bitbucket とか使ってれば、そんなこと気にしなくてもよいのだが、まぁ諸般の事情で独自にGitサーバーを構築したいこともあるだろう。

ということで、GitWebがお手軽そうなので、試してみる。

環境は、レンタルサーバーのCentOS6.3

1.インストール

http://git-scm.com/book/ja/v1/Git-%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC-GitWeb

  1. # yum search gitweb
  2. Loaded plugins: fastestmirror
  3. Determining fastest mirrors
  4. * base: ftp.iij.ad.jp
  5. * extras: ftp.iij.ad.jp
  6. * updates: ftp.iij.ad.jp
  7. base | 3.7 kB 00:00
  8. extras | 3.4 kB 00:00
  9. updates | 3.4 kB 00:00
  10. updates/primary_db | 2.5 MB 00:00
  11. vz-base | 951 B 00:00
  12. vz-updates | 951 B 00:00
  13. ======================================= N/S Matched: gitweb ========================================
  14. gitweb.noarch : Simple web interface to git repositories
  15.  
  16. Name and summary matches only, use "search all" for everything.

yum でインストール

  1. # yum install -y gitweb

2.Gitのビルド

GitWebの設定をするために、ソースコードから、Gitをビルドする。

Git でソースコードを取得する

  1. # git clone git://git.kernel.org/pub/scm/git/git.git
  2. Initialized empty Git repository in /home/piroto/download/git/.git/
  3. remote: Counting objects: 183667, done.
  4. remote: Compressing objects: 100% (47770/47770), done.
  5. remote: Total 183667 (delta 134102), reused 183217 (delta 133864)
  6. Receiving objects: 100% (183667/183667), 49.28 MiB | 3.70 MiB/s, done.
  7. Resolving deltas: 100% (134102/134102), done.

GITWEB_PROJECTROOT に、Gitリポジトリのルートパスをを指定して make

  1. # cd git
  2. # make GITWEB_PROJECTROOT="/var/www/git" prefix=/usr gitweb
  3. GIT_VERSION = 2.3.3.262.ge80e85a
  4. SUBDIR gitweb
  5. SUBDIR ../
  6. make[2]: `GIT-VERSION-FILE' is up to date.
  7. GEN gitweb.cgi
  8. GEN static/gitweb.js
  9. # cp -Rf gitweb /var/www

3.VirtualHostの設定

httpd.conf に、rev.typea.info で、GitWebにアクセスできるように VirtualHostの指定を行う。

  1. <VirtualHost *:80>
  2. ServerName rev.typea.info
  3. DocumentRoot /var/www/gitweb
  4. <Directory /var/www/gitweb>
  5. Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
  6. AllowOverride All
  7. order allow,deny
  8. Allow from all
  9. AddHandler cgi-script cgi
  10. DirectoryIndex gitweb.cgi
  11. </Directory>
  12. </VirtualHost>

4.トラブルシュート

以下のようなエラー

  1. Can't locate Time/HiRes.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at /var/www/gitweb/gitweb.cgi line 20.
  2. BEGIN failed--compilation aborted at /var/www/gitweb/gitweb.cgi line 20.

ライブラリをインストールする。

http://flatworld21.blogspot.jp/2012/04/perlcant-locate-timehirespm.html

  1. # yum install perl-Time-HiRes

5.Basic認証をかける

ソースコードや設定ファイルには、いろいろなアクセスキーやら、パスワードやらをハードコーディングすることが多いため(昔Amazonのアクセスキーが公開されていると、Amazonから電話がかかってきたことがある)まずいため、上記のVirtualHostの設定を思い直して、Basic認証をかける状態に最低限しておく。

5.1 アカウントの登録

  1. # cd /etc/httpd
  2. # htpasswd /etc/httpd/.passwd git
  3. New password:
  4. Re-type new password:
  5. Adding password for user git

5.2 VirtualHostの書き直し

  1. <VirtualHost *:80>
  2. ServerName rev.typea.info
  3. DocumentRoot /var/www/gitweb
  4. <Directory /var/www/gitweb>
  5. Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
  6. AllowOverride All
  7. order allow,deny
  8. Allow from all
  9. AddHandler cgi-script cgi
  10. DirectoryIndex gitweb.cgi
  11. </Directory>
  12. <Directory "/">
  13. AuthType Basic
  14. AuthName "Git Repository"
  15. AuthUserFile /etc/httpd/.passwd
  16. Require user git
  17. </Directory>
  18. </VirtualHost>

6.出来上がり

6.1 httpd のリスタート

  1. # /sbin/service httpd restart

6.2 Basic認証

gitweb_basic_auth

6.3 プロジェクトのソースコードが閲覧可能に!

もちろん、コミット履歴やログやタグなんかも確認できます。便利!

gitweb02

Follow me!

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です