capistrano - atlanta ruby user group.pdf

Upload: makedonin

Post on 04-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    1/20

    CapistranoDeployment Sucks. Capistrano Swallows.Charles Brian Quinn

    Atlanta Ruby User Group

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    2/20

    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 Configuration

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    3/20

    Without Capistrano

    SSH into app servercd into /path/my/app

    move app elsewhereget latest version of appsetup database.ymlsetup any other shared resourcesmigrate databasesrestart application serversrestart web server

    repeat for all servers (!)if an error introduced, move old back....cry a little bit not cool

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    4/20

    With Capistrano

    $ rake remote:deploy

    $ rake remote:rollback

    cool (calm and assertive)

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    5/20

    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

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    6/20

    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

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    7/20

    deploy.rb

    The configuration or recipe file:

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

    rolesrole :web, "bristol.highgroove.com"

    tasksdesc "A Task that does something cool"task :something_cool, :roles => [:app, :db] do

    # ...

    end

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    8/20

    the minimum to play

    set :application, racecar

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

    role :app, daytona.highgroove.com

    role :web, daytona.highgroove.com

    role :db, daytona.highgroove.com, :primary =>

    true

    http://svn.example.org/app-name/trunkhttp://svn.example.org/app-name/trunkhttp://svn.example.org/app-name/trunkhttp://svn.example.org/app-name/trunk
  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    9/20

    Task Dissected

    desc "A task demonstrating the use of transactions."

    task :long_deploy, :roles => :app do

    transaction do update_code

    disable_web

    symlink

    migrate

    end

    restart enable_web

    end

    Ruby DSLsRule!

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    10/20

    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

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    11/20

    Out-of-the-box

    Supports: subverison, darcs, perforce,bazaar, bazaar-NG

    Default: restarts FCGIs and apache

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    12/20

    Set er up

    $ rake remote:setup

    or

    $ rake remote:exec ACTION=setup

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    13/20

    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

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    14/20

    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

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    15/20

    Demo

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    16/20

    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 config files using ERB or use put

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    17/20

    A tricked out setup

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

    And the public svn repo:http://svn.highgroove.com/deployment/

    Sets up apache 2.1+ mod_proxy_balancer,mongrel configs, crontabs, ferret_index,rails_cron, etc. and more!

    https://bristol.highgroove.com:8443/deployment/http://www.slingshothosting.com/files/apache2_2_mongrel_deploy.rbhttps://bristol.highgroove.com:8443/deployment/https://bristol.highgroove.com:8443/deployment/http://www.slingshothosting.com/files/apache2_2_mongrel_deploy.rbhttp://www.slingshothosting.com/files/apache2_2_mongrel_deploy.rb
  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    18/20

    Heartbeat

    Making Deployment actually Push-Button

  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    19/20

    www.heartbeathq.com

    More Plugging and Promotion

    Launching Real Soon(tm)

    Takes in a svn repository, reads deploymentfile -- allows selection of tasks, and *real*push-button deployment

    Also runs remote tasks, and monitors URLs Demo

    http://www.heartbeathq.com/http://www.heartbeathq.com/
  • 8/14/2019 Capistrano - Atlanta Ruby User Group.pdf

    20/20

    For more on Cap

    The [outdated] manual: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/

    http://dizzy.co.uk/cheatsheets/http://weblog.jamisbuck.org/http://groups.google.com/group/capistranohttp://manuals.rubyonrails.com/read/book/17http://dizzy.co.uk/cheatsheets/http://dizzy.co.uk/cheatsheets/http://weblog.jamisbuck.org/http://weblog.jamisbuck.org/http://groups.google.com/group/capistranohttp://groups.google.com/group/capistranohttp://manuals.rubyonrails.com/read/book/17http://manuals.rubyonrails.com/read/book/17