Mercurial on CentOS でバージョン管理(+ mod_wsgi)
ソースコードのバージョン管理として Mercurial を導入してみました。お勧めらしい mod_wsgi の導入も何とかできたので、記録として残しておきます。
GitHubを使ってみようと Eclipse + EGit も試してみたんですが、EGit の動きがイマイチよろしくなかった印象が…そんなこともあって、Google code の Mercurial を試した結果が割と良かったので、とあるプロジェクトで実用できるか環境構築も含めて評価してみることにしました。
Git や Mercurial は CVS、Subversion などのようなシングルリポジトリではなく、分散型バージョン管理ができる次世代(もう”現代”と言っても良いと思うけど)ツールです。Subversion の居心地に慣れきった方も一度使ってみることをお勧めします。HTTP経由で push / pull できるところが魅力なんだと私は思ってます、ハイ。
1. Mercurial をインストールする
# yum install mercurial
2. mod_wsgi をソースからコンパイルし、インストールする
$ wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
$ tar xfv mod_wsgi-3.3
$ cd mod_wsgi-3.3
$ ./configure
$ make
$ su -c "make install"
3. /etc/mercurial/hgrc を作成する
確か mod_wsgi など、hgwebdir で HTTP 経由での push はデフォルトoff になっていたはずなので、そのおまじないと考える。
社内イントラでセキュリティ保護を考えなくて良い場合に push_ssl = false とすれば良い
[web]
allow_push = *
push_ssl = false
4. /etc/httpd/conf.d/hg.conf を作成する(httpd.conf に直接追加でもお好きなように。)
ちなみに Location ディレクティブでDigest認証をするように設定していますが、いらないかもしれません。pushするときの認証に必要です。(1/28修正)
LoadModule wsgi_module modules/mod_wsgi.so
<VirtualHost *:80>
ServerName hoge
DocumentRoot /var/www/html
ErrorLog /var/log/httpd/hoge-error_log
CustomLog /var/log/httpd/hoge-access_log common
WSGIScriptAlias /hg /var/www/wsgi-bin/hgwebdir.wsgi
<Directory /var/www/wsgi-bin>
Options ExecCGI FollowSymlinks
AddHandler wsgi-script .wsgi
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Location /hg>
AuthType Digest
AuthName "Mercurial"
AuthDigestProvider file
AuthUserFile /var/lib/hg/hgusers
<LimitExcept GET>
Require valid-user
</LimitExcept>
</Location>
</VirtualHost>
5. /var/www/wsgi-bin/hgwebdir.wsgi を作成する(4. の WSGIScriptAlias のパスと合わせれば良い)
from mercurial import demandimport; demandimport.enable()
application = hgwebdir('/var/www/wsgi-bin/hgwebdir.config')
from mercurial.hgweb.hgwebdir_mod import hgwebdir
6. /var/www/wsgi-bin/hgwebdir.config を作成する(5. の hgwebdir 引数と合わせれば良い、はず)
[collections]
/var/lib/hg = /var/lib/hg
7. /var/lib/hg/hgusers を作成する
ここで作成したユーザーが Mercurial にアクセスできるユーザーになります。
(1/28追記) 4.の AuthNameで定義した値と realm が一致する必要があるので注意。ここでハマりました…
# htdigest [-c /var/lib/hg/hgusers] 'Mercurial' hguser
8. Apache 再起動
# service httpd restart