GitWebで簡単にGitサーバーの情報を閲覧できるようにする
Gitサーバーを単純にたてただけだと、ソースコードの閲覧など Subversion でデフォルトでできていた、以下のような感じのWebページが存在しない。
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
- # yum search gitweb
- Loaded plugins: fastestmirror
- Determining fastest mirrors
- * base: ftp.iij.ad.jp
- * extras: ftp.iij.ad.jp
- * updates: ftp.iij.ad.jp
- base | 3.7 kB 00:00
- extras | 3.4 kB 00:00
- updates | 3.4 kB 00:00
- updates/primary_db | 2.5 MB 00:00
- vz-base | 951 B 00:00
- vz-updates | 951 B 00:00
- ======================================= N/S Matched: gitweb ========================================
- gitweb.noarch : Simple web interface to git repositories
- Name and summary matches only, use "search all" for everything.
yum でインストール
- # yum install -y gitweb
2.Gitのビルド
GitWebの設定をするために、ソースコードから、Gitをビルドする。
Git でソースコードを取得する
- # git clone git://git.kernel.org/pub/scm/git/git.git
- Initialized empty Git repository in /home/piroto/download/git/.git/
- remote: Counting objects: 183667, done.
- remote: Compressing objects: 100% (47770/47770), done.
- remote: Total 183667 (delta 134102), reused 183217 (delta 133864)
- Receiving objects: 100% (183667/183667), 49.28 MiB | 3.70 MiB/s, done.
- Resolving deltas: 100% (134102/134102), done.
GITWEB_PROJECTROOT に、Gitリポジトリのルートパスをを指定して make
- # cd git
- # make GITWEB_PROJECTROOT="/var/www/git" prefix=/usr gitweb
- GIT_VERSION = 2.3.3.262.ge80e85a
- SUBDIR gitweb
- SUBDIR ../
- make[2]: `GIT-VERSION-FILE' is up to date.
- GEN gitweb.cgi
- GEN static/gitweb.js
- # cp -Rf gitweb /var/www
3.VirtualHostの設定
httpd.conf に、rev.typea.info で、GitWebにアクセスできるように VirtualHostの指定を行う。
- <VirtualHost *:80>
- ServerName rev.typea.info
- DocumentRoot /var/www/gitweb
- <Directory /var/www/gitweb>
- Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
- AllowOverride All
- order allow,deny
- Allow from all
- AddHandler cgi-script cgi
- DirectoryIndex gitweb.cgi
- </Directory>
- </VirtualHost>
4.トラブルシュート
以下のようなエラー
- 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.
- BEGIN failed--compilation aborted at /var/www/gitweb/gitweb.cgi line 20.
ライブラリをインストールする。
http://flatworld21.blogspot.jp/2012/04/perlcant-locate-timehirespm.html
- # yum install perl-Time-HiRes
5.Basic認証をかける
ソースコードや設定ファイルには、いろいろなアクセスキーやら、パスワードやらをハードコーディングすることが多いため(昔Amazonのアクセスキーが公開されていると、Amazonから電話がかかってきたことがある)まずいため、上記のVirtualHostの設定を思い直して、Basic認証をかける状態に最低限しておく。
5.1 アカウントの登録
- # cd /etc/httpd
- # htpasswd /etc/httpd/.passwd git
- New password:
- Re-type new password:
- Adding password for user git
5.2 VirtualHostの書き直し
- <VirtualHost *:80>
- ServerName rev.typea.info
- DocumentRoot /var/www/gitweb
- <Directory /var/www/gitweb>
- Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
- AllowOverride All
- order allow,deny
- Allow from all
- AddHandler cgi-script cgi
- DirectoryIndex gitweb.cgi
- </Directory>
- <Directory "/">
- AuthType Basic
- AuthName "Git Repository"
- AuthUserFile /etc/httpd/.passwd
- Require user git
- </Directory>
- </VirtualHost>
6.出来上がり
6.1 httpd のリスタート
- # /sbin/service httpd restart
6.2 Basic認証
6.3 プロジェクトのソースコードが閲覧可能に!
もちろん、コミット履歴やログやタグなんかも確認できます。便利!