capistranoでデプロイ自動化
capistranoでかずー氏アイコンジェネレーターのデプロイを自動化した。
あとはjenkinsと組み合わせてテスト駆動開発を進めていきたい。
ということで設定したcapistranoのメモを。
インストール
gemで配布されてる。
gem install capistrano
初期設定
capifyコマンドで入れられる!
capify . [add] writing './Capfile' [add] making directory './config' [add] writing './config/deploy.rb' [done] capified!
あとはconfig/deploy.rbに設定を書いていけばOK.
いちお、自分のものを重要なところ隠しつつ載せると
set :application, "kazooshi_gen" set :repository, "git@your.repository.path.git" set :scm, :git # Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none` set :user, "app_server_user_name" set :use_sudo, false set :port, 22 set :deploy_to, "set_to_app_path" ssh_options[:forward_agent] = true ssh_options[:keys] = '/path/to/your/id_rsa/for/app_server/' role :web, "moosan.org" # Your HTTP server, Apache/etc role :app, "moosan.org" # This may be the same as your `Web` server #role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run #role :db, "your slave db-server here" # if you want to clean up old releases on each deploy uncomment this: # after "deploy:restart", "deploy:cleanup" # if you're still using the script/reaper helper you will need # these http://github.com/rails/irs_process_scripts # If you are using Passenger mod_rails uncomment this: namespace :deploy do task :start do ; end task :stop do ; end task :restart, :roles => :app, :except => { :no_release => true } do run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}" end end
これを書き終わったら
cap deploy
これで終わり!
デプロイ先に指定したディレクトリに
current release
という2つのディレクトリができてるはず。
releaseは今までのデプロイされたものが全て入っていて、currentは最新のreleaseのシンボリックリンク。
もうちょっと色々と設定できるけど、まだ全部は把握してないのでそのうちまとめる
・ω・