7. Co-existing with 1.x
# In ~/.bashrc
alias cap1=quot;`which cap` _1.4.1_quot;
alias cap2=quot;`which cap`quot;
alias cap=quot;echo 'Please explicitly choose cap1 or cap2.'quot;
8. New in 2.0?
• More rake-like
- Use `cap2 -T` to list tasks
- Namespaces
• Deployment strategies
• Dependencies
• Generic hooks
9. New task names
• deploy well, umm, deploy
• deploy_with_migrations deploy:migrations
• diff_from_last_deploy deploy:pending:diff
• setup deploy:setup
• Same idea, just with namespaces
10. New Deployment Tasks
• Subversion log of undeployed changes
• deploy:pending
• Command, gem, file, directory dependencies
• deploy:check
12. Recipes in plugins
# New Capfile
Dir['vendor/plugins/*/recipes'].each do |plugin|
load_paths << plugin
end
load 'deploy' if respond_to?(:namespace)
load 'config/deploy'
13. Daemon Strategies
• Default uses spin/spawner/reaper
• Solaris Service Management Framework
• runit
• daemontools
• Autogenerate script/spin
14. Staging
• Separate clusters for staging & deployment
• Use svnmerge to manage branches
• Trunk is deployed to staging server
• Production branch gets deployed live
15. General Strategy
• Create a rake task to do what you want.
• Create a Capistrano task that runs the rake
task.
• Hook it into the deployment.
16. DB Backup - Rake
desc quot;Dumps the database into db/env-data.sql.quot;
task :dump => :environment do
abc = ActiveRecord::Base.configurations[RAILS_ENV]
cmd = ['mysqldump']
cmd << quot;--host='#{abc['host']}'quot; unless abc['host'].blank?
cmd << quot;--user='#{abc['username']}'quot;
cmd << quot;--password='#{abc['password']}'quot;
cmd << abc['database']
cmd << quot; | gzip > #{RAILS_ROOT}/db/#{RAILS_ENV}-data.sql.gzquot;
sh cmd.flatten.join ' '
end
17. DB Backup - Capfile
desc “Back up the production database”
task :backup, :roles => :db, :only => { :primary => true } do
rake = fetch(:rake, 'rake')
rails_env = fetch(:rails_env, 'production')
run quot;cd #{current_path}; #{rake} RAILS_ENV=#{rails_env} db:dumpquot;
get quot;#{current_path}/db/#{rails_env}-data.sql.gzquot;, quot;db/#
{rails_env}-data.sql.gzquot;
end