Helloworld stack prod : Sandbox for a pseudo production stack
The idea of this repo is to :
- try, train on new softwares,
- practice on Docker/k8s,
- apply best practices.
The final goal is to be the closest possible of what would be a complete production stack, meaning that you'll have :
- A REST api with an HTTP server,
- A monitored SQL database,
- A reverse proxy handling HTTPS,
- Some api monitoring,
- An authentication service.
Obviously you should have proper testing and deployment on a VPS via CI/CD.
Right now the four first points are implemented in an early stage. We have selected :
- A Python REST api made with FastAPI and Gunicorn as an htttp server.
- PostgreSQL as a SQL database and pgadmin to monitor it.
- Traefik as reverse proxy,
- Uptime Kuma as simple uptime monitoring.
Roadmap
- Test Caddy as reverse proxy.
- Rework of the api backend and use the Web-Queue-Worker architecture.
- Implement IAM with Fief or Keycloak (try both).
- ELK Stack for monitoring, or Jaeger.
- Prometheus + Grafana ?
Requirements :
Whether you work locally in "dev mode", or that this stack is deployed on a VPS, you'll need Docker and docker compose.
Docker
Docker-compose
-
You might also need
haveged
, install it viaapt install haveged
. This is supposed to add more randomness to the VPS for docker-compose to start. TODO : check this more in detail.
VPS
If you want to deploy this stack on a vps, you'll need to rent it, you can rent one for example on DigitalOcean, for around 5 euros/month.
Remark
If you have an old laptop, why not turn it into you own little Ubuntu Server and try deployement on it rtather than a vps ?
Environement variables needed to be set
Traefik Dashboard :
USERNAME
HASHED_PASSWORD
PostgreSQl + FastaPI connection to DB :
DB_USERNAME
DB_PASSWORD
PgAdmin db monitoring :
PGADMIN_DEFAULT_EMAIL
HASHED_PGADMIN_DEFAULT_EMAIL
Sources
Here are some sources that might be useful.
- FastAPI Best Practices
- Deploying FastAPI Apps Over HTTPS with Traefik Proxy
- An Extremely Simple Docker, Traefik, and Python FastAPI Example
- Dockerizing FastAPI with Postgres, Uvicorn, and Traefik
- Tiangolo official fastapi docker image
- How to install Traefik 2.x on a Docker Swarm
- Deploying FastAPI (and other) apps with HTTPS powered by Traefik
- Deploying a FastAPI app with Docker, Traefik, and Let's Encrypt
Control startup and shutdown order in Compose
- https://docs.docker.com/compose/startup-order/
- https://github.com/jasonsychau/RelayAndContainers
- https://github.com/vishnubob/wait-for-it
- https://github.com/Eficode/wait-for