Skip to content
Ruby Rack tutorial

Build and deploy a Ruby Rack application

Rack provides a standard interface between Ruby web applications and application servers. This tutorial creates a minimal Rack 3 application served by Puma and deploys it with the Clever Cloud Ruby runtime.

Create the Rack application

Install a currently supported Ruby release, Bundler and Git, then initialize the project:

mkdir myRackApp
cd myRackApp
git init

Create a Gemfile with Rack and Puma. Declaring the Ruby branch keeps local and deployed environments consistent:

Gemfile
source "https://rubygems.org"

ruby "~> 3.4"

gem "puma", "~> 7.0"
gem "rack", "~> 3.2"

Create the Rack entry point:

config.ru
class HelloWorld
  def call(_env)
    [200, { "content-type" => "text/plain" }, ["Hello world!"]]
  end
end

run HelloWorld.new

Install the dependencies and generate the lockfile:

bundle install
bundle lock --add-platform x86_64-linux

You can check the application locally with bundle exec puma config.ru, then open http://localhost:9292.

Deploy on Clever Cloud

Install Clever Tools, log in and create a Ruby application linked to the current directory:

npm i -g clever-tools
clever login

clever create -t ruby -a myRackApp

Clever Tools targets your personal organisation by default. To use another organisation, add --org ORGANISATION or -o ORGANISATION when you create or link the application.

You can display your application’s URL or add a custom domain. A custom domain also requires DNS configuration:

clever domain
clever domain add your.website.tld

Commit the files and deploy:

git add .
git commit -m "First deploy"

clever deploy
clever open

The Ruby runtime installs the locked gems and starts config.ru with Puma. It manages the listening socket and NGINX connection, so this application does not need a custom port or run command. Read application configuration with ENV["VARIABLE_NAME"].

Learn more

Last updated on