Your SlideShare is downloading. ×
0
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Capistrano2
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Capistrano2

1,038

Published on

An introduction to deploying rails applications with capistrano I gave at RailsToItaly in 2007

An introduction to deploying rails applications with capistrano I gave at RailsToItaly in 2007

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

No Downloads
Views
Total Views
1,038
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
34
Comments
0
Likes
7
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Capistrano 2 Beyond Hassle-Free Deployment Luca Mearelli Pisa - Oct. 27, 2007
  • 2. Rails is fun
  • 3. Rails is fun Rails is TOO MUCH fun
  • 4. Deployment
  • 5. System Administration
  • 6. Rails : Web development = Capistrano : Sys.administration
  • 7. Capistrano basics •SSH to the remote machines •Posix compatible shell •Same password or public key •a bit of ruby knowledge •works from a command line
  • 8. Capistrano basics •Capfile (makefile, rakefile, ...) •It’s ruby task :dump_db, :hosts => quot;database.spazidigitali.comquot; do run quot;mysqldump -u deploy sd_production > /home/luca/dumps/db.sqlquot; end cap dump_db
  • 9. role :sd_db, quot;database.spazidigitali.comquot; task :dump_db do run quot;mysqldump -u deploy sd_production > /home/luca/dumps/db.sqlquot; end task :free_space do run quot;df -hquot; end cap dump_db
  • 10. set :gateway, quot;firewall.spazidigitali.comquot; role :sd_db, quot;database.spazidigitali.comquot; task :dump_db do run quot;mysqldump -u deploy sd_production > /home/luca/dumps/db.sqlquot; end task :free_space do run quot;df -hquot; end cap dump_db
  • 11. set :gateway, quot;firewall.spazidigitali.comquot; role :sd_db, quot;database.spazidigitali.comquot;, quot;replica.spazidigitali.comquot; task :dump_db do run quot;mysqldump -u deploy sd_production > /home/luca/dumps/db.sqlquot; end task :free_space do run quot;df -hquot; end cap dump_db
  • 12. set :gateway, quot;firewall.spazidigitali.comquot; role :sd_db, quot;database.spazidigitali.comquot;, quot;replica.spazidigitali.comquot; role :sd_app, quot;mongrels.spazidigitali.comquot; task :dump_db, :roles=>:sd_db do run quot;mysqldump -u deploy sd_production > /home/luca/dumps/db.sqlquot; end task :free_space, :roles=>[:sd_db, :sd_app ] do run quot;df -hquot; end cap dump_db
  • 13. set :gateway, quot;firewall.spazidigitali.comquot; role :sd_db, quot;database.spazidigitali.comquot;, quot;replica.spazidigitali.comquot; role :sd_app, quot;mongrels.spazidigitali.comquot; namespace :spazidig do desc quot;Dumping our DBsquot; task :dump_db, :roles=>:sd_db do run quot;mysqldump -u deploy sd_production > /home/luca/dumps/db.sqlquot; end desc quot;Checking free spacequot; task :free_space, :roles=>[:sd_db, :sd_app ]do run quot;df -hquot; end end cap spazidig:dump_db
  • 14. set :gateway, quot;firewall.spazidigitali.comquot; role :sd_db, quot;database.spazidigitali.comquot;, quot;replica.spazidigitali.comquot; role :sd_app, quot;mongrels.spazidigitali.comquot; namespace :spazidig do desc quot;What??quot; task :default do run quot;uname -aquot; end desc quot;Dumping our DBsquot; task :dump_db, :roles=>:sd_db do run quot;mysqldump -u deploy sd_production > /home/luca/dumps/db.sqlquot; end desc quot;Checking free spacequot; task :free_space, :roles=>[:sd_db, :sd_app ]do run quot;df -hquot; end end cap spazidig spazidig:dump_db cap dump_db cap spazidig:free_space
  • 15. set :gateway, quot;firewall.spazidigitali.comquot; role :sd_db, quot;database.spazidigitali.comquot;, quot;replica.spazidigitali.comquot; role :sd_app, quot;mongrels.spazidigitali.comquot; set :destination, quot;db.sqlquot; namespace :spazidig do desc quot;Dumping our DBsquot; task :dump_db, :roles=>:sd_db do run quot;mysqldump -u deploy sd_production > /home/luca/dumps/#{destination}.sqlquot; end end cap spazidig:dump_db
  • 16. set :gateway, quot;firewall.spazidigitali.comquot; role :sd_db, quot;database.spazidigitali.comquot;, quot;replica.spazidigitali.comquot; role :sd_app, quot;mongrels.spazidigitali.comquot; set :destination, quot;db.sqlquot; set(:database) do Capistrano::CLI.ui.ask quot;Which database?: quot; end namespace :spazidig do desc quot;Dumping our DBsquot; task :dump_db, :roles=>:sd_db do run quot;mysqldump -u deploy #{database} > /home/luca/dumps/#{destination}.sqlquot; end end cap spazidig:dump_db
  • 17. task :deploy do transaction do try_this then_do_that end end task :try_this do on_rollback { run quot;do_cleanupquot; } #... end task :then_do_that do on_rollback { run quot;do_super_cleanupquot; } #... end
  • 18. on :event, :callback, :only => %w(tasks_to_do) # :load, :exit, :start, :finish, :begin, :after trigger :notify, current_task on :notify, :callback
  • 19. load_paths << quot;config/deployquot; case ENV['STAGE'] when quot;productionquot; then load quot;productionquot; when quot;stagingquot; then load quot;stagingquot; else abort quot;unknown stage: #{ENV['STAGE']}quot; end
  • 20. before :deploy, :run_tests after quot;deploy:update_codequot;, :link_database_yml task :run_tests do system quot;rakequot; or abort quot;tests failedquot; end task :link_database_yml do run quot;ln -s #{release_path}/config/database.yml #{shared_path}/database.ymlquot; end
  • 21. Cap •cap -T •cap <some task> •cap invoke COMMAND=quot;df -hquot; •cap invoke COMMAND=quot;df -hquot; ROLES=sd_db •cap invoke COMMAND=quot;df -hquot; HOSTS=www.spazidigitali.com •cap shell
  • 22. Capify capify . •Creates a Capfile •Creates a deploy “configuration” file
  • 23. Cap •cap deploy:setup •cap deploy •cap deploy:check •cap deploy:rollback •cap deploy:cold •cap deploy:migrations •cap deploy:update •cap deploy:web:disable •cap deploy:migrate •cap deploy:web:enable •cap deploy:start •cap deploy:cleanup
  • 24. deploy:setup •<deploy_to> •current •releases •200706060120 •200702020815 •shared •log •pids •system
  • 25. deploy:check depend :remote, :gem, 'rpdf', '>=1.1.4' depend :remote, :directory, quot;/tmp/railsquot; depend :remote, :writable, quot;/dir/file.logquot; depend :local, :command, quot;gemquot; depend :remote, :command, quot;mysqldumpquot;
  • 26. deploy:cold •copies the code - cap deploy:update •migrates the database - cap deploy:migrate •starts the service - cap deploy:start
  • 27. Variables •:ssh_options •:use_sudo •:application •:group_writable •:repository •:rake •:scm •:current_path •:deploy_via •:release_path •:deploy_to •:shared_path •:revision
  • 28. Deployment strategies •Checkout (classic capistrano) •Remote cache (svn up) •Export •Copy (via checkout or export, with compression)
  • 29. Example* *sorta real
  • 30. That’s all folks •Luca Mearelli •http://spazidigitali.com •lucamea@gmail.com

×