Capistrano 2 Rocks My World
-
Upload
mathie -
Category
Technology
-
view
3.618 -
download
5
description
Transcript of Capistrano 2 Rocks My World
Capistrano 2Rocks my world
Graeme Mathieson, Rubaidh Ltd<[email protected]>
http://woss.name/ & http://www.rubaidh.com/
• So, what is it?
• Installing 2.0
• What’s new in Cap 2?
• Stuff I’ve done with cap 2
What’s the plan?
• A Rails deployment tool
• A Java deployment tool
• A troubleshooting tool
• An ad-hoc systems management tool
What is it?
Without a Capfile
$ cap2 invoke COMMAND=uname HOSTS=macallan,cardhu * executing `invoke' * executing "uname" servers: ["macallan", "cardhu"] [macallan] executing command [cardhu] executing command ** [out :: cardhu] SunOS ** [out :: macallan] Linux command finished$
Using cap shell
$ cap2 shell HOSTS=balvenie,cardhu * executing `shell'cap> uptime[establishing connection(s) to balvenie, cardhu] ** [out :: balvenie] 19:33:52 up 211 days, 7:25, 1 user, load average: 0.06, 0.07, 0.07 ** [out :: cardhu] 7:33pm up 10 day(s), 6:47, 2 users, load average: 0.18, 0.16, 0.15cap> uname -r ** [out :: balvenie] 2.4.21-47.0.1.EL ** [out :: cardhu] 5.10cap>
Installing 2.0
$ gem install -y net-ssh net-ftp highline[ ... ]$ gem install -s http://gems.rubyonrails.com/ capistrano[ ... ]
Done!
Co-existing with 1.x
# In ~/.bashrcalias cap1="`which cap` _1.4.1_"alias cap2="`which cap`"alias cap="echo 'Please explicitly choose cap1 or cap2.'"
New in 2.0?
• More rake-like
- Use `cap2 -T` to list tasks
- Namespaces
• Deployment strategies
• Dependencies
• Generic hooks
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
New Deployment Tasks
• Subversion log of undeployed changes
• deploy:pending
• Command, gem, file, directory dependencies
• deploy:check
What I’ve been up to
Recipes in plugins
# New CapfileDir['vendor/plugins/*/recipes'].each do |plugin| load_paths << pluginendload 'deploy' if respond_to?(:namespace)load 'config/deploy'
Daemon Strategies
• Default uses spin/spawner/reaper
• Solaris Service Management Framework
• runit
• daemontools
• Autogenerate script/spin
Staging
• Separate clusters for staging & deployment
• Use svnmerge to manage branches
• Trunk is deployed to staging server
• Production branch gets deployed live
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.
DB Backup - Rake
desc "Dumps the database into db/env-data.sql."task :dump => :environment do abc = ActiveRecord::Base.configurations[RAILS_ENV] cmd = ['mysqldump'] cmd << "--host='#{abc['host']}'" unless abc['host'].blank? cmd << "--user='#{abc['username']}'" cmd << "--password='#{abc['password']}'" cmd << abc['database'] cmd << " | gzip > #{RAILS_ROOT}/db/#{RAILS_ENV}-data.sql.gz" sh cmd.flatten.join ' 'end
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 "cd #{current_path}; #{rake} RAILS_ENV=#{rails_env} db:dump" get "#{current_path}/db/#{rails_env}-data.sql.gz", "db/#{rails_env}-data.sql.gz"end
Hook into deployment
before "deploy:migrate", "db:backup"
All in a plugin
$ script/plugin install -x \http://svn.rubaidh.com/plugins/trunk/rubaidh_platform
“I checked out your slides, and they look great! Best of luck on your presentation.”
- Jamis Buck
What else do you want to know?