Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify Procfile to run Gunicorn process in a non-standard folder on Heroku?

I'm new to heroku and gunicorn so I'm not sure how this works. But I've done some searching and I think I'm close to deploying my Django app (1.5.1). So I know I need a Procfile which has

web: gunicorn app.wsgi 

Because my directories are a bit different. I can't run gunicorn in the root directory

app_project     requirements/     contributors/     app/         app/             settings/             wsgi.py         # Normally Procfile goes here     Procfile 

Normally app/ would be the root directory, but I decided to structure my folders this way to separate my django app from some other things. Since I have to put the Procfile in the root directory for heroku to recognize it, what should I put in the Procfile and/or what parameters should I place in the gunicorn command?

Note:

web: gunicorn app.wsgi # won't work because Procfile is in a directory above                        # I also want to keep the directories as is                        # I also don't want to create a secondary git inside the app folder just for heroku web: gunicorn app.app.wsgi # won't work because I don't want to convert the folder into a python module 
like image 470
Derek Avatar asked May 07 '13 09:05

Derek


People also ask

Where do I put Procfile?

The Procfile is always a simple text file that is named Procfile without a file extension. For example, Procfile. txt is not valid. The Procfile must live in your app's root directory.

What is Procfile Gunicorn?

This file is used to explicitly declare your application's process types and entry points. It is located in the root of your repository. Procfile web: gunicorn myproject.wsgi. This Procfile requires Gunicorn, the production web server that we recommend for Django applications.

What type of file is Procfile?

A Procfile is a text file named Procfile placed in the root of your application that lists the process types in an application. Each process type is a declaration of a command that is executed when a container of that process type is started.

Do you need Gunicorn for Heroku?

Heroku is an excellent Platform As A Service (PAAS) provider that will host any Python HTTP application, and recommends using Gunicorn to power your apps. Unfortunately, the process model of Gunicorn makes it unsuitable for running production Python sites on Heroku.


2 Answers

Try:

web: gunicorn --pythonpath app app.wsgi 
like image 81
Graham Dumpleton Avatar answered Oct 03 '22 01:10

Graham Dumpleton


As @Graham Dumpleton stated in his answer, the OP's problem could be solved by modifying his Procfile to the following:

web: gunicorn --pythonpath app app.wsgi

Why this works:

  • Remember, that the Procfile is simply used by Heroku to start processes. In this case, gunicorn processes.
  • Gunicorn's --pythonpath argument allows you to dynamically attach a directory to the list of directories that the Python runtime searches for when do module look-ups.
  • By adding --pythonpath app to the gunicorn command, the interpreter was basically told 'look inside of the app directory for a package (also) called app which contains a module called wsgi.`

The generic names of the folders in the OP's question can obscure the syntax of the command, which is as follows: gunicorn --pythonpath <directory_containing_package> <package>.<module>

More Info:
Gunicorn Documentation

like image 39
eikonomega Avatar answered Oct 03 '22 01:10

eikonomega