Capistrano Deployment By Nyros Developer


Published on

Capistrano Deployment By Nyros Developer

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Capistrano Deployment By Nyros Developer

  1. 1. Capistrano Deployment By Sharma
  2. 2. Application Deployment <ul><li>Application deployment is one of those things that becomes more and more complicated as the scale of our application increases. With just a single box running our database and our application, it’s very easy to handle. </li></ul><ul><li>But when we start putting our database on a different server, and then separating our web servers from our application servers, and eventually splitting our database into master and slave servers… It can get to where we almost don’t want to deploy our application any more. </li></ul>
  3. 3. When we need to Deploy <ul><li>Whenever we make any changes in any of the components/files which are part of the repository (like SVN, Git) then we need to publish it, otherwise changes might not be visible. </li></ul>
  4. 4. What is Capistrano <ul><li>Capistrano is an open source tool for running scripts on multiple servers and its main use is deploying web applications. </li></ul><ul><li>It is a standalone utility that can also integrate nicely with Rails. We simply provide Capistrano with a deployment “recipe” or “formula” that describes our various servers and their roles. It is a single-command deployment. It even allows us to roll a bad version out of production and it revert back to the previous release very easily. </li></ul>
  5. 5. Capistrano Deployment <ul><li>The main functionality of the Capistrano is to Deploy the rails application which we have already developed and we are using the &quot;SVN&quot; or “GIT” to manage the code. It will transfer all the files of our rails application which we have developed in our local host to server directly by simply executing a simple command in our command prompt. </li></ul>
  6. 6. Capistrano Deployment <ul><li>Capistrano is originally called SwitchTower, the name was changed to Capistrano in March 2006 because of some trademark conflict. </li></ul><ul><li>The original author, Jamis Buck, announced in the year 2009. </li></ul>
  7. 7. Steps to deploy a rails app <ul><li>> gem install capistrano </li></ul>
  8. 8. Capistrano Deployment <ul><li>Now, we need to capistranize our rails application using the following command </li></ul><ul><ul><li>>capify . </li></ul></ul><ul><li>It will creates two files: </li></ul><ul><li> -- config/deploy.rb </li></ul><ul><ul><li>-- capfile </li></ul></ul>
  9. 9. How to set the deploy.rb file <ul><li>require 'rubygems' </li></ul><ul><li>require 'activesupport' </li></ul><ul><li>set :application, “<application_name>&quot; </li></ul><ul><li>set :scm_username, “<username>“ </li></ul><ul><li>set :use_sudo, false </li></ul><ul><li>set :repository, &quot;http://#{scm_username}; </li></ul>
  10. 10. deploy.rb file <ul><li>:scm_username is your server user name. </li></ul><ul><li>:application is an arbitrary name you create to identify your application on the server </li></ul><ul><li>:use_sudo specifies to Capistrano that it does not need to append 'sudo' before all the commands it will run. </li></ul><ul><li>:repository identifies where your Subversion repository is located. </li></ul>
  11. 11. deploy.rb file <ul><li>If we aren't deploying to /u/apps/#{application} on the target servers (which is the default path), we need to specify the actual location by using deploy_to variable like this… </li></ul><ul><li>set :deploy_to, &quot;/var/www/#{application}&quot; </li></ul><ul><li>set :deploy_via, :checkout </li></ul>
  12. 12. deploy.rb file <ul><li>If we aren't using Subversion(SVN) to manage our source code, specify the SCM by using the “scm” variable… </li></ul><ul><li>set :scm, :git </li></ul><ul><ul><li>set :user, &quot;root&quot; </li></ul></ul><ul><ul><li>role :app, &quot;; </li></ul></ul><ul><ul><li>role :web, &quot;; </li></ul></ul><ul><ul><li>role :db, &quot;;, :primary => true </li></ul></ul>
  13. 13. deploy.rb file <ul><li>These are the default roles created by the capistrano, but we can add others if we want. The default roles are: </li></ul><ul><ul><li>role :app, “<domain_name>&quot; </li></ul></ul><ul><ul><li>role :web, “<domain_name>&quot; </li></ul></ul><ul><ul><li>role :db, “<domain_name>&quot;, :primary => true </li></ul></ul><ul><li>Since most rails users will have the same domain name for their web, app, and database, we can simply use our domain variable we set earlier. </li></ul>
  14. 14. deploy.rb file <ul><ul><li>namespace :migrations do </li></ul></ul><ul><ul><li>desc &quot;Run the Migrations&quot; </li></ul></ul><ul><ul><li>task :up, :roles => :app do </li></ul></ul><ul><ul><ul><li> run &quot;cd #{current_path}; rake db:auto:migrate;&quot; </li></ul></ul></ul><ul><ul><li>end </li></ul></ul><ul><ul><li>task :down, :roles => :app do </li></ul></ul><ul><ul><ul><li>run &quot;cd #{current_path}; rake db:drop; rake db:create&quot; </li></ul></ul></ul><ul><ul><li>end </li></ul></ul><ul><ul><li>end </li></ul></ul>
  15. 15. Capistrano Deployment <ul><li>After completion of our settings in the deploy.rb file, we need to commit the application by using “svn commit” command if we use SVN. </li></ul><ul><li>Then we need to run the following command: </li></ul><ul><li>> cap deploy:setup </li></ul><ul><li>It is used to create the directory structure in server. </li></ul>
  16. 16. Capistrano Deployment <ul><li>> cap deploy:check </li></ul><ul><li>It checks all the dependencies/things like directory permissions and necessary utilities to deploy the application by using Capistrano. </li></ul><ul><li>If everything is successful, you should see a message like… </li></ul><ul><li>You appear to have all necessary dependencies installed </li></ul>
  17. 17. Capistrano Deployment <ul><li>And finally deploy the application by using the following command: </li></ul><ul><ul><li>> cap deploy </li></ul></ul><ul><ul><li>…………… . </li></ul></ul><ul><ul><li>…………… .. </li></ul></ul><ul><ul><li>Command finished successfully….. </li></ul></ul>
  18. 18. Some Important commands <ul><li>To Install the gem </li></ul><ul><li>> gem install capistrano </li></ul><ul><li>Add our application to Capistrano </li></ul><ul><li>> capify . </li></ul><ul><li>Execute the setup tasks </li></ul><ul><li>> cap deploy:setup </li></ul>
  19. 19. Capistrano Commands <ul><li>> cap deploy:setup </li></ul><ul><li>it will create the directory structure in server like this… </li></ul>
  20. 20. Capistrano Commands <ul><li>Deploy our application </li></ul><ul><li>> cap deploy </li></ul><ul><li>Runs the migrate task on the new release before updating the symlink </li></ul><ul><li>> rake remote:deploy_with_migrations </li></ul><ul><li>Rollback a release from production </li></ul><ul><li>> rake rollback </li></ul>
  21. 21. Capistrano Commands <ul><li>Clean up the releases directory, leaving the five most recent releases </li></ul><ul><li>> cap cleanup </li></ul>
  22. 22. Capistrano Commands <ul><li>Prints the difference between what was last deployed, and what is currently in your repository </li></ul><ul><li>> cap diff_from_last_deploy </li></ul>
  23. 23. Advantages <ul><li>It can execute commands in parallel on multiple servers. </li></ul><ul><li>It can perform migrations during deployment. It can restart mongrels/fcgi. </li></ul><ul><li>It uses repository which allows us to easy upgradation of source code. </li></ul>
  24. 24. Disadvantages & Alternatives <ul><li>lack of scalability : when you're dealing with hundreds of servers, it starts showing its limits, unless it makes heavy use of threading or multi-processing. </li></ul><ul><li>Altarnatives : </li></ul><ul><li>inploy ---- gem install inploy </li></ul><ul><li>vlad ----- gem install vlad </li></ul><ul><li>phd ----- Passenger-based Heroku-like Deployment </li></ul>
  25. 25. References <ul><li> </li></ul><ul><li> </li></ul>
  26. 26. <ul><li>Thank You </li></ul>