EC2にKanonとtrac-code-comments-pluginをインストールする


Kanonとは?

Kanon

Trac/Maven/Jenkinsを一括インストールするツール
(Trac LightningのLinux版)

Kanon LAB (公式サイトだが繋がらない?)
okamototk / KanonConductor — Bitbucket

trac-code-comments-plugin

Trac(Kanon)のリポジトリブラウザ上でコードに対するコメントを付けることが出来るようになるプラグイン
Automattic/trac-code-comments-plugin

Tracには他にも同様のプラグインがいくつかあるが、これが一番新しそうで、使いやすそうに見えた。
(リポジトリもGithubにあるし)

環境

使用環境

AWS EC2のRed Hat Enterprise Linux 7.0 (HVM), SSD Volume Type - ami-99bef1a9を利用する。

準備

yum updateとMercurial,gitのインストールをしておく。
(Kanon上のリポジトリとしてsvn,bazaarを使用する場合は併せてインストールしておく)

sudo yum update
sudo yum install -y hg git

Kanon インストール

BitBucketに書いてある手順どおりに。
okamototk / KanonConductor — Bitbucket

Kanon ソースの取得

BitBucketではMercurialを使用してクローンする。

hg clone https://bitbucket.org/okamototk/kanonconductor

Kanon インストール

コマンド一発で。

cd kanonconductor
sudo ./kanon-setup

幾つか質問されるので、それなりに答えるだけでインストール完了。
自分の環境では、/opt/kanonにKanonがインストールされた。
また、サンプルプロジェクトが/var/opt/kanon/trac/SampleProjectに作成されていた。

trac関連のコマンドを実行出来るようにするために/opt/kanon/binにパスを通しておく。

export PATH=/opt/kanon/bin:$PATH

Kanonにアクセス

インストールが完了した時点で、Kanonのhttpdによるサーブも完了しており、http://${IP}/tracでKanonプロジェクトにアクセスできる。

新たにKanonプロジェクトを作成したい場合はkanon-create-projectコマンドにより行う。
いくつかの質問に答えるだけでプロジェクトを作成できる。

trac-code-comments-pluginのインストール

Kanonのリポジトリブラウザでコードに対するコメントを残せるtrac-code-comment-pluginをインストールする。
Automattic/trac-code-comments-plugin

trac-code-comments-plugin ソースの取得

Githubよりクローンする。

git clone https://github.com/Automattic/trac-code-comments-plugin

trac-code-comment-plugin のインストール

git cloneしたソースよりeggファイルを作成する。
(python 2.4+ が必要)

cd trac-code-comments-plugin
python setup.py bdist_egg

これで、distディレクトリにeggファイルが作成されるので、このeggファイルを${TRAC_PROJECT}/plugins配下に移動する。
今回はKanonインストール時に作成されたSampleProjectにインストールする。

sudo mv dist/TracCodeComments-1.1.1-py2.6.egg /var/opt/kanon/trac/SampleProject/plugins
sudo chown apache:apache /var/opt/kanon/trac/SampleProject/plugins/TracCodeComments-1.1.1-py2.6.egg

これで、httpdを再起動すればインストールが完了するはずだが、自分の環境ではエラーとなった。

Traceback (most recent call last):
  File "/opt/kanon/lib/python2.6/site-packages/Trac-0.12.4.ja1-py2.6.egg/trac/web/api.py", line 446, in send_error
    data, 'text/html')
  File "/opt/kanon/lib/python2.6/site-packages/Trac-0.12.4.ja1-py2.6.egg/trac/web/chrome.py", line 835, in render_template
    template = self.load_template(filename, method=method)
  File "/opt/kanon/lib/python2.6/site-packages/Trac-0.12.4.ja1-py2.6.egg/trac/web/chrome.py", line 796, in load_template
    self.get_all_templates_dirs(), auto_reload=self.auto_reload,
  File "/opt/kanon/lib/python2.6/site-packages/Trac-0.12.4.ja1-py2.6.egg/trac/web/chrome.py", line 511, in get_all_templates_dirs
    dirs.extend(provider.get_templates_dirs() or [])
  File "build/bdist.linux-x86_64/egg/code_comments/web.py", line 25, in get_templates_dirs
    return [self.get_template_dir()]
  File "build/bdist.linux-x86_64/egg/code_comments/web.py", line 29, in get_template_dir
    return resource_filename(__name__, 'templates')
  File "/opt/kanon/lib/python2.6/site-packages/distribute-0.6.14-py2.6.egg/pkg_resources.py", line 869, in resource_filename
    self, resource_name
  File "/opt/kanon/lib/python2.6/site-packages/distribute-0.6.14-py2.6.egg/pkg_resources.py", line 1345, in get_resource_filename
    return self._extract_resource(manager, zip_path)
  File "/opt/kanon/lib/python2.6/site-packages/distribute-0.6.14-py2.6.egg/pkg_resources.py", line 1352, in _extract_resource
    manager, os.path.join(zip_path, name)
  File "/opt/kanon/lib/python2.6/site-packages/distribute-0.6.14-py2.6.egg/pkg_resources.py", line 1370, in _extract_resource
    self.egg_name, self._parts(zip_path)
  File "/opt/kanon/lib/python2.6/site-packages/distribute-0.6.14-py2.6.egg/pkg_resources.py", line 949, in get_cache_path
    self.extraction_error()
  File "/opt/kanon/lib/python2.6/site-packages/distribute-0.6.14-py2.6.egg/pkg_resources.py", line 915, in extraction_error
    raise err
ExtractionError: Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

  [Errno 13] Permission denied: '/var/opt/kanon/trac/.egg-cache'

The Python egg cache directory is currently set to:

  /var/opt/kanon/trac/.egg-cache

Perhaps your account does not have write access to this directory?  You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.

どうやら、eggファイルを展開する場合、.egg-cacheディレクトリを作成する必要があるらしい。
ので、apacheがアクセスできる.egg-cacheディレクトリを作成する。

sudo mkdir /var/opt/kanon/trac/.egg-cache
sudo chown apache:apache /var/opt/kanon/trac/.egg-cache

Kanonの上部メニューにCode Commentsメニューが表示されていればインストール完了。
(ログインする必要あり)

コードレビュー

  • リポジトリブラウザのコード上に表示されるコメントアイコンをクリック

  • ダイアログが表示されるのでコメントを入力する(Trac Wiki記法が使える)

  • 下記の形式でコメントが表示される(コメントを縮小表示はできなそう…)

  • Code Commentメニューでは、作成されたコメント一覧を見ることができる