https://github.com/samrocketman/docker-production-ready-flask
This is an example app meant to package a Flask REST API in Docker meant for running in production contexts.
https://github.com/samrocketman/docker-production-ready-flask
Last synced: about 2 months ago
JSON representation
This is an example app meant to package a Flask REST API in Docker meant for running in production contexts.
- Host: GitHub
- URL: https://github.com/samrocketman/docker-production-ready-flask
- Owner: samrocketman
- License: cc0-1.0
- Created: 2022-10-17T03:16:14.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-19T22:06:34.000Z (over 1 year ago)
- Last Synced: 2025-01-06T10:13:21.098Z (3 months ago)
- Language: Makefile
- Size: 14.6 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - samrocketman/docker-production-ready-flask - This is an example app meant to package a Flask REST API in Docker meant for running in production contexts. (Makefile)
README
# Purpose
Create the smallest feasible Docker container for a Python flask app using a
production-ready WSGI server.Follow Python, Flask, and Docker best practices:
- Python
- Flake8 formatted code.
- Organize code into modules.
- Unit tests with pytest.
- Code coverage report generated from unit tests.
- Flask
- Run Flask from a production WSGI server; Apache httpd
- Web server supports HTTP/2.
- Docker
- PID 1 init program to handle process signals and child processes.
- Web server starts in foreground.
- Web server logs to stdout and stderr to be handled by Docker instead of
writing logs to disk.# Running Docker container
The resulting Docker image is `flask`. To build and start web service run the
following.make serve
Open in a web browser:
* http://localhost:8080 to see the JSON API response.
* http://localhost:8080/media/example.txt example assetRun tests with
make test
# ARM image support
The restulting Docker image is `flaskarm`.
Building an arm image from an amd64 machines (in my case Ubuntu) requires some
extra packages to be installed on the host.sudo apt install -y qemu-user-static binfmt-support
Then, you can run the ARM version of the flask app.
make serve-arm
Tests can be run as well.
make test-arm
# Result
Flask app running apache2 runs as a normal user (`apache`) via wsgi. Final
container size is just under 62MB.Complete with unit testing and 100% test coverage.
# License
CC0 or Public Domain