Capistrano 2
  Rocks my world
       Graeme Mathieson, Rubaidh Ltd
           <mathie@rubaidh.com>
http://woss.name/ & htt...
What’s the plan?
•   So, what is it?

•   Installing 2.0

•   What’s new in Cap 2?

•   Stuff I’ve done with cap 2
What is it?
•   A Rails deployment tool

•   A Java deployment tool

•   A troubleshooting tool

•   An ad-hoc systems man...
Without a Capfile

$ cap2 invoke COMMAND=uname HOSTS=macallan,cardhu
   * executing `invoke'
   * executing quot;unamequot...
Using cap shell
$ cap2 shell HOSTS=balvenie,cardhu
  * executing `shell'
cap> uptime
[establishing connection(s) to balven...
Installing 2.0
$   gem   install -y net-ssh net-ftp highline
[   ...   ]
$   gem   install -s http://gems.rubyonrails.com/...
Co-existing with 1.x

# In ~/.bashrc
alias cap1=quot;`which cap` _1.4.1_quot;
alias cap2=quot;`which cap`quot;
alias cap=q...
New in 2.0?
•   More rake-like

    -   Use `cap2 -T` to list tasks

    -   Namespaces

•   Deployment strategies

•   De...
New task names
•   deploy    well, umm, deploy

•   deploy_with_migrations     deploy:migrations

•   diff_from_last_deplo...
New Deployment Tasks
•   Subversion log of undeployed changes
    •   deploy:pending

•   Command, gem, file, directory de...
What I’ve been up to
Recipes in plugins

# New Capfile
Dir['vendor/plugins/*/recipes'].each do |plugin|
  load_paths << plugin
end
load 'deploy...
Daemon Strategies
•   Default uses spin/spawner/reaper

•   Solaris Service Management Framework

•   runit

•   daemontoo...
Staging
•   Separate clusters for staging & deployment

•   Use svnmerge to manage branches

•   Trunk is deployed to stag...
General Strategy


•   Create a rake task to do what you want.

•   Create a Capistrano task that runs the rake
    task.
...
DB Backup - Rake
desc quot;Dumps the database into db/env-data.sql.quot;
task :dump => :environment do
  abc = ActiveRecor...
DB Backup - Capfile

desc “Back up the production database”
task :backup, :roles => :db, :only => { :primary => true } do
...
Hook into deployment


before quot;deploy:migratequot;,   quot;db:backupquot;
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.”

                                   -...
What else do you want
      to know?
Upcoming SlideShare
Loading in …5
×

Capistrano 2 Rocks My World

3,906 views
3,828 views

Published on

The talk I gave at ScotRUG last night about Capistrano 2 and some of the things I've been doing with it.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,906
On SlideShare
0
From Embeds
0
Number of Embeds
49
Actions
Shares
0
Downloads
87
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Capistrano 2 Rocks My World

  1. 1. Capistrano 2 Rocks my world Graeme Mathieson, Rubaidh Ltd <mathie@rubaidh.com> http://woss.name/ & http://www.rubaidh.com/
  2. 2. What’s the plan? • So, what is it? • Installing 2.0 • What’s new in Cap 2? • Stuff I’ve done with cap 2
  3. 3. What is it? • A Rails deployment tool • A Java deployment tool • A troubleshooting tool • An ad-hoc systems management tool
  4. 4. Without a Capfile $ cap2 invoke COMMAND=uname HOSTS=macallan,cardhu * executing `invoke' * executing quot;unamequot; servers: [quot;macallanquot;, quot;cardhuquot;] [macallan] executing command [cardhu] executing command ** [out :: cardhu] SunOS ** [out :: macallan] Linux command finished $
  5. 5. 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.15 cap> uname -r ** [out :: balvenie] 2.4.21-47.0.1.EL ** [out :: cardhu] 5.10 cap>
  6. 6. Installing 2.0 $ gem install -y net-ssh net-ftp highline [ ... ] $ gem install -s http://gems.rubyonrails.com/ capistrano [ ... ] Done!
  7. 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. 8. New in 2.0? • More rake-like - Use `cap2 -T` to list tasks - Namespaces • Deployment strategies • Dependencies • Generic hooks
  9. 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. 10. New Deployment Tasks • Subversion log of undeployed changes • deploy:pending • Command, gem, file, directory dependencies • deploy:check
  11. 11. What I’ve been up to
  12. 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. 13. Daemon Strategies • Default uses spin/spawner/reaper • Solaris Service Management Framework • runit • daemontools • Autogenerate script/spin
  14. 14. Staging • Separate clusters for staging & deployment • Use svnmerge to manage branches • Trunk is deployed to staging server • Production branch gets deployed live
  15. 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. 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. 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
  18. 18. Hook into deployment before quot;deploy:migratequot;, quot;db:backupquot;
  19. 19. All in a plugin $ script/plugin install -x http://svn.rubaidh.com/plugins/trunk/rubaidh_platform
  20. 20. “I checked out your slides, and they look great! Best of luck on your presentation.” - Jamis Buck
  21. 21. What else do you want to know?

×