Skip to content

Instantly share code, notes, and snippets.

@heratyian
Last active April 4, 2024 16:52
Show Gist options
  • Save heratyian/706d70d1e5aee64f2dd40ea0664f730e to your computer and use it in GitHub Desktop.
Save heratyian/706d70d1e5aee64f2dd40ea0664f730e to your computer and use it in GitHub Desktop.
deploying-to-render

How to deploy your app on Render

To deploy your app on a live production server allowing anyone with a URL to visit, we will use Render. Make an account at that link before you proceed.

We'll be following the instructions from Render Docs

  1. Create a new blueprint instance

Connect this blueprint instance to your GitHub repository. It's a good idea to only select the 1 repository you'd like to deploy. Then click 'connect' next to the repository you want to deploy.

Free Plan

As a note, free plan databases are deleted after 90 days. If you plan to use your app beyond 90 days, you must upgrade your database to a paid plan.

Create new credentials

We'll need to create a new credentials.yml.enc file. This is an encrypted file used to store things like api keys that you don't want to commit directly to the repository.

delete config/credentials.yml.enc

run EDITOR="code --wait" rails credentials:edit

This will create, decrypt, and open a new credentials.yml.enc file. Close the file. You should see a new config/credentials.yml.enc and config/master.key. Your master.key is like your app password. Never commit this to GitHub.

config

follow the instructions to add:

  1. build script

Create a render-build.sh file in bin/ folder bin/render-build.sh (a build script) It should look something like this.

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

bundle install
bundle exec rake assets:precompile
bundle exec rake assets:clean
bundle exec rake db:migrate

Make sure the script is executable before checking it into Git: chmod a+x bin/render-build.sh

  1. render.yaml

render.yaml (a file to declare all the services required to deploy your app)

It should look something like this. Make sure to set the plan to free and to change YOURAPPNAME to something to identify your app. (all lowercase, no special characters)

databases:
  - name: YOURAPPNAME
    plan: free
    databaseName: YOURAPPNAME
    user: YOURAPPNAME

services:
  - type: web
    name: YOURAPPNAME
    plan: free
    env: ruby
    buildCommand: "./bin/render-build.sh"
    startCommand: "bundle exec puma -C config/puma.rb"
    envVars:
      - key: DATABASE_URL
        fromDatabase:
          name: YOURAPPNAME
          property: connectionString
      - key: RAILS_MASTER_KEY
        sync: false

Deploy

Head over to your new web service on render. Make sure to set the value of the RAILS_MASTER_KEY in envrionmnet variables to the contents of your config/master.key file. Then click save changes.

After you've updated your credentials and added bin/render-build.sh and render.yaml files, make a commit with these changes and push. This will trigger a build. You can now head over to render dashboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment