TIL: Deploying a Sinatra app to Render.com

This morning I wanted to deploy a simple Sinatra app to Render.com. It wasn’t super obvious to me, so I figured I’d write down what worked in the end.

First, a Gemfile:

# Gemfile
source 'https://rubygems.org'

gem 'sinatra'
gem 'sinatra-contrib'
gem 'puma'

* I’m pretty sure sinatra-contrib is not necessary.

Also at this point in time you’ll need to bundle lock --add-platform x86_64-linux for your Render.com deployment to work.

Here’s my main.rb "hello world" app:

# main.rb
require 'sinatra'

get '/' do
'Hello world!'

And .ruby-version, assuming you’re using a version manager like rbenv:


I decided to use a render build file, even though it’s very simple. ./bin/render-build.sh:

#!/usr/bin/env bash
# exit on error
set -o errexit

bundle install

Finally, in production (Render.com) I needed to use a config.ru file. Attempting to run with a simple ruby main.rb resulted in this error:

==> Starting service with 'ruby main.rb'
<internal:/opt/render/project/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- sinatra (LoadError)
     from <internal:/opt/render/project/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
     from main.rb:2:in `<main>'

Here’s my config.ru:

# config.ru (run with rackup)
require './main'
run Sinatra::Application

And so my Build Command in Render.com settings:


And my Start Command in Render.com settings:

rackup -p $PORT