Deploying Rails Apps with Capistrano

Preview:

DESCRIPTION

Seminar presentation on Capistrano by Chaitanya at Nyros Technologies on 16th June, 2009. http://www.nyros.com

Citation preview

Capistrano

Deploying Rails Appswith Capistrano

By

Chaitanya

What is Capistrano

• 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.

• It was previously called Switchtower. You can easily rollback to previous versions, do database migrations, and complete other complicated tasks.

• Presently available version is 2.2.0

• 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.

Deployment isn’t that complex, right?

• Simple sites are easy– One Database– One Webserver– One Application

• Multiple Sites?

Installing Capistrano

• Gem install capistrano– “cap –h” to see commands

• Now to apply it to an application– “capify .”

• Creates two files:– config/deploy.rb– capfile

Configure Capistrano

• Edit deploy.rb to match your app’s setup

– You’ll need to specify the servers, repository location and deployment path at minimum

– Defaults to SVN, normal SSH port, key in user home, SCM executable on PATH, etc.

– When you first start, you’ll probably only have one server fulfill the DB, web and app roles.

My Modifications to deploy.rb

set :application, "captest"set :repository, "https://pollack.textdriven.com/svn/captest"role :web, "burnaby.textdrive.com"role :app, "burnaby.textdrive.com"role :db, "burnaby.textdrive.com"set :deploy_to, "/users/home/patched/sites/captest" set :user, "patched" set :svn_username, "captest"set :svn_password, "captest"

desc "Restart the webserver/fcgi procs, however you do it"task :restart, :roles => :app do # I’m not going to restart anything for this exampleendtask :after_deploy, :roles => :app do

# Set my new dispatch.fcgi to be executablerun "chmod 755 #{deploy_to}/current/public/dispatch.fcgi"

end

Setup

• “rake remote:exec ACTION=setup”– Sets up the base directories

This creates/sites/captest/releases/sites/captest/shared/sites/captest/shared/log/sites/captest/shared/system

Deployment Structure

Lets Deploy!

• “Rake --tasks” to see all our options• “Rake deploy” to push a version• “Rake rollback” to rollback

Deploying?

cap deploy

Rollback?

cap rollback

Web Access?

cap disable_web

cap enable_web

Various commands

• cap apache:configure # Configure Apache.• cap apache:reload # Reload Apache• cap apache:restart # Restart Apache• cap apache:start # Start Apache• cap apache:stop # Stop Apache• cap app:restart # Restart application server.• cap app:setup # Setup mongrel• cap app:start # Start application server.• cap app:stop # Stop application server.• cap app:symlinks:setup # Setup application symlinks in the

public• cap app:symlinks:update # Link public directories to shared

location.• cap cache_comm_count # Simple cache of counts for comm

users• cap db:setup # Setup database server.• cap deploy # Deploys your project.• cap deploy:check # Test deployment dependencies.

Various commands

• cap deploy:cleanup # Clean up old releases.• cap deploy:cold # Deploys and starts a `cold' application.• cap deploy:migrate # Run the migrate rake task.• cap deploy:migrations # Deploy and run pending migrations.• cap deploy:pending # Displays the commits since your last deploy.• cap deploy:pending:diff # Displays the `diff' since your last deploy.• cap deploy:restart # Restart the Mongrel processes on the app serv...

• cap deploy:rollback # Rolls back to a previous version and restarts.• cap deploy:rollback:code # Rolls back to the previously deployed version.• cap deploy:setup # Prepares one or more servers for deployment.• cap deploy:start # Start the Mongrel processes on the app server...

• cap deploy:stop # Stop the Mongrel processes on the app server ...

• cap deploy:symlink # Updates the symlink to the most recently depl...

• cap deploy:update # Copies your project and updates the symlink.

Thank You

Recommended