SlideShare a Scribd company logo
Capistrano Travis Roberts [email_address] http://twitter.com/travisroberts
Prerequisites SSH access to server SSH user/password (ssh keys are better) Ruby
Step 1: Cut a hole in the box gem install capistrano Step 2:  cd path/to/project Step 3:  capify . Project Setup
Customize deploy.rb Required settings set  :application ,  "test_app" set  :domain ,  "mysite.com" set  :deploy_to ,  "/var/www/apps/#{application}" set  :repository ,  " http://svn.centresource.com/#{application}/trunk " role  :web , domain  # where the web server runs role  :app , domain  # where the application layer runs role  :db ,  domain,  :primary  =>  true   # where your db runs
Customize deploy.rb Optional settings set  :scm ,  :git set  :repository ,  " [email_address] :username/projectname.git" set  :user ,  "deploy" set  :password ,  "p@55w0rd" set  :use_sudo ,  false Recommended settings set  :deploy_via ,  'remote_cache' set  :keep_releases ,  5
Folder Structure Folder structure on server (created by calling  cap servers:setup ) /deploy_to_path --current (symlink) --releases --20100422123598 --20100422123942 --shared --system --pids --logs
The Process Container (does nothing) Container (does nothing) Copies code to server Touches up the copied code Updates current symlink Restarts application
Custom Tasks # symlink database namespace  :deploy   do   desc  "Symlink database."   task  :symlink_db   do   run  "ln -nfs #{shared_path}/system/database.yml #{release_path}/config/database.yml"   end end   after  'deploy:update_code' ,  'deploy:symlink_db'
Overwrite Tasks namespace  :deploy   do   # symfony doesn't need these tasks   task  :start   do  ;  end   task  :stop   do  ;  end   task  :restart   do  ;  end     # doctrine migration   task  :migrate   do   run  "cd #{release_path} && php symfony doctrine:migrate --env='prod'"   end end
Put It All Together cap servers:setup cap deploy:cold cap deploy cap deploy:migrations cap deploy:rollback cap -T

More Related Content

Capistrano Overview

  • 1. Capistrano Travis Roberts [email_address] http://twitter.com/travisroberts
  • 2. Prerequisites SSH access to server SSH user/password (ssh keys are better) Ruby
  • 3. Step 1: Cut a hole in the box gem install capistrano Step 2: cd path/to/project Step 3: capify . Project Setup
  • 4. Customize deploy.rb Required settings set :application , "test_app" set :domain , "mysite.com" set :deploy_to , "/var/www/apps/#{application}" set :repository , " http://svn.centresource.com/#{application}/trunk " role :web , domain # where the web server runs role :app , domain # where the application layer runs role :db , domain, :primary => true # where your db runs
  • 5. Customize deploy.rb Optional settings set :scm , :git set :repository , " [email_address] :username/projectname.git" set :user , "deploy" set :password , "p@55w0rd" set :use_sudo , false Recommended settings set :deploy_via , 'remote_cache' set :keep_releases , 5
  • 6. Folder Structure Folder structure on server (created by calling cap servers:setup ) /deploy_to_path --current (symlink) --releases --20100422123598 --20100422123942 --shared --system --pids --logs
  • 7. The Process Container (does nothing) Container (does nothing) Copies code to server Touches up the copied code Updates current symlink Restarts application
  • 8. Custom Tasks # symlink database namespace :deploy do desc "Symlink database." task :symlink_db do run "ln -nfs #{shared_path}/system/database.yml #{release_path}/config/database.yml" end end after 'deploy:update_code' , 'deploy:symlink_db'
  • 9. Overwrite Tasks namespace :deploy do # symfony doesn't need these tasks task :start do ; end task :stop do ; end task :restart do ; end # doctrine migration task :migrate do run "cd #{release_path} && php symfony doctrine:migrate --env='prod'" end end
  • 10. Put It All Together cap servers:setup cap deploy:cold cap deploy cap deploy:migrations cap deploy:rollback cap -T