Resources for Developers

Ruby

Ruby is officially supported by Scalingo. Furthermore, custom support is added for the Rails framework in all its versions.

Buildpack

The buildpack is based on Bundler and will install the dependencies defined in the Gemfile and Gemfile.lock of your project (source of the buildpack).

Ruby application

Presence of a Gemfile

Rack based application

Presence of a config.ru

Rack environment

When a Rack application is detected, the following environment variable will automatically be set by the platform:

  • RACK_ENV=production

Rails application

Rails app detection

Rails 2

Presence of a config/environment.rb

Rails 3, Rails 4

Presence of a config/application.rb

Rails 5

Presence of a config/application.rb

For Rails 5.1, node and yarn will be automatically installed if the gem webpacker is installed.

Rails environment

When a Rails application is detected, the following environment variables will automatically be set by the platform:

  • RACK_ENV=production
  • RAILS_ENV=production

Specifying a custom Ruby runtime

If your need to install a custom version of Ruby, you can achieve that by specifying it in your Gemfile:

Ruby MRI 2.4.2

ruby "2.4.2"

JRuby 2.0.0

ruby "2.0.0", :engine => "jruby", :engine_version => "1.7.20"

List of the compatible runtimes

Only last patch version of each major release is listed here, but other minor version are also present if your require them for specific tests.

MRI

  • 2.5.0
  • 2.4.2
  • 2.3.5
  • 2.2.8
  • 2.1.10
  • 2.0.0

Jruby

  • 1.7.18: Ruby versions: 1.8.7, 1.9.3, 2.0.0
  • 1.7.19: Ruby versions: 1.8.7, 1.9.3, 2.0.0
  • 1.7.20: Ruby versions: 1.8.7, 1.9.3, 2.0.0

Ruby application web server

Ruby contains a default application web server named WEBrick. As it is always present, most web framework use it by default. It’s good enough in development, but it has never been thought to be a production server.

Do not use WEBrick

WEBrick has the following characteristics:

  • Single threaded
  • Single process

It can’t handle several request in parallel, they are all in a single request queue. As a result, very poor performance can be expected. To get the best of your containers, you need to use a real production-ready application server.

Using Puma as a production server

To handle several requests in parallel, we recommend puma. To use it, add it as dependency in your Gemfile:

gem 'puma'

And configure how to launch your app by defining a Procfile:

web: bundle exec puma -C config/puma.rb

The configuration file looks like the following:

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  # Worker specific setup for Rails 4.1+
  ActiveRecord::Base.establish_connection
end

Thus you can change the global settings by modifying the environment variables WEB_CONCURRENCY and MAX_THREAD and restarting your app.


mode_edit Suggest edits