Getting Started with Capistrano in Ten Easy Steps

3,330 views
3,262 views

Published on

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,330
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
32
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Getting Started with Capistrano in Ten Easy Steps

  1. 1. Getting Started with Capistrano in Ten Easy Steps Keith Pitty http://keithpitty.org keith@keithpitty.org
  2. 2. What is Capistrano? ● A tool that aims to make it easy to deploy Rails applications! ● Written by Jamis Buck, one of the core Rails team 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 2
  3. 3. These ten steps are based on my experience ● Starting point: – “Agile Web Development with Rails” – 2nd edition, Section 27.5 ● There may be better ways, but... ● The following steps worked for me 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 3
  4. 4. Step 1: Install Software ● Client and server – my client: OS X – my server: Fedora Core 6 on a VPS ● Native components – apache2, mysql5, ruby, rb-rubygems, rb-termios ● Ruby gems – rake, rails, termios, capistrano, mongrel, mongrel_cluster $ sudo gem install --include-dependencies [gem] 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 4
  5. 5. Step 2: Set up Database mysql> create database app; mysql > grant all privileges on app.* to 'app'@'localhost identified by 'password' with grant option; 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 5
  6. 6. Step 3: Add Mongrel to Project ● On development machine, this will create config/mongrel_cluster.yml: $ mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N -2 /deploy/path/current 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 6
  7. 7. Step 4: Apply Capistrano to Project ● On development machine, this will create config/deploy.rb and lib/tasks/capistrano.rake: $ cap –apply-to /local/project/path [app] 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 7
  8. 8. Step 5: Configure Capistrano (1) ● Edit config/deploy.rb: – Add as first statement: require 'mongrel_cluster/recipes' 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 8
  9. 9. Step 5: Configure Capistrano (2) ● Edit config/deploy.rb: – Set variables: set :application, “app” set :repository, “http:svn.host.com/#{application}/trunk” set :deploy_to, “/usr/local/railsapps/#{application}” set :mongrel_conf, “#{current_path}/config/mongrel_cluster.yml” 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 9
  10. 10. Step 5: Configure Capistrano (3) ● Edit config/deploy.rb (continued): set :web, “my.host.com” set :app, “my.host.com” set :db, “my.host.com”, :primary => true set :user, “keith” 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 10
  11. 11. Step 6: Set up Directories ● On development machine, this will set up directories on target server: $ cap setup 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 11
  12. 12. Step 7: Secure Database ● Copy database.yml to #{shared_path}/config on server ● Rename to database.yml.production and set production username and password ● Add the following to :after_update_code task in config/deploy.rb: db_config = “#{shared_path}/config/database.yml.production” run “cp #{db_config} #{release_path}/config/database.yml” 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 12
  13. 13. Step 8: Ensure Subversion is OK ● Installed on client and server? ● Repository created on server? ● Apache configured for subversion? ● svn import? ● svn checkout? 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 13
  14. 14. Step 9: Deploy and Verify ● One more pre-req: edit sudoers file on server ● Deploy app, create tables (from client): $ cap cold_deploy $ cap migrate ● Verify (on server): $ curl -I http://127.0.0.1:8000 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 14
  15. 15. Step 10: Configure Apache ● Configure Apache to connect to Mongrel – Proxy for mongrel_cluster – VirtualHost with rewrite rules for app – see AWDwR, Section 27.5, Step Five for details ● Restart Apache ● App should now work via browser! 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 15
  16. 16. From now on it will be easy! ● When you've checked in some changes: $ cap deploy ● If you need to back out your changes: $ cap rollback 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 16
  17. 17. Resources ● “Agile Web Development with Rails” – Second Edition, section 27.5 ● http://manuals.rubyonrails.com/read/book/17 – when it's available ● http://rubyforge.org/projects/capistrano/ ● http://weblog.jamisbuck.org ● capistrano@googlegroups.com ● rubyonrails-deployment@googlegroups.com 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 17
  18. 18. Thanks for listening! Keith Pitty http://keithpitty.org keith@keithpitty.org 21 Feb 2007 Sydney RoR Meetup: quot;Getting Started with Capistranoquot; Keith Pitty 18

×