I decided to run AltLaw.org under a “/v1″ URL prefix. It’s still beta, and the URL structure will likely change in the future. I don’t want to break 160,000 links when that day comes. Fortunately, Mongrel makes this pretty easy with the –prefix option to mongrel_rails.
I added --prefix '/v1' to my mongrel_rails command line. After removing absolute URLs (those not using {:controller=>...}) from my views, everything worked great.
The only problem is, this technique prevents Apache from serving static files without hitting the Mongrel server. A typical mod_rewrite directive like this:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
RewriteRule (.*) $1 [L]
doesn’t work, because the REQUEST_URIs now all start with “/v1″ and the files in “MyRailsApp/public” don’t.
Here’s a simple workaround: make a symlink like this:
cd /path/to/MyRailsApp/public
ln -s . v1
That’s right, “v1″ is a symlink that points back to the “public” directory. I was afraid this might cause an infinite loop, but it doesn’t. Keeping the same mod_rewrite rule above, Apache will serve the static files under “public” even if the request is prefixed with “/v1″. Pretty cool.
No Comments »
I’ve used Darcs as my only version-control system for a while now. When I got into Rails, I naturally wanted to use Capistrano. Unfortunately, Darcs and Capistrano don’t get along too well. Darcs’ file-based repositories don’t mesh well with Capistrano’s assumption that the repository is accessed through a server, a la Subversion.
I ran into problems with cap deploy:update_code because Darcs couldn’t find the repository. After a discussion on the Capistrano mailing list I decided to go my own route.
I have two Darcs repositories, one on my development machine and one on the server. I darcs push patches from development to the server. Then I have my own custom Capistrano tasks to get the latest code from the server’s copy of the repository. This is adapted from the Capistrano sources:
namespace :deploy do
task :update_code, :except => { :no_release => true } do
on_rollback { run "rm -rf #{release_path}; true" }
run("darcs get --partial /home/myapp/repo --repo-name=#{release_path}")
run("rm -rf #{release_path}/_darcs")
finalize_update
end
end
I also had to write a custom finalize_update task to add the links to the shared Rails directories:
namespace :deploy do
task :finalize_update, :except => { :no_release => true } do
run <<-CMD
ln -s #{shared_path}/log #{latest_release}/log &&
ln -s #{shared_path}/tmp #{latest_release}/tmp &&
ln -s #{shared_path}/data #{latest_release}/data &&
ln -s #{shared_path}/index #{latest_release}/index &&
ln -s #{shared_path}/config/database.yml #{latest_release}/config/database.yml &&
ln -s #{shared_path}/public/system #{latest_release}/public/system
CMD
end
end
No Comments »