This project implements a REST API webservice using PostgreSQL and Flask.
It is running in 2 containers: one for the application and one for the database.
The application is configured to run on a local machine, using .env file to store the secrets.
While this is not the safest way to store credentials, this project is for demonstration only.
In production, please make sure to store your secrets in encrypted format in a safe place.
- Create a
.envfile and specify all the environment variables listed in.env.example - Install requirements
pip3 install -r requirements.txt
- Create the containers
docker-compose up
- Since this is the first time the database is created, we need to apply migrations:
alembic upgrade head- more about migrations in
alembic/README.md
- We have a webservice running at
localhost:8080
For the testing we use a different database. Before running the tests, we must create the test database:
docker-compose -f docker-compose-test.yaml up
This time we don't have to do any migrations, there's a pytest fixture which takes care about this. Now the tests are ready to run.
- create a single-node k8s cluster with minikube
- deploy postgres config
- deploy postgres secrets
- deploy postgres
- deploy app config
- deploy app
- get the URL of the app
- all of these steps are listed in the
Makefile - the database uses a different volume inside the cluster
- this deployment is very simple
- only 1 replica for the app deployment
- postgres is also a 1 replica deployment instead of a stateful set