Bundle Your Torquebox Gems for Production

We recently decided to try Torquebox for a JRuby on Rails app we’re working on. We chose Torquebox for the same reason we chose JRuby: reduce external platform dependencies to maximize ease of deployment in heterogeneous environments. Getting it up and running in development was pretty straight forward. However, when we tried to get a production environment together we ran into some Bundler woes.

Our Gemfile looks something like this:

We don’t want to include our test or development gems in our production deployments. That way we wouldn’t have to worry about using development libraries which might rely on native libraries through ffi, increase the size of our deployable artifact, or otherwise complicate our production runtime. We accomplished this by using bundle install --without test development when packaging our gems into the JRuby install that would go out with our production server artifact.

We create our current deployable artifact by:

  1. downloading and unpacking Torquebox
  2. replacing its embedded JRuby with the version that we’re using
  3. installing our non test and development gems into that JRuby install
  4. packing up our Rails app into a Torquebox knob
  5. tar’ing the whole thing up

One of our first problems was the inability to load our Bundler environment in production. We kept getting this error when launching torquebox:

My first unfounded reaction was to think that some asshole included a dev dependency as a runtime dependency in their gem (I WAS WRONG).

It turns out that Rails seems to currently need to be told not to load certain gem groups via an entry in the .bundle/config file. The file’s BUNDLE_WITHOUT: test:development property is automatically saved when your run bundle install --without test development. However, if you revert that change because you WANT to use dev and test gems while developing and testing, it might not be there when you package up your app for production. Luckily, the entries in .bundle/config can also be specified as env vars AND torquebox lets you define them for your app in config/torquebox.yml:

So far Torquebox is looking pretty bad-ass!

  • Micah–

    Thanks for both trying out TorqueBox and sharing your experiences with it!

  • Comments are closed.