Deploying my first rails app
I’ve been working on a little Ruby on Rails application on and off for a few weeks, and finally have enough together that it made sense to deploy it somewhere other than my laptop. It ended up taking all day; here are some of the high and lowlights, in chronological order.
- When building ruby from source on my Breezy xen slice, I ended up with no zip lib. Gotta download a way old version that says it’s obsolete. This is just one reason why package managers are worth having; too bad there isn’t an acceptable versions of ruby in Breezy. I did blow a few hours trying to upgrade to Edgy yesterday, but bad Xen things happened so I’m stuck on Breezy for now.
- Capistrano needs ruby’s openssl lib, which is part of the core, but if you don’t have the ssl dev libraries around, it doesn’t get built. So, rebuild ruby and that part worked.
- I’ve been using sqlite for development and though it would be nice for production, too, so I had to install libsqlite3-dev & the sqlite3-ruby gem. Started to think about making it work with Capistrano, via ideas here. But even when the permissions all seem to work ( as in the user running the app can write to the file with the sqlite3 command line tool ) rails is only able to read from it - pukes with a generic error when it tries to write. So, mysql it is. Thanks to migrations, switching from sqlite to mysql only took a minute. Cool.
- Not so clear on how capistrano knows what user to run things as - this seems like the main reference, but I’m having trouble finding everything I need in there. Probably need to dig around in the source.
- This app isn’t running on its own domain, and I had an unpleasant time with RAILS_RELATIVE_URL_ROOT & lighttpd. I’m running rails 1.2 RC 2 and haven’t had a chance to dig around the changelogs to see if there are relevant changes in there that would explain the headaches, which are that it only seems to work if you set it in routes.rb as discussed here. That’s lame because you can’t just have it for production then. A better approach seems to be just doing it in lighttpd except that the app doesn’t then write urls correctly.
- Thanks to this lighttpd configuration guide for pointing out that alias.url needs to be set as well for the public/ directory to be properly served in this kind of configuration.
In retrospect, I probably would have been better off taking easier paths with a few things - running the app on its own subdomain, and going right to mysql both would have saved me some trouble. There still would have been a number of annoyances but that’s par for the course deploying software. Definitely not as much fun as writing the actual application.
August 19th, 2007 at 1:42 PM
What I was able to do is to use RAILS_RELATIVE_URL_ROOT by sticking it in “routes.rb” as described in the post you mentioned. Then I simply made a constant (MY_PATH) in the environments/development.rb and environments/production.rb files (which needed to be different) and then used that on the call in routes.rb:
ActionController::AbstractRequest.relative_url_root = MY_PATH
This may get around the issue you were describing. So… in development.rb you would have something like: MY_PATH = ’/whatever’
August 24th, 2007 at 5:07 PM
Right on - that totally takes care of it.
Here’s what I have now, which is working well:
1. add something like ActionController::AbstractRequest.relative_url_root = PATH_PREFIX
to config/routes.rb
2. add PATH_PREFIX = ”
after the bootstrap part of config/environments.rb
3. override it in config/environments/production.rb
PATH_PREFIX = ’/whatever’