プログラミングノート

一からものを作ることが好きなエンジニアの開発ブログです。

RedmineとGitで作るプロジェクト開発環境

今メインで利用しているマシンにTracを入れようかどうか迷っていたのですが、入れるのが面倒だったのでちょっと前から話題になっているRedmineを入れてみました。


環境はこんな感じです。

Redmineインストール

1. RedmineSVNからソースを取得

$ svn checkout http://redmine.rubyforge.org/svn/branches/0.8-stable redmine


2. redmine/config/database.ymlでMySQLの設定を修正してDBを初期化

$ cd redmine
$ rake db:create RAILS_ENV=production
$ rake db:migrate RAILS_ENV=production
$ rake load_default_data RAILS_ENV=production


3. 起動して動作確認

$ script/server -e production

これでとりあえずは利用できるようになりました。
PCを立ち上げて毎回起動するのは面倒なので、Apacheから起動できるようにします。

Passengerのインストールと設定

passengerはgemから入るので簡単。インストール中に表示されるメッセージにhttpd.confの設定が記載されているので忘れずにメモしておきます。Apacheをソースからインストールしている場合は環境変数を設定する必要があるみたいです。

# gem install passenger
# export APXS2=/usr/local/httpd/bin/apxs 
# passenger-install-apache2-module


httpd.confに設定を追加します。

LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.2.2/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.2.2
PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby


今回は、http://localhost/で今まで通りドキュメントルートにアクセスし、http://redmine/Redmineにアクセス出来るようにしたかったので下記のようにVirtualHostを設定しました。

<Directory "/usr/local/httpd/rails/">
   Options Indexes FollowSymLinks
   AllowOverride None
   Order allow,deny
   Allow from all
</Directory>

NameVirtualHost *:80

<Virtualhost *:80>
 ServerName localhost
 DocumentRoot /usr/local/httpd/htdocs
</VirtualHost>

<Virtualhost *:80>
 ServerName redmine
 DocumentRoot /usr/local/httpd/rails/redmine/public
</VirtualHost>


/etc/hostsにも設定を追加。

127.0.0.1       localhost
127.0.0.1       redmine


後はApacheを再起動すれば終了です。Apache自動起動にしているので、これでPC起動した段階でRedmineにアクセス出来るようになりました。Railsの開発環境が入っていればすぐにセットアップ出来るので、Trac入れるより大分楽でした。

Gitと連携させる

RedmineSubversion、Darcs、MercurialCvs、Bazaar、Gitの6種類からSCMを選択出来る仕組みになっていたので、今回はちょっと前から利用しているGitで試してみました。

Gitの準備

まずはローカル管理用のGitをまとめるディレクトリを生成しておきます。

# mkdir /git
# chmod 777 /git
$ cd /git


次に、Redminedで管理するプロジェクト用のGitを生成します。

$ mkdir /git/proj
$ cd /git/proj
$ git --bare init


最後に、開発中のプロジェクトを上記Gitにpushします。

$ cd /path/to/proj
$ git init
$ git add .
$ git commit -m 'init repo'
$ git remote add local /git/proj
$ git push local master
Redmineでの設定

管理者でRedmineにログインし、プロジェクト選択 > 設定 > リポジトリ から上記リポジトリを指定すれば、ブラウザ上で変更履歴が確認できるようになります。

SCM: Git
Path to .git directory: /git/proj

githubから持ってくる

githubからプロジェクトを持ってきてRedmine管理にする方法です。
githubから取得したプロジェクトをそのままローカルGitにpushします。

$ mkdir /git/iphone-samples
$ cd /git/iphone-samples
$ git --bare init
$ cd
$ git clone git@github.com:ntaku/iphone-samples.git
$ cd iphone-samples
$ git remote add local /git/iphone-samples
$ git push local master


ということで、今回は特にはまりポイントもなくスムーズに導入出来ました。まだあまり使ってませんが、入れるのは楽だし複数プロジェクトも見やすいので、個人的にはTracよりこっちのが好き。

追記

今日見てみるとGitリポジトリのブラウズが何故か出来なくなっていたので、下記の修正を追加したところ復帰しました。

/path/to/redmine/lib/redmine/scm/adapters/git_adapter.rb

# Git executable name
# GIT_BIN = "git"
GIT_BIN = "/usr/local/git/bin/git"