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 Application Detection

Scalingo automatically detects the use of Rails, whatever the version used. All Rails versions are supported.

Starting with 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

Bundler Version

Our deployment system is automatically using the latest available bundler version.

  • Bundler 1: 1.17.3
  • Bundler 2: 2.3.10

If your application fails to boot with the following error logs:

Activating bundler (2.0.1) failed:
Could not find 'bundler' (2.0.1) required by your /app/Gemfile.lock.

It means you need to update bundler in your project:

$ gem update bundler
$ bundle update --bundler
$ git add Gemfile.lock
$ git commit -m "Update bundler to new version"
$ git push scalingo master

Ruby Versions

Availability

MRI scalingo-20 scalingo-22
3.3 up to 3.3.5 up to 3.3.5
3.2 up to 3.2.5 up to 3.2.5
3.1 up to 3.1.6 up to 3.1.6
3.0 up to 3.0.7 unsupported
2.7 up to 2.7.8 unsupported
2.6 up to 2.6.8 unsupported
2.5 up to 2.5.9 unsupported

Select a Version

The default Ruby version on both scalingo-20 and scalingo-22 is the latest 3.1 version. If you need to install another version, specify it in your Gemfile, using the ruby keyword. For example, to install Ruby 3.3.0:

ruby "3.3.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_THREADS and restarting your app.

WEB_CONCURRENCY

The level of concurrency configured is defined automatically according to the memory of the containers of your application. If you want to override this value, you can define the environment variable: WEB_CONCURRENCY.

The default values are:

Container Memory (MB) Default Concurrency
256 1
512 1
1024 2
2048 2
4096 4
8192 4

Suggest edits

Ruby

©2024 Scalingo