Saturday, March 10, 2012

Deploying with Trinidad on Heroku

Heroku is an excellent platform for JRuby deployment, but it only provides indirect support for JRuby through it's Java stack. As a result, deployment on Heroku requires some XML, a little knowledge of Maven, and bunch of hacky-feeling tricks. That's why I chose not to include a detailed discussion of it in my book. Instead, I thought it would make a nice blog post.

I've created the simplest possible Rack application that can be deployed on Heroku with Trinidad and JRuby <https://github.com/jkutner/jruby-trinidad-heroku>. The key elements are these:
  • pom.xml - this is a Maven config file that can be copied as is (in most cases).
  • Jemfile - a renamed Gemfile so that Heroku doesn't think this is an MRI app.
  • Procfile - a Heroku config file with instructions for running the app.
  • script/jruby - a modified jruby executable for the Heroku platform.
  • config.ru - the application itself (can be replaced with any Rack app)
Once your application has these components, you'll need to create the Heroku application by running this command from the application root:


The first thing you'll notice is that we are creating an app on the Heroku Cedar stack. This provides the Java platform support. We're also using a buildpack takes care of setting up the essentials for any Java application on Heroku (most importantly is making sure the Maven dependencies are available at runtime).

Then you can deploy with this command:


There is a slightly out-dated post by Chris Howie on deploying Sinatra on a Trinidad, JRuby, Heroku stack. There is also an example application called Punchy that has been ported to Heroku by Mathew Rodley. Heroku has changed it's configuration since these were created, but the basics hold true. They are worth reading.

In addition to Heroku's lack of native JRuby support, it also lacks native support for Trinidad. So it's unclear how many of the Trinidad extensions will function. This is unfortunately because the Trinidad extension are a big part of why this platform is superior to almost every MRI-based server.

In the future, I will investigate Trinidad extensions on Heroku and follow up with another post.


No comments:

Post a Comment