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 initCreate a Gemfile with Rack and Puma. Declaring the Ruby branch keeps local and deployed environments consistent:
source "https://rubygems.org"
ruby "~> 3.4"
gem "puma", "~> 7.0"
gem "rack", "~> 3.2"Create the Rack entry point:
class HelloWorld
def call(_env)
[200, { "content-type" => "text/plain" }, ["Hello world!"]]
end
end
run HelloWorld.newInstall the dependencies and generate the lockfile:
bundle install
bundle lock --add-platform x86_64-linuxYou 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 myRackAppClever 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.tldCommit the files and deploy:
git add .
git commit -m "First deploy"
clever deploy
clever openThe 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"].