Jon Maddox has previously published on how to do automated PHP deployment with capistrano, but I thought an all-ruby solution that handles all the rollbacky goodness of standard Cap was in order.
The trick is to create your standard config/deploy.rb lookin deployment recipe (like this one), and in it you have to redefine the deploy and update_code tasks to read:
# Override deploy to prevent restarting
task :deploy do
update # task from standard cap recipe
end
# Override update_code to remove Rails directories
task :update_code, :except => { :no_release => true } do
on_rollback { delete release_path, :recursive => true }
source.checkout(self)
set_permissions
@releases = nil
end
There’s nothing else that’s special; just add your normal set statements up the top, sprinkling after_ and before_ task callbacks as required. Now go ahead and deploy the sucker:
cap setup && cap deploy
If you’re wondering where you’d start looking to discover this sort of thing, all of Capistrano’s magic exists in its standard recipe in the capistrano gem’s lib directory. If you’re using Capistrano 1.4.0 and macports that path would be:
/opt/local/lib/ruby/gems/1.8/gems/capistrano-1.4.0/lib/capistrano/recipes/standard.rb
Archived comments
Comments were previously allowed on articles. Though no new comments are being accepted you can see the old comments below.
-
Cap is teh awesome! Another Aussie wrote the Deprec gem which is used to set up baremetal ubuntu boxes w/ Ruby/Rails/Etc.
http://deprec.rubyforge.org/
!
-
Yep, not to mention it’s an awesome piece of code to steal and plunder from if you want to learn more about capistrano.
