Foreman and Procfile tips&tricks

Lately I’ve been playing around with the Heroku stack and I’d like to share little tricks that might be common knowledge but which I’ve not seen mentioned on the Heroku standard documentation.

So the doc tells you you must set your Procfile as such (for a Python app):

web: gunicorn app:app -b 0.0.0.0:$PORT -w 3

You can then run the webserver on your machine for development with the command:

foreman start

But if your app also uses memcached, redis, postgres or others, then you must open as many additional tabs in your terminal to run each service (I don’t want to have the daemons running all the time on my all-purpose macbook air).

What you can do to make your life easier is to create a new file Procfile.dev which you should add to .gitignore (so that it is not uploaded to Heroku and does not affect your production environment) and add all those services in there:

web: python app.py
memcached: memcached -v
coffee: coffee --watch --output static/js/ --compile lib/

And run it with:

foreman start -f Procfile.dev

This will launch my app with standard Python (easier for quick debugging than gunicorn), my memcached instance and even compile my CoffeeScript on the fly so I can edit freely while testing my changes.

Looking in your terminal you’ll even see each service logs all pretty and color coded.

Leave a Reply

Your email address will not be published.