Heroku: How to Publish an Existing Rails App
With Rails 5, the deployment process to Heroku has gotten even easier. Here are the steps to publishing a new Heroku app without using a one-click install.
STEP 1 - Create Rails App
Make sure you have a Rails 5 app that uses a postgresql database.
rails _5.0.0_ new my_api_app --api -d postgresql
Change directory into your app.
cd my_api_app
STEP 2 - Heroku Login
Make sure you've downloaded the Heroku Client (Toolbelt)
Login into Heroku.
heroku login
STEP 3 - Create App
Create a Heroku app from the existing rails app.
heroku create
STEP 4 - Double Check Your Work
Double check if everything is OK. If nothing fails, you're good.
git config --list | grep heroku
STEP 5 - Publish to Heroku
Add all the files and create a message.
git add -A && git commit -m 'initial import'
Publish to Heroku
git push heroku master
STEP 6 - Update Heroku DB
Update the database schema. Notice that we use rake
because we're using Rails 4.2.6.
heroku run rake db:migrate
STEP 7 - Populate Heroku DB
Populate the Heroku Database with seed data.
heroku run rake db:seed
STEP 8 - Double Check Your Server
Review your web app and determine if it's running.
heroku ps:scale web=1
STEP 9 - Double Check Your Heroku Process
Check the state of your Heroku process.
heroku ps
STEP 10 - Review your Heroku Configuration
Heroku config will show you a list of environmental variables and configurations for your specific app.
heroku config
STEP 11 - View Your Web App
View your web app live.
heroku open
STEP 12 - Review Logs
It's helpful to review your logs and see how things are looking. This command will collect the last 10,000 logs and save it to a .log
file.
heroku logs -n 10000 > ~/Desktop/heroku-logs.log
Get the real-time logs and use grep
to only showme
heroku logs -t | grep keyword_string_etc
Rename Heroku App
By default, Heroku will randomly assign you an app name. Here's how to give it a name you prefer.
heroku apps:rename new_app_name
Managing Environmental Variables
You can create, edit and delete Environmental Variables using Heroku Command Line.
heroku config:set VAR_IN_UPPERCASE=value
Managing Multiple Accounts
If you part of an web studio or agency where you manage multiple Heroku accounts, I highly suggest you read more about Heroku Accounts Plugin.