capistrano-ext-textdrive
I’ve finally found a workable set of deployment practices for getting my little rails apps up and running in shared hosting at TextDrive. None of the actual mechanics are particularly en vogue these days – I’m just using plain old lighttpd with external fcgi processes.
What is kind of fun, though, is that I’ve reduced almost all of the duplication across my deploy.rb files, so now they look like this:
require 'capistrano/ext/textdrive'
set :application, 'reading'
set :domain, 'matthewtodd.org'
This is exceedingly pleasing to me, because these are the only 2 settings I’d ever change from app to app—precisely what belongs in an application-specific configuration file.
Herewith, a description of the behavior that require
line provides:
textdrive_configure_lighttpd
Run this once for your account.
- creates lighttpd configuration file and supporting directory structure for virtual hosts, logs and PID files
- writes an rc.d start/stop/restart script for lighttpd, and a crontab entry to run it at server startup
textdrive_after_setup
Run this once for your application. An after_setup task has been defined to call this automatically, but if you write your own, you’ll clobber it—see this test case – so be sure to call textdrive_after_setup if you write a custom after_setup task.
- creates an empty mysql database named
"#{user}_#{application}"
and writes"#{shared_path}/database.yml"
referencing it - writes an rc.d start/stop/restart script for the application and a crontab entry to run it at server startup
- writes a lighttpd virtual host configuration and restarts lighttpd
- configures apache to proxy requests for
"#{application}.#{domain}
to lighttpd
textdrive_after_update_code
Run this every time you deploy. An after_update_code convenience task has been defined just as above, with the same clobberability caveats.
- create symlinks to
"#{shared_path}/database.yml"
and"#{shared_path}/sockets"
from the appropriate places under"#{release_path}"
If you'd like to try it out
This code’s packaged as a gem, but I haven’t released it anywhere yet. So:
svn export http://matthewtodd.org/svn/public/capistrano-ext-textdrive
cd capistrano-ext-textdrive
rake install
And then your deploy.rb is going to need a few more lines than mine, since I made the defaults fit my needs and tastes. It will probably end up looking something like this:
require 'capistrano/ext/textdrive'
set :application, YOUR_APPLICATION
set :domain, YOUR_DOMAIN
set :user, YOUR_USERNAME
set :lighttpd_port, YOUR_LIGHTTPD_PORT
set :repository, YOUR_REPOSITORY_PATH
Do be sure to read through the gem code first to understand what it’s doing – I expect things will generally work fine, but it would be a shame to run into trouble with it.
A few notes
One last unautomated bit is that you’ll need to set ProxyPreserveHost On
for each Apache virtual host into which you’re deploying rails apps this way. (See steps 10-12 in this bit of TextDrive documentation.)
Most of this approach comes from Installing a Rails Application at TextDrive, in the TextDrive knowledge base.
See also Shovel, from Geoffrey Grosenbach.