Deploy Flask App to Heroku Beginner Mind Overview

WorkFlow

I was happy with the local version of my Portfolio app so now it was time to push it to Heroku. Heroku is a platform that allows you to push your web app online. My portfolio app is small so I am currently using the free version of Heroku. Even though the process of building your web app on Heroku is relatively straight forward, I did run into a few issues that took a while to surmount. In this post I am writing a brief overview of the process.

Step 1

Offline Flask App Ready

Flask app already built offline. You will view your offline app via a URL similar to http://127.0.0.1:5000/ which is the local host IP address on your laptop.

Step 2

Sign up to Heroku

Go to Heroku and create an account. I am using the CLI (Command Line Interface) to deploy to Heroku. You can go here to install the Heroku CLI Toolbelt using Homebrew.

Step 3

Login to Heroku in Terminal or iTerm2

Use the following terminal command to login to Heroku in your terminal

heroku login

You will be prompted for your email address and password you signed up with.

Step 4

Deploy to Github

At this point I would advise you to deploy your app to Github.

git add .

git commit -m "your message here"

git push origin master

Step 5

Procfile & Requirements.txt

In order for the app to build on Heroku you will need a procfile and a requirements.txt file. The procfile will tell Heroku what file to execute in order to run the app. The procfile isn't saved with an extension and will look something like this:

 

The requirements.txt file tells Heroku what *dependencies it will need to install in order to run the app. You can create a requirements file in terminal. First cd into the folder that contains the app. Then you can run the following command:

pip freeze > requirements.txt

This will not only create a list of app dependencies but also create a txt file for you automatically.

Step 6

Build Logs

A very useful feature of Heroku are the logs that it shows you. The logs will help you to identify errors in the build or updating process.

 

Step 7

App Online

The most rewarding part of this process is that after all the obstacles and failed build attempts, pressing forward in the midst of uncertainty finally allowed me to get the app online, which was my primary objective. I now can move onto online issues with my Flask Portfolio.

My Portfolio

 

Useful tip:

In order to get more precise logs use the following switch in your procfile:

--preload

 

*A dependency is something that the app relies on the run, e.g. Flask depends on Jinja 2 being installed in order to run. Heroku will look to the requirements.txt file in order to find the dependencies from your local version of the app in order for it to run online with Heroku.

 

Did you find this blog post useful? Is there something you don't understand or something I am omitting?  If so I would love to hear from you in the comments section below or by dropping me an e-mail.