TIL: Deploying a Sinatra app to Render.com — Good Enough
source link: https://goodenough.us/blog/2023-06-05-til-deploying-a-sinatra-app-to-render-com/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Deploying a Sinatra app to Render.com — Good Enough
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!'
end
And .ruby-version
, assuming you’re using a version manager like rbenv:
3.2.2
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:
./bin/render-build.sh
And my Start Command in Render.com settings:
rackup -p $PORT
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK