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
- 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.
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.
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.
follow the instructions to add:
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
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
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