Created
April 22, 2010 06:45
-
-
Save koseki/374898 to your computer and use it in GitHub Desktop.
Capistrano without Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# この行を追加。デフォルトだと-fでCapfileを指定したときにエラーになる。 | |
Dir.chdir(File.dirname(__FILE__)) | |
load 'deploy' if respond_to?(:namespace) # cap2 differentiator | |
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } | |
load 'config/deploy' # remove this line to skip loading any of the default tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'capistrano/ext/multistage' | |
set :default_stage, "staging" | |
set :application, "application_name" | |
set :repository, "https://svn.example.com/your_project_name/trunk/#{application}/" | |
set :use_sudo, false | |
set :scm, :subversion | |
set :scm_username, ENV['SVN_USER'] || ENV['USER'] | |
set :scm_prefer_prompt, true # 毎回パスワードを入力する設定 | |
# 最新のリリースディレクトリ内にsharedのシンボリックリンクを作成します。 | |
def shared_link(paths) | |
return if paths.to_a.empty? | |
cmd = [] | |
paths.to_a.each do |path| | |
cmd << "rm -rf #{latest_release}#{path}" | |
cmd << "ln -s #{shared_path}#{path} #{latest_release}#{path}" | |
end | |
run cmd.join(" && ") | |
end | |
namespace :deploy do | |
# defaultタスクからrestartを外します。呼ばれるタスクは以下の通り。 | |
# default -> update -> (update_code -> (deploy!,finalize_update),symlink) | |
desc "デプロイを実行します。" | |
task :default do | |
update | |
end | |
# Rails用のシンボリックリンク作成処理を置き換えます。 | |
task :finalize_update, :except => { :no_release => true } do | |
run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true) | |
# シンボリックリンクにしたいパスを以下に書きます。 | |
shared_link(%w{ | |
/path/to/symlink/example/1 | |
/path/to/symlink/example/2 | |
}) | |
end | |
[ | |
# Railsアプリケーション関連のタスクを消します。 | |
:restart, :start, :stop, :cold, :migrate, :migrations, | |
# setupもとりあえず消します。必要なら自分で定義します。 | |
:setup, | |
].each {|t| task(t){} } | |
namespace :rollback do | |
# オリジナルはrevision, restart, cleanup。restartを外します。 | |
desc "デプロイ前の状態に戻します。" | |
task :default do | |
revision | |
cleanup | |
end | |
# defaultタスクと同じ内容なので消します。 | |
[:code].each {|t| task(t){} } | |
end | |
namespace :web do | |
# メンテナンス表示用のタスクを消します。必要なら自分で定義します。 | |
[:disable,:enable].each {|t| task(t){}} | |
end | |
end | |
# デプロイ時に一緒に実行したいタスクはdeploy:finalize_updateをフックします。 | |
# このタイミングでタスクが失敗すると元に戻してくれます。 | |
# | |
# after "deploy:finalize_update", "your:originaltask" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :domain, "live.example.com" | |
set :gateway, "gateway.example.com" # sshの踏み台サーバ | |
set :user, "sshuser" # sshログインユーザ名 | |
set :deploy_to, "/home/#{user}/path/to/deploy" | |
role :app, "#{domain}" | |
puts <<'EOT' | |
-------------------------------------------------------------------------------- | |
_ _ _ | |
__/\__ | (_)_ _____| | __/\__ | |
\ / | | \ \ / / _ \ | \ / | |
/_ _\ | | |\ V / __/_| /_ _\ | |
\/ |_|_| \_/ \___(_) \/ | |
your app name here | |
-------------------------------------------------------------------------------- | |
EOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set :domain, "staging.example.com" | |
set :gateway, "gateway.example.com" # sshの踏み台サーバ | |
set :user, "sshuser" # sshログインユーザ名 | |
set :deploy_to, "/home/#{user}/path/to/deploy" | |
role :app, "#{domain}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment