Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku Gunicorn Procfile

I have a hard time finding documentation for creating Procfiles using flask with gunicorn and Heroku. Somewhere I found that the syntax is: web: gunicorn my_folder.my_module:app. But I can't make it work. It only works for me when my python script: hello.py is in the root folder of the app. When I put it in a subfolder called app and create a Procfile: web: gunicorn app.hello:app it doesn't work. Only when I use web: gunicorn hello:app and my python script is in the root folder. Can someone explain me the proper syntax of Procfiles for gunicorn on Heroku, and how to make it work when the python script is in a subfolder?

like image 440
CasperTN Avatar asked Aug 09 '16 13:08

CasperTN


People also ask

What is Heroku Procfile?

Heroku apps include a Procfile that specifies the commands that are executed by the app on startup. You can use a Procfile to declare a variety of process types, including: Your app's web server. Multiple types of worker processes. A singleton process, such as a clock.

Does Heroku need Gunicorn?

First, and most importantly, Heroku web applications require a Procfile . This file is used to explicitly declare your application's process types and entry points. It is located in the root of your repository. This Procfile requires Gunicorn, the production web server that we recommend for Django applications.

What is Gunicorn in Heroku?

Gunicorn is a pure-Python HTTP server for WSGI applications. It allows you to run any Python application concurrently by running multiple Python processes within a single dyno. It provides a perfect balance of performance, flexibility, and configuration simplicity.


1 Answers

Gunicorn takes a flag, --chdir, that lets you select which directory your Python app lives in. So, if you have a directory structure like:

my-project/
  Procfile
  my_folder/
    my_module.py

and my_module.py contains:

app = Flask(__name__, ...)

You can put the following in your Procfile:

web: gunicorn --chdir my_folder my_module:app
like image 62
kristina Avatar answered Oct 04 '22 09:10

kristina