deploying rails apps with capistrano

17
Capistrano Deploying Rails Apps with Capistrano By Chaitanya

Upload: nyros-technologies

Post on 17-May-2015

3.113 views

Category:

Technology


1 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Deploying Rails Apps with Capistrano

Capistrano

Deploying Rails Appswith Capistrano

By

Chaitanya

Page 2: Deploying Rails Apps with Capistrano

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.

Page 3: Deploying Rails Apps with Capistrano

• 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

Page 4: Deploying Rails Apps with Capistrano

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

Page 5: Deploying Rails Apps with Capistrano

Deployment isn’t that complex, right?

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

• Multiple Sites?

Page 6: Deploying Rails Apps with Capistrano

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

Page 7: Deploying Rails Apps with Capistrano

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.

Page 8: Deploying Rails Apps with Capistrano

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

Page 9: Deploying Rails Apps with Capistrano

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

Page 10: Deploying Rails Apps with Capistrano

Deployment Structure

Page 11: Deploying Rails Apps with Capistrano

Lets Deploy!

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

Page 12: Deploying Rails Apps with Capistrano

Deploying?

cap deploy

Page 13: Deploying Rails Apps with Capistrano

Rollback?

cap rollback

Page 14: Deploying Rails Apps with Capistrano

Web Access?

cap disable_web

cap enable_web

Page 15: Deploying Rails Apps with Capistrano

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.

Page 16: Deploying Rails Apps with Capistrano

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.

Page 17: Deploying Rails Apps with Capistrano

Thank You