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.
First create a new rails app
If you check your Gemfile, you should see some key differences:
gem you have
Some 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
some configuration variables for Rails and we’re set.
Note: here I left
group just as an example.
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.
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:
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.