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.
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.
Sign up to Heroku
Login to Heroku in Terminal or iTerm2
Use the following terminal command to login to Heroku in your terminal
You will be prompted for your email address and password you signed up with.
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
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.
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.
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.
In order to get more precise logs use the following switch in your procfile:
*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.