How to deploy a Rails 7 app to Render

Ed SSemuwembaEd SSemuwemba
2 min read

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;

  1. render.yaml

  2. 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;

  1. Click on Blueprints

  2. Then click on the New Blueprint instance

  3. Select your repository

Deploy the app

In the deploy window;

  1. Set the value of RAILS_MASTER_KEY to the contents of config/master.key

  2. Then click, Approve

  3. Give the deployment process some time to complete

  4. The deployed app should be accessible via: https://app_name.onrender.com

Conclusion

What I liked about Render

  1. The ease of connecting easily to GitHub and selecting the target repo

  2. The fact that new changes to the repo are detected and deployment takes place automatically is awesome.

What I didn't like about Render

  1. The official render tutorial for deployment didn't specify that we needed to add bin/rails db:migrate to the bin/render-build.sh script.

  2. They were not clear on how to handle the Postgres database after the trial period other than stating that I had to upgrade.

  3. 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.

0
Subscribe to my newsletter

Read articles from Ed SSemuwemba directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ed SSemuwemba
Ed SSemuwemba