This contains instructions on deploying and maintaining Boilerplate on Heroku.
flowchart LR
subgraph backend ["Backend (Heroku)"]
bundle[[React Bundle]]
api([Rails API]) --> db[(PostgreSQL)]
nginx([NGINX Server])
nginx --> bundle
nginx --> api
end
browser[Browser]
browser --> nginx
When deployed, the application consists of three servers:
- A Rails server for API requests (through Ruby buildpack)
- A PostgreSQL database server (through Heroku Postgres Addon)
- An NGINX static web server to serve the built react bundle and also act as a reverse proxy for API requests (through NGINX buildpack)
There are two versions of the application: staging and production.
- When commits are pushed to the
develop
branch, they are immediately built and released to the staging environment - After testing is complete, changes are promoted from staging into the production environment through Heroku's pipeline feature
TODO
To deploy Boilerplate on Heroku, follow these steps:
- Create an app for the API and Frontend on Heroku
- Configure API
- Add the Heroku PostgreSQL addon
- Add the following environment vars to the app:
FRONTEND_ORIGIN="frontend-app-name.herokuapp.com" SECRET_KEY_BASE="generate using bundle exec rake secret" DATABASE_URL="should be auto populated after installing Heroku PostgreSQL addon" ACTION_MAILER_GMAIL_ACCOUNT="[email protected]" ACTION_MAILER_GMAIL_PASSWORD="gmail app password"
- Inside the API directory, configure the remote and deploy:
$ heroku git:remote -a <api-app-name> $ git push heroku develop:main
- Optional: To populate the app with test data, run the following command.
# NOTE: This will clear out all records in the database! # NOTE: This command will output the credentials for the test account(s). $ heroku run -a <api-app-name> rails db:seed
- Configure Frontend
- Add the following environment vars to the app:
VITE_API_URL=https://api-app-name.herokuapp.com
- Add the following buildpacks:
$ heroku buildpacks:add -a <frontend-app-name> heroku/nodejs $ heroku buildpacks:add -a <frontend-app-name> heroku-community/nginx
- Inside the Frontend directory, configure the remote and deploy:
$ heroku git:remote -a <frontend-app-name> $ git push heroku develop:main
- Add the following environment vars to the app:
Migrations are automatically run before backend changes are released for both staging and production so you don't need to worry about manually running them!