Written in Ruby but it can easily be used to deploy any language! • Installed as a Ruby gem! • Easy to get started on, but also provides advanced capabilities
• Connects directly to server(s) via SSH! • Automates tasks/commands on server! • Checks out code directly to server from remote! • Uses symlinks to achieve “nearly no downtime” deployments! • Keeps versioned “releases” for rolling back
! # Includes default deployment tasks require 'capistrano/deploy' ! # Loads custom tasks from `lib/capistrano/tasks' if you have any defined. Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } Capfile
# Check required files and directories exist cap deploy:check:directories # Check shared and release directories exist cap deploy:check:linked_dirs # Check directories to be linked exist in shared cap deploy:check:linked_files # Check files to be linked exist in shared cap deploy:check:make_linked_dirs # Check directories of files to be linked exist in shared cap deploy:cleanup # Clean up old releases cap deploy:cleanup_rollback # Remove and archive rolled-back release cap deploy:finished # Finished cap deploy:finishing # Finish the deployment, clean up server(s) cap deploy:finishing_rollback # Finish the rollback, clean up server(s) cap deploy:log_revision # Log details of the deploy cap deploy:published # Published cap deploy:publishing # Publish the release cap deploy:revert_release # Revert to previous release timestamp cap deploy:reverted # Reverted cap deploy:reverting # Revert server(s) to previous release cap deploy:rollback # Rollback to previous release cap deploy:started # Started cap deploy:starting # Start a deployment, make sure server(s) ready cap deploy:symlink:linked_dirs # Symlink linked directories cap deploy:symlink:linked_files # Symlink linked files cap deploy:symlink:release # Symlink release to current cap deploy:symlink:shared # Symlink files and directories from shared to release cap deploy:updated # Updated cap deploy:updating # Update server(s) by setting up a new release cap install # Install Capistrano, cap install STAGES=staging,production
a deployment, make sure everything is ready deploy:started - started hook (for custom tasks) deploy:updating - update server(s) with a new release deploy:updated - updated hook deploy:publishing - publish the new release deploy:published - published hook deploy:finishing - finish the deployment, clean up everything deploy:finished - finished hook Note: Several “hook” tasks that you can link custom tasks into using after() and before()
│ ├── 20140311223109 │ └── 20140311181949 ├── repo ├── shared └── revisions.log Note: “Current” is a symlink to the latest release. Make sure to point your virtual host web root to “current”.
- revert server(s) to previous release deploy:reverted - reverted hook deploy:publishing deploy:published deploy:finishing_rollback - finish the rollback, clean up everything deploy:finished Note: Several “hook” tasks that you can link custom tasks into using after() and before()
it DRY # Default value for :linked_files is [] set :linked_files, %w{config/database.yml} ! # Default value for linked_dirs is [] set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} Link shared files / dirs
Announcement http://capistranorb.com/2013/06/01/release-announcement.html! • Capistrano GitHub https://github.com/capistrano/capistrano! • PHP & Capistrano 3: Notes to Self - Jeremy Kendall http://jeremykendall.net/2013/11/24/php-and-capistrano-3-notes-to-self/! • Using Capistrano v3 with Chef - Lee Hamby http://lee.hambley.name/2013/06/11/using-capistrano-v3-with-chef.html! • Slides to this Deck https://speakerdeck.com/galenandrew! • Sample Code https://github.com/galenandrew/cap-demo