This feels like it doesn't live up to its own hype because it doesn't really exhibit a production-quality deployment of a Python application but something closer to a dev server. It uses a single-threaded flask server behind a nginx reverse proxy without a WSGI layer to handle multiple requests, etc. Here is the nginx code:
server {
listen 80;
server_name: localhost;
location / {
proxy_pass http://fai:4242/;
proxy_set_header Host "localhost";
}
}
According to the docker-compose.yml file, fai:4242 is running a container called "flask": flask:
build:
context: ./
dockerfile: Dockerfile
container_name: flask
networks:
net:
aliases:
- faip
And according to the Dockerfile for the "flask" app.py runs flask built-in (single threaded, recommended for development only) server: if __name__ == '__main__':
APP.run(host='0.0.0.0', port=4242)
There's not much to say about this except that the flask project themselves don't recommend running this server in production[1]. I would recommend a WSGI server such as gunicorn[2] running under supervisord[3]. I would also like to see some logging and error handling in production quality code, and it would make sense to have nginx serve the static files (index.html, index.js, etc.) directly without using up a python thread (which should be reserved for the more dynamic endpoints.) It would be nice to demonstrate using nginx for rat limiting[4] or as a load balancer[5] spreading the work across multiple flask servers.Mind you, I think this is a neat little demo, but as something to put into production - or to teach other people how to put REST APIs into production - it falls short in its current state.
[1]: https://flask.palletsprojects.com/en/1.1.x/tutorial/deploy/
[2]: http://docs.gunicorn.org/en/stable/deploy.html#deploying-gun...