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 ?
How run a flask app packaged as pex in gunicorn?
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.
@alwaysprep could you provide an example? –
Via
@Via Do you use pants for build process? If so go to dist file where .pex file resides. and write: "PEX_SCRIPT=gunicorn ./{pex_file_name}.pex {path_to_your_app}:app" You need to add gunicorn to your 3rdparty. –
Inaccuracy
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
© 2022 - 2024 — McMap. All rights reserved.