Heroku CLI Deployment of Ruby on Rails APIs powered by PostgreSQL with MacOS

For Girls in Tech COVID-19 hackathon project, my other three teammates and I, decided to create a finding volunteers application for children, called Help@Home, which connects children who need help with their homework and mental health with adult volunteers. I was responsible for implementing a RoR API. To make database accessible for my teammates from all over the world, I chose to deploy it using Heroku.
Before getting into the deploying part, the brief introduction of how the Help@Home backend was designed is needed. It was created with Ruby on Rails powered by PostgreSQL using self referential relationship (for more information about self referential association check out my blog here), one table for users (client & volunteer) and one join table for appointments, from which the client and the volunteer are connected. For security management, JWT, Bcrypt and dotenv are applied.
Now let’s talk about how to deploy.
- A free Heroku account (https://signup.heroku.com/dc)
- MacOS homebrew installation in command shell
( https://devcenter.heroku.com/articles/getting-started-with-ruby#set-up)
brew install heroku/brew/heroku
3. Once installed, we can use Heroku CLI to login to our account
heroku login
4. Open the api backend folder and create Heroku repository
heroku create
5. Create Procfile, which is needed for setting up the environment for Heroku (Procfile should be in the main folder, in the same folder with Gemfile)
touch Procfile
6. Paste the following line into Procfile
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
7. Now we need to commit and push the changes to the repository
git add .
git commit -m "init"
git push heroku master
At this point, Heroku starts deploying the app.
8. Add token signing key/value pair in ‘.env’ file into Heroku app → settings → Config Vars


9. Run the migration
heroku run rake db:migrate
10. Now open the url to check it out (the app might take a few minutes to open. )
Ta-da! 🤩

I hope this will help you! ;)
References: