Last post I demonstrated setting up a Ruby on Rails app on Heroku, running with the Puma server. As I mentioned before, in order to get the most out of Puma you should use a Ruby implementation with real threads like JRuby or Rubinius 2. In this post we’ll repeat most of the previous steps, but this time we’ll use a Third-Party Buildpack and get setup with JRuby.
Note: I’m not covering the specifics other than telling you to use RVM or rbenv to setup JRuby (I’m running 1.6.7.2)
First create a new rails app
If you check your Gemfile, you should see some key differences:
1
sqlite3
gem you have 1
activerecord-jdbcsqlite3-adapter
1
jruby-openssl
included1
assets
group includes 1
therubyrhino
gemSome adjustments are needed to get this new Rails app to play nice on
Heroku with Puma. First, we can’t just use the
gem; You need to use
the 1
pg
instead. Add 1
activerecord-jdbcpostgresql-adapter
and set
some configuration variables for Rails and we’re set.1
puma
Gemfile
Note: here I left
in the
1
activerecord-jdbcsqlite3-adapter
group just as an example.1
development
config/application.rb
config/production.rb
Heroku’s Cedar stack has no native language or framework; instead your
sever is setup via a set of scripts called Buildpacks. Heroku
provides buildpacks for Ruby, Node.js, Python and a handful of others,
but you can also create or use your own Buildpack by using the
flag and providing a URL. Here we’ll use JRuby’s Heroku Buildpack from github.com/jruby/heroku-buildpack-jruby.1
--buildpack
Now when you push your code up, Heroku’s slug compiler knows how to package things an build them to use JRuby.
As I mentioned last time, a
tells Heroku how to run your app:1
Procfile
Thats it! Commit your changes and push to Heroku like before:
Within a few moments you should be running on JRuby/Puma on Heroku. Notice that your slug size is significantly larger than a normal stock Rails app running on MRI. That’s because of 4th item you see above, “Vendoring JRuby into slug”.
Congratulations! You’re now running Rails with JRuby and Puma on Heroku.