Capistrano Deployment By Nyros Developer

  • 2,488 views
Uploaded on

Capistrano Deployment By Nyros Developer

Capistrano Deployment By Nyros Developer

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
2,488
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
33
Comments
0
Likes
0

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 Deployment By Sharma
  • 2. Application Deployment
    • 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.
    • 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.
  • 3. When we need to Deploy
    • 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.
  • 4. What is Capistrano
    • Capistrano is an open source tool for running scripts on multiple servers and its main use is deploying web applications.
    • 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.
  • 5. Capistrano Deployment
    • The main functionality of the Capistrano is to Deploy the rails application which we have already developed and we are using the "SVN" 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.
  • 6. Capistrano Deployment
    • Capistrano is originally called SwitchTower, the name was changed to Capistrano in March 2006 because of some trademark conflict.
    • The original author, Jamis Buck, announced in the year 2009.
  • 7. Steps to deploy a rails app
    • > gem install capistrano
  • 8. Capistrano Deployment
    • Now, we need to capistranize our rails application using the following command
      • >capify .
    • It will creates two files:
    • -- config/deploy.rb
      • -- capfile
  • 9. How to set the deploy.rb file
    • require 'rubygems'
    • require 'activesupport'
    • set :application, “<application_name>&quot;
    • set :scm_username, “<username>“
    • set :use_sudo, false
    • set :repository, &quot;http://#{scm_username}@www.example.com/svn/trunk&quot;
  • 10. deploy.rb file
    • :scm_username is your server user name.
    • :application is an arbitrary name you create to identify your application on the server
    • :use_sudo specifies to Capistrano that it does not need to append 'sudo' before all the commands it will run.
    • :repository identifies where your Subversion repository is located.
  • 11. deploy.rb file
    • 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…
    • set :deploy_to, &quot;/var/www/#{application}&quot;
    • set :deploy_via, :checkout
  • 12. deploy.rb file
    • If we aren't using Subversion(SVN) to manage our source code, specify the SCM by using the “scm” variable…
    • set :scm, :git
      • set :user, &quot;root&quot;
      • role :app, &quot;divvyhub.com&quot;
      • role :web, &quot;divvyhub.com&quot;
      • role :db, &quot;divvyhub.com&quot;, :primary => true
  • 13. deploy.rb file
    • These are the default roles created by the capistrano, but we can add others if we want. The default roles are:
      • role :app, “<domain_name>&quot;
      • role :web, “<domain_name>&quot;
      • role :db, “<domain_name>&quot;, :primary => true
    • 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.
  • 14. deploy.rb file
      • namespace :migrations do
      • desc &quot;Run the Migrations&quot;
      • task :up, :roles => :app do
        • run &quot;cd #{current_path}; rake db:auto:migrate;&quot;
      • end
      • task :down, :roles => :app do
        • run &quot;cd #{current_path}; rake db:drop; rake db:create&quot;
      • end
      • end
  • 15. Capistrano Deployment
    • 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.
    • Then we need to run the following command:
    • > cap deploy:setup
    • It is used to create the directory structure in server.
  • 16. Capistrano Deployment
    • > cap deploy:check
    • It checks all the dependencies/things like directory permissions and necessary utilities to deploy the application by using Capistrano.
    • If everything is successful, you should see a message like…
    • You appear to have all necessary dependencies installed
  • 17. Capistrano Deployment
    • And finally deploy the application by using the following command:
      • > cap deploy
      • …………… .
      • …………… ..
      • Command finished successfully…..
  • 18. Some Important commands
    • To Install the gem
    • > gem install capistrano
    • Add our application to Capistrano
    • > capify .
    • Execute the setup tasks
    • > cap deploy:setup
  • 19. Capistrano Commands
    • > cap deploy:setup
    • it will create the directory structure in server like this…
  • 20. Capistrano Commands
    • Deploy our application
    • > cap deploy
    • Runs the migrate task on the new release before updating the symlink
    • > rake remote:deploy_with_migrations
    • Rollback a release from production
    • > rake rollback
  • 21. Capistrano Commands
    • Clean up the releases directory, leaving the five most recent releases
    • > cap cleanup
  • 22. Capistrano Commands
    • Prints the difference between what was last deployed, and what is currently in your repository
    • > cap diff_from_last_deploy
  • 23. Advantages
    • It can execute commands in parallel on multiple servers.
    • It can perform migrations during deployment. It can restart mongrels/fcgi.
    • It uses repository which allows us to easy upgradation of source code.
  • 24. Disadvantages & Alternatives
    • 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.
    • Altarnatives :
    • inploy ---- gem install inploy
    • vlad ----- gem install vlad
    • phd ----- Passenger-based Heroku-like Deployment
  • 25. References
    • http://www.capify.org
    • http://ruby-toolbox.com/categories/deployment_automation.html
  • 26.
    • Thank You