Sie sind auf Seite 1von 20

Capistrano

Deployment Sucks. Capistrano Swallows. Charles Brian Quinn Atlanta Ruby User Group

Whats it? Whos it?


Automated Web Application Deployment Another tool extracted from Basecamp by
Jamis Buck and DHH

Uses Rake and Net:SSH cleverly Convention over Conguration

Without Capistrano
SSH into app server cd into /path/my/app move app elsewhere get latest version of app setup database.yml setup any other shared resources migrate databases restart application servers restart web server repeat for all servers (!) if an error introduced, move old back.... cry a little bit

not cool

With Capistrano

$ rake remote:deploy

$ rake remote:rollback

cool (calm and assertive)

The Mental Model


Capistrano is your actor He assumes roles, and executes tasks It helps to deploy an app once manually to
see whats involved

Go Git it
$ gem install capistrano
(requires needle and Net:SSH) optionally termios for hiding passwords (linux only)

apply to your app: $ cap --apply-to /my/app MyApp

deploy.rb
The conguration or recipe le:

variables
set :deploy_to, "/var/www/apps/#{application}"

roles
role :web, "bristol.highgroove.com"

tasks
desc "A Task that does something cool" task :something_cool, :roles => [:app, :db] do # ... end

the minimum to play


set :application, set :repository, racecar/trunk racecar http://svn.highgroove.com/

role :app, daytona.highgroove.com role :web, daytona.highgroove.com role :db, daytona.highgroove.com, :primary => true

Task Dissected
desc "A task demonstrating the use of transactions." task :long_deploy, :roles => :app do transaction do update_code disable_web symlink Ruby DSLs migrate Rule! end restart enable_web end

Built-in Tasks

deploy / cold_deploy / deploy_with_migrations rollback update / update_code / update_current cleanup disable_web / enable_web migrate restart / restart_web setup

Out-of-the-box
Supports: subverison, darcs, perforce,
bazaar, bazaar-NG

Default: restarts FCGIs and apache

Set er up
$ rake remote:setup

or
$ rake remote:exec ACTION=setup

Directory Structure
[deploy_to] +- releases | +- 20050725121411 | +- 20050801090107 | +- 20050802231414 | ... | +- 20050824141402 | | +- Rakefile | | | app | | | config | | | db | | | lib | | | log --> [deploy_to]/shared/log | | | public | | | +- ... | | | system --> [deploy_to]/shared/system | | | ... | | | script | | | test | | | vendor | +- shared | +- log | +- system | + current --> [deploy_to]/releases/20050824141402

Fun with Callbacks


Every task has before_ and after_ example:
task :after_update_code, :roles => [:app, :db] do database_yml sudo "chmod -R +x #{release_path}/script/*" end

Demo

Tips n Tricks

$ rake remote:exec ACTION=show_tasks

interactive shell (new feature as of 1.2.0) mongrel_cluster by Bradley Taylor (overrides


spinner and restart for mongrel)

build cong les using ERB or use put

A tricked out setup


Check out:
http://www.slingshothosting.com/les/apache2_2_mongrel_deploy.rb

And the public svn repo:


http://svn.highgroove.com/deployment/

Sets up apache 2.1+ mod_proxy_balancer,


mongrel congs, crontabs, ferret_index, rails_cron, etc. and more!

Heartbeat

Making Deployment actually Push-Button

www.heartbeathq.com
More Plugging and Promotion Launching Real Soon(tm) Takes in a svn repository, reads deployment
le -- allows selection of tasks, and *real* push-button deployment

Also runs remote tasks, and monitors URLs Demo

For more on Cap


[outdated] manual: The http://manuals.rubyonrails.com/read/book/17

The GoogleGroup: http://groups.google.com/group/capistrano Jamis blog: http://weblog.jamisbuck.org/ A Cheatsheet: http://dizzy.co.uk/cheatsheets/

Das könnte Ihnen auch gefallen