DEV Community

loading...
Cover image for Deploy Flask app on Heroku with Github

Deploy Flask app on Heroku with Github

Ludovic Taffin
I'm just a webdev
・2 min read

Hello guys,

Heroku is an awesome resource if you want to set up a web app.
I recently needed it for a personal project and here is some simple step i had to follow to set up this correctly.

All starts with an awesome GitHub project

Let's imagine you have develop and awesome flask app in a private GitHub repository:

Some GitHub repository

My code is sooo complicated (run.py) :

My awesome code

And the result is awesome:

Hello, World!

This result is incredible and i have to share the result with the world to let anyone use this!
I'll then deploy it first on a free resource to see my result online.

Deploy on Heroku.

For this i'll use Heroku! After creating an account, i'll create my first app.
I set up a name and a region and then discover my dashboard.
You can see and configure a lot of things but we will focus on deploy tab.
I will first select GitHub for deployment method.
After a connection to GitHub profile, you can select the repository (public or private) to deploy by entering the name.

I can now define an automatic or manual deploy. I'll go for a manual, as I didn't set CI. I just have to select the branch and hit deploy.

Spoiler, as it is, the deployment will fail.
Heroku needs some extra information to make this awesome project work.

Some extra needs

First, a list of requirements for the project. Those are listed in my requirements.txt. For my tiny project i only need:

flask
jinja2
gunicorn
Enter fullscreen mode Exit fullscreen mode

Then, a runtime definition (defined in runtime.txt). Here are supported version of Python in Heroku :
Here

So i defined my runtime simply as follow

python-3.9.4

Finally, Heroku web applications require a Procfile. This file is used to explicitly declare application’s process types and entry points. It is located in the root of the repository.

web: gunicorn wsgi:app

(related to my wsgi.py file)

This Procfile requires Gunicorn, the production web server. That's why I set Gunicorn in my requirements file.

We can now deploy the wonderful app and enjoy it at the dedicated URL provide by Heroku.

My repositroy is available here

Discussion (0)