Capistrano
Upcoming SlideShare
Loading in...5
×
 

Capistrano

on

  • 3,261 views

Walk through on how to deploy applications via capistrano

Walk through on how to deploy applications via capistrano

Statistics

Views

Total Views
3,261
Views on SlideShare
3,255
Embed Views
6

Actions

Likes
1
Downloads
20
Comments
0

1 Embed 6

http://www.slideshare.net 6

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Capistrano Capistrano Presentation Transcript

    • Capistrano by Jason Noble http://jasonnoble.org
    • Getting Started
      • http://github.com/jasonnoble/capistrano-demo/
      • Click fork
      • Click “Your Clone URL”
      • Paste into a terminal window
      • Two branches in this repo
        • master (base shopping cart, no capistrano changes)
        • working_capistrano_deploys
    • Quick Demo of App
      • Create/Migrate databases
        • rake db:create:all
        • rake db:migrate
      • script/server
      • http://localhost:3000/store
      • http://localhost:3000/admin
        • admin/admin
      • http://localhost:3000/users
    • Server preperation
      • Install Git (1.5.5.6)
      • Install Rake gem (0.8.7)
      • Install Rails gem (2.3.5)
      • Install mongrel_cluster gem (1.0.5)
      • Mysql server / Mysql gem
    • Local Preparation
      • sudo gem install capistrano
        • Latest is 2.5.10 (as of 11/2009)
      • capify .
        • Creates ./Capfile
        • Creates ./config/deploy.rb
    • config/deploy.rb
      • set :application, “shopping_cart”
      • set :repository, git@github.com: jasonnoble /capistrano-demo.git
      • set :scm, :git
      • set :user, “ jasonn ”
      • default_run_options[:pty] = true
        • Enables password entry for git
      • set :branch, ”master”
      • set :deploy_to, "/var/www/#{user}/#{application}”
      • set :deploy_via, :remote_cache
    • config/deploy.rb cont.
      • role :web, “ 192.168.255.54 ”
      • role :app, “ 192.168.255.54 ”
      • role :db, “ 192.168.255.54 ”, :primary => true
      • set :mongrel_conf, “#{current_path}/config/mongrel_cluster.yml”
      • set :use_sudo, false
    • config/deploy.rb cont.
      • namespace :deploy do
      • namespace :mongrel do
      • [:stop, :start, :restart ].each do |t|
      • desc "#{t.to_s.capitalize} the mongrel appserver"
      • task t, :roles => :app do
      • invoke_command "mongrel_rails cluster::#{t.to_s} -C #{mongrel_conf}", :via => run_method
      • end
      • end
      • end
      • desc "Customer restart task for mongrel cluster"
      • task :restart, :roles => :app, :except => { :no_release => true } do
      • deploy.mongrel.restart
      • end
      • desc "Customer start task for mongrel cluster"
      • task :start, :roles => :app, :except => { :no_release => true } do
      • deploy.mongrel.start
      • end
      • desc "Customer stop task for mongrel cluster"
      • task :stop, :roles => :app, :except => { :no_release => true } do
      • deploy.mongrel.stop
      • end
      • end
    • config/mongrel_cluster.yml
      • ---
      • cwd: /var/www/rails/ jasonn /shopping_cart/current
      • log_file: log/mongrel.log
      • port: " 7010 ”
      • environment: production
      • address: 0.0.0.0
      • pid_file: tmp/pids/mongrel.pid
      • servers: 2
    • config/database.yml
      • Production setting, change
      • socket: /tmp/mysql.sock
      • to
      • socket: /var/lib/mysql/mysql.sock
      • Modify the database name to be unique
    • Setup SSH keys on the server
      • scp ~/.ssh/id_dsa.pub 192.168.255.54:~/
      • ssh [email_address]
        • Login with your password
      • mkdir –p ~/.ssh
      • chmod 755 ~/.ssh
      • mv ~/id_dsa.pub .ssh/authorized_keys
      • Logout. When you log back in it should not ask for a password.
      • While logged in, run the following:
        • ssh github.com
          • This adds the GitHub host to your “known hosts” file
          • Will prevent later errors
    • Add Deploy SSH key to Github
      • On your server:
        • ssh-keygen –d
        • cat ~/.ssh/id_dsa.pub
          • Copy
      • http://github.com/jasonnoble/capistrano-demo/edit
        • Click Add another deploy key
        • Paste your key into the box
    • cap -T
      • Capistrano uses the “cap” command
      • Similar to Rake, has tasks available
      • cap –T
        • cap deploy # Deploys your project.
        • cap deploy:check # Test deployment dependencies.
        • cap deploy:cleanup # Clean up old releases.
    • cap deploy:setup
      • This makes a bunch of directories that capistrano needs to work
      • /var/www/rails/ username /app_name
        • shared
        • releases
      • Sets up directory ownership properly
    • cap deploy:check
      • Verifies required directories are there
      • Tests SSH connectivity
      • Verifies some minimal gems are installed
    • Git installed in custom dir
      • If you get the following error: The following dependencies failed. Please check them and try again: --> `git' could not be found in the path (127.0.0.1)
      • Add the following to config/deploy.rb
        • set :scm_command, "/path/to/git/bin/git"
        • set :local_scm_command, "git"
    • cap deploy:cold
      • First time deploy method
      • This should error out when trying to use the database (we haven’t created it!)
      • Login to the server
        • RAILS_ENV=production rake db:create
      • Logout and run cap deploy:cold again
    • Your site is live!
      • http://192.168.255.54:7010/
        • Use the mongrel port you specified in config/mongrel_cluster.yml
    • Make a change to the rails app
      • Change the text in one of the views
      • commit it via git
      • cap deploy
        • We use deploy instead of deploy:cold because it’s already been deployed once
    • Questions?