CapistranoをRails以外で使う方法
CapistranoはRailsと非常に親和性高いんですが、他の言語でも使えます。
例としてEthnaのプロジェクトを capistranize してみます。
1.Ethnaのプロジェクト作成
$ ethna.sh add-project test creating directory (/path/to/project/test) [y/n]: y
2.Rails環境の適用
$ rails rails-tmp $ cp rails-tmp/Rakefile test $ cp -a rails-tmp/config test $ cp rails-tmp/db db $ cp -a rails-tmp/test test $ cp -a rails-tmp/lib/* test/lib $ cp rails-tmp/vendor test/vendor
これでRails環境が動作するようになりました。
プロジェクトのディレクトリ内で Rake -T 等を実行してエラーがでなければOKです。
3.capistranizeの適用
ここからは普通のrailsアプリケーションと同じです。
$ cap -A test
config/deploy.rbを設定するとcapistranoが使えるようになります。
標準のRailsアプリとディレクトリ構成が違うため、それに併せてタスクをオーバーライドします。
config/deploy.rbの最後に以下のコードを追加します。
desc "Set up the expected application directory structure on all boxes" task :setup, :roles => [:app, :db, :web] do run <<-CMD mkdir -p -m 775 #{releases_path} #{shared_path}/system && mkdir -p -m 777 #{shared_path}/log && mkdir -p -m 777 #{shared_path}/tmp && CMD end desc <<-DESC Update all servers with the latest release of the source code. All this does is do a checkout (as defined by the selected scm module). DESC task :update_code, :roles => [:app, :db, :web] do on_rollback { delete release_path, :recursive => true } source.checkout(self) run <<-CMD rm -f #{release_path}/config/id_rsa.contents* && rm -rf #{release_path}/log #{release_path}/tmp && ln -nfs #{shared_path}/log #{release_path}/log && ln -nfs #{shared_path}/tmp #{release_path}/tmp CMD end
その他にもフレームワークによっては変更しなければいけないタスクがあるかもしれません。その場合は
/path/to/rubygemsroot/capistrano-1.2.0/lib/capistrano/recipes/standard.rb から変更するタスクをdeploy.rbにコピーして変更すればOKです。
capistranoのヤバさは実際に体感してみるとわかります。