Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How run a flask app packaged as pex in gunicorn?

I am planning to package my flask app as a pex for self contained distribution, wondering how can I run the pex in Gunicorn ? or maybe packaging even gunicorn in the executable so when I run the pex, flask app runs in gunicorn . is that even possible ?

like image 529
user2616355 Avatar asked Nov 06 '18 20:11

user2616355


2 Answers

I assembled an example app showing how to package a Flask application with Pex and run the resulting pex-file with Gunicorn, see here: https://github.com/wolkenarchitekt/pex-flask-gunicorn-example

These are the essential commands to package and run the app:

python setup.py sdist
pex -vv -r requirements.txt -D . -o ./hello-service.pex
PEX_SCRIPT=gunicorn ./hello-service.pex hello_service.main:app -b :8000

As you can see, Gunicorn is even packaged within the pex-file.

like image 189
Wolkenarchitekt Avatar answered Sep 22 '22 22:09

Wolkenarchitekt


Just an update about @ifischer answer, the (recently introduced) -c aim to put a script as an entry point for pex

pip3 wheel -w . .
pex --python=python3 -r requirements.txt -f . -o hello-service.pex -c gunicorn
./hello-service.pex hello_service.main:app -b :8000
like image 41
Jérôme B Avatar answered Sep 26 '22 22:09

Jérôme B