How to deploy a Rails 7 app to Render
Introduction
Heroku no longer has a free tier. This blog post lists the reasons why.
Heroku used to be my go-to service for experimenting with new frameworks. I would generate the starter app, and then deploy it to Heroku.
Then I would continue to incrementally build on what had been deployed.
I searched for options and came across Render and Fly.io.
I was particularly interested in a service that could host a Ruby on Rails app and a PostgreSQL database.
I decided to experiment with Render.
Adding the necessary files
The following files are necessary as a prerequisite to make the deployment possible;
render.yaml
render-build.sh
render.yaml
is added to the root
databases:
- name: rumblr
databaseName: rumblr
user: root
plan: free
services:
- type: web
name: rumblr
runtime: ruby
plan: free
buildCommand: "./bin/render-build.sh"
# preDeployCommand: "./bin/rails db:migrate" # preDeployCommand only available on paid instance types
startCommand: "./bin/rails server"
envVars:
- key: DATABASE_URL
fromDatabase:
name: rumblr
property: connectionString
- key: RAILS_MASTER_KEY
sync: false
- key: WEB_CONCURRENCY
value: 2 # sensible default
render-build.sh
is added to bin
directory
#!/usr/bin/env bash
# exit on error
set -o errexit
bundle install
./bin/rails assets:precompile
./bin/rails assets:clean
./bin/rails db:migrate
Deployment
Sign in with GitHub
An account is required to access Render services.
I created one using Github.
Create an instance
In the Render Dashboard;
Click on Blueprints
Then click on the New Blueprint instance
Select your repository
Deploy the app
In the deploy window;
Set the value of
RAILS_MASTER_KEY
to the contents ofconfig/master.key
Then click,
Approve
Give the deployment process some time to complete
The deployed app should be accessible via:
https://app_name.onrender.com
Conclusion
What I liked about Render
The ease of connecting easily to GitHub and selecting the target repo
The fact that new changes to the repo are detected and deployment takes place automatically is awesome.
What I didn't like about Render
The official render tutorial for deployment didn't specify that we needed to add
bin/rails db:migrate
to thebin/
render-build.sh
script.They were not clear on how to handle the Postgres database after the trial period other than stating that I had to upgrade.
Sometimes, I forgot to click sync when new changes were pushed to the GitHub repo, resulting in the deployment not happening automatically.
Shout out to Silumesii for the pairing sessions to make this happen and for the idea for this blog post.
Subscribe to my newsletter
Read articles from Ed SSemuwemba directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by