Capistrano 2.3.0
Posted by Jamis on Friday, May 2
On February 16 I set myself to travel a path that I hoped would eventually help me deal with the project overload I was feeling. Today I get to release Capistrano 2.3, which is very near to the end of that path!
gem install capistrano
Capistrano 2.3 is primarily significant in that it switches to the new Net::SSH v2 library, which is faster and slimmer than the older Net::SSH v1 library. It also pulls in Net::SFTP v2, and the new Net::SSH::Gateway and Net::SCP libraries.
In addition to that, cap 2.3 adds several exciting (if I do say so myself) new features, and a few bug fixes that had lingered for far too long.
FEATURE: The :copy strategy has been significantly improved. Instead of doing a blind checkout/export, archiving the result, and copying it over, you can specify that a local cached copy of your repository should be used. If the cached copy does not exist, it is created (via a checkout), otherwise it is simply updated (a much faster operation than a checkout, typically). This functions much like the :remote_cache strategy, but locally. To use this, simply set the :copy_cache variable to true:
1 2 |
set :deploy_via, :copy set :copy_cache, true |
By default, the cached copy will be in your machine’s temporary directory (/tmp, for example), but you can specify your own location by setting :copy_cache to the desired path:
1 2 |
set :deploy_via, :copy set :copy_cache, "/u/caches/#{application}" |
But wait! There’s more! Suppose you have certain files that you don’t want to deploy, like photoshop files or your .git directory. You can set the :copy_exclude variable to a file glob (or an array of globs):
1 2 3 |
set :deploy_via, :copy set :copy_cache, true set :copy_exclude, [".git", "materials"] |
This should make your deploys faster than ever, especially using a tip I hope to share in the next day or two that uses this in conjunction with some vendor/rails symlinking.
FEATURE: Even though I strenuously believe it is a mistake to deploy anything that is not under source control, I’ve finally caved and added a dumb :none SCM module. It can be used to deploy a specific directory if used with the :copy strategy:
1 2 3 |
set :repository, "." set :scm, :none set :deploy_via, :copy |
Again, there are very, very few cases when I think use of this technique is justified, but because I ran into one myself a month ago, I decided it was worth adding.
FEATURE: Support was added for “depend :remote, file” to test for the existence of a specific file:
depend :remote, "/etc/syslog.conf" |
This is used in conjunction with the deploy:check task.
FEATURE: You can specify ssh_options per-server, now, simply by giving an :ssh_options key and corresponding hash with the server definition:
role "some.host", :ssh_options => { :keys => "/path/to/key" } |
FEATURE: There are two new file transfer helpers, upload and download, which are much more powerful and resource-friendly than the old ‘put’ and ‘get’ helpers. You can use upload and download to transfer single files, or entire directory trees:
1 2 |
upload "/local/file", "/remote/file" download "/remote/file", "/local/file" |
This will transfer to or from all active servers, which is particular tricky when using the download helper, since it will download the file simultaneously from all active hosts. To make this work, you need to make sure each is downloaded to a different location:
1 2 |
Dir.mkdir("destination") download "/remote/file", "destination/file-$CAPISTRANO:HOST$" |
The above will download the file from each host to a file on the local host, where the local file includes the name of the source host. Tricky!
Also, you can now specify that you want to upload or download via SCP instead of SFTP:
1 2 |
upload "local", "remote", :via => :scp download "remote", "local", :via => :scp |
The default is :sftp.
The less exciting (but still mildly titillating) things are the bug fixes and pleasure-enhancing behavioral changes:
- The default run options are now mixed into the command options when executing a command from the capistrano shell.
- The git SCM now uses git-ls-remote instead of git-rev-parse to resolve the revision of the checkout.
- A trivial export method has been added to the git SCM.
- The git SCM will include tags when it fetches.`
- The sudo() helper now works nicely with complex and chained commands.
- The deploy:setup task will now use sudo if :use_sudo is true (the default)
So, have at it! Remember to report bugs to http://capistrano.lighthouseapp.com. And patches are always welcome via git—just fork the capistrano repository at git://github.com/jamis/capistrano.git (thanks GitHub!).
Cheers!
