lost password?

home
•  xaraya
•  rails +
•  django
•  webdev +
•  xamp
•  musings

rss
Tag this page
   

» Blogs that link here
last modified: Nov 02, 2007
(first posted: Oct 30, 2007)
(2606 Reads)
Permalink

Deploying with Capistrano from a local svn

A quick "how-to" deploy a Rails based site with Capistrano 2.0 from a local svn repository using the capistrano_rsync_with_remote_cache gem

Capistrano is a Ruby (on Rails, but not necessarily) utility for deploying applications from development machines to servers. It's designed to check out the code from an online repository (normally Subversion - svn), and make a fresh production directory on the server and switch it live.

When your repos is local and not accessible from the server, Capistrano has limited support for this scenario. Using "set :deploy_via, :copy" checks out everything into a temporary directory, zips it up (tgz), and copies the entire thing every time you deploy. Not very nice, especially on my slow (satellite) connection, and especially if only a few files change from one deploy to the next.

There are a number of recipes written up to utilize rsync in conjunction with Capistrano for incremental deployments. rsync is a command-line file synchronization utility probably already distributed with your (*nix) US. (That's "r" as in "remote", not "Ruby", by the way). (see the Capistrano mailing list ).

The best solution I've found is the capistrano_rsync_with_remote_cache gem written by Mark Cornick at Viget Labs.

With this gem, when you do "cap deploy" it will check out the latest version from svn into the .rsync_cache/ directory, and use rsync to copy only those files that have changed over to the server. On the server side, a cache is maintained in the shared/ directory, which is then copied to the current production copy of your project.

Get Capistrano 2 Going with :copy

From your Rails project root,

  $ sudo gem install -y capistrano
$ capify .

Edit config/deploy.rb, and set the variables as needed, including,

set :application, "myapp"
set :domain, "www.myapp.com"
set :repository, "file:///Users/myname/#{application}/trunk"
set :deploy_via, :copy

If necessary you may also need to add or modify tasks in the Capfile (perhaps as recommended by your hosting service).

To setup the directories on the server (needed once and only once):

  $ cap deploy:setup

To deploy the entire project (eg first time):

  $ cap deploy:cold

And to deploy updates:

  $ cap deploy

Unfortunately, as explained above, the deploy task is not much different from the deploy:cold one when using :copy

Get Capistrano Going with :rsync_with_remote_cache

The gem's docs are pretty thin how to install and get it going. So here's some more details. Check out and build the gem locally, go to a temporary directory and,

  $ mkdir CapistranoRsyncWithRemoteCache
  $ svn co http://svn.extendviget.com/lab/trunk/gems/capistrano_rsync_with_remote_cache
  $ cd capistrano_rsync_with_remote_cache/
  $ rake package
  $ cd pkg
  $ sudo gem install capistrano_rsync_with_remote_cache-2.1

Then edit your deploy.rb file, changing :deploy_via :copy to:

set :deploy_via, :rsync_with_remote_cache

It also make sense to (optionally) add this line so the .svn sub-directories are not deployed: 

set :rsync_options, '-az --delete --exclude=.svn --delete-excluded'

Now, "cap deploy" checks out to .rsync_cache, and copies only the changed files over to the server.

 

There are no comments attached to this item.

Post a new comment

How many days in a week?

Name :