Deploying Rails Apps with Capistrano

  • Published on

  • View

  • Download


Seminar presentation on Capistrano by Chaitanya at Nyros Technologies on 16th June, 2009.


<ul><li> 1. Capistrano Deploying Rails Apps with Capistrano ByChaitanya</li></ul> <p> 2. What isCapistrano </p> <ul><li>Capistrano is a utility for managing remote servers and automating remote tasks. It is popularly used to deploy Rails applications .The main functionality of the Capistrano is to Deploy the rails application which you have already written. and we are using the "SVN" subversion to manage the code. </li></ul> <p> 3. </p> <ul><li>It was previously called Switchtower. You can easily rollback to previous versions, do database migrations, and complete other complicated tasks. </li></ul> <ul><li>Presently available version is 2.2.0 </li></ul> <p> 4. </p> <ul><li>Capistrano will transfer all the files of the rails application which you have developed in your local host to server directly by simply executing an simple command in your command prompt. </li></ul> <p> 5. Deployment isnt that complex, right? </p> <ul><li>Simple sites are easy </li></ul> <ul><li><ul><li>One Database </li></ul></li></ul> <ul><li><ul><li>One Webserver </li></ul></li></ul> <ul><li><ul><li>One Application </li></ul></li></ul> <ul><li>Multiple Sites? </li></ul> <p> 6. Installing Capistrano </p> <ul><li>Gem install capistrano </li></ul> <ul><li><ul><li> cap h to see commands </li></ul></li></ul> <ul><li>Now to apply it to an application </li></ul> <ul><li><ul><li> capify . </li></ul></li></ul> <ul><li>Creates two files: </li></ul> <ul><li><ul><li>config/deploy.rb </li></ul></li></ul> <ul><li><ul><li>capfile </li></ul></li></ul> <p> 7. Configure Capistrano </p> <ul><li>Edit deploy.rb to match your apps setup </li></ul> <ul><li><ul><li>Youll need to specify the servers, repository location and deployment path at minimum </li></ul></li></ul> <ul><li><ul><li>Defaults to SVN, normal SSH port, key in user home, SCM executable on PATH, etc. </li></ul></li></ul> <ul><li><ul><li>When you first start, youll probably only have one server fulfill the DB, web and app roles. </li></ul></li></ul> <p> 8. My Modifications to deploy.rb </p> <ul><li>set :application, "captest" </li></ul> <ul><li>set :repository, "" </li></ul> <ul><li>role :web, "" </li></ul> <ul><li>role :app, "" </li></ul> <ul><li>role :db,"" </li></ul> <ul><li>set :deploy_to, "/users/home/patched/sites/captest"</li></ul> <ul><li>set :user, "patched"</li></ul> <ul><li>set :svn_username, "captest" </li></ul> <ul><li>set :svn_password, "captest" </li></ul> <ul><li>desc "Restart the webserver/fcgi procs, however you do it" </li></ul> <ul><li>task :restart, :roles =&gt; :app do </li></ul> <ul><li># Im not going to restart anything for this example </li></ul> <ul><li>end </li></ul> <ul><li>task :after_deploy, :roles =&gt; :app do </li></ul> <ul><li># Set my new dispatch.fcgi to be executable </li></ul> <ul><li>run "chmod 755 #{deploy_to}/current/public/dispatch.fcgi" </li></ul> <ul><li>end </li></ul> <p> 9. Setup </p> <ul><li> rake remote:exec ACTION=setup </li></ul> <ul><li><ul><li>Sets up the base directories </li></ul></li></ul> <p>This creates /sites/captest/releases /sites/captest/shared /sites/captest/shared/log /sites/captest/shared/system 10. Deployment Structure 11. Lets Deploy! </p> <ul><li>Rake --tasksto see all our options </li></ul> <ul><li>Rake deploy to push a version </li></ul> <ul><li>Rake rollback to rollback </li></ul> <p> 12. Deploying? </p> <ul><li><ul><li>capdeploy </li></ul></li></ul> <p> 13. Rollback? </p> <ul><li>cap rollback </li></ul> <p> 14. Web Access? </p> <ul><li>cap disable_web </li></ul> <ul><li>cap enable_web </li></ul> <p> 15. Various commands </p> <ul><li>cap apache:configure# Configure Apache. </li></ul> <ul><li>cap apache:reload# Reload Apache </li></ul> <ul><li>cap apache:restart# Restart Apache </li></ul> <ul><li>cap apache:start# Start Apache </li></ul> <ul><li>cap apache:stop# Stop Apache </li></ul> <ul><li>cap app:restart# Restart application server. </li></ul> <ul><li>cap app:setup# Setup mongrel </li></ul> <ul><li>cap app:start# Start application server. </li></ul> <ul><li>cap app:stop# Stop application server. </li></ul> <ul><li>cap app:symlinks:setup# Setup application symlinks in the public </li></ul> <ul><li>cap app:symlinks:update# Link public directories to shared location. </li></ul> <ul><li>cap cache_comm_count# Simple cache of counts for comm users </li></ul> <ul><li>cap db:setup# Setup database server. </li></ul> <ul><li>cap deploy# Deploys your project. </li></ul> <ul><li>cap deploy:check# Test deployment dependencies. </li></ul> <p> 16. Various commands </p> <ul><li>cap deploy:cleanup# Clean up old releases. </li></ul> <ul><li>cap deploy:cold# Deploys and starts a `cold' application. </li></ul> <ul><li>cap deploy:migrate# Run the migrate rake task. </li></ul> <ul><li>cap deploy:migrations# Deploy and run pending migrations. </li></ul> <ul><li>cap deploy:pending# Displays the commits since your last deploy. </li></ul> <ul><li>cap deploy:pending:diff# Displays the `diff' since your last deploy. </li></ul> <ul><li>cap deploy:restart# Restart the Mongrel processes on the app serv... </li></ul> <ul><li>cap deploy:rollback# Rolls back to a previous version and restarts. </li></ul> <ul><li>cap deploy:rollback:code# Rolls back to the previously deployed version. </li></ul> <ul><li>cap deploy:setup# Prepares one or more servers for deployment. </li></ul> <ul><li>cap deploy:start# Start the Mongrel processes on the app server... </li></ul> <ul><li>cap deploy:stop# Stop the Mongrel processes on the app server ... </li></ul> <ul><li>cap deploy:symlink# Updates the symlink to the most recently depl... </li></ul> <ul><li>cap deploy:update# Copies your project and updates the symlink. </li></ul> <p> 17. </p> <ul><li>Thank You </li></ul>