A Flask based Python Backend service for the "Umbrella structured" Project and Docker training materials.
On MacOS its required the installation of brew install postgresql@14 to being able to
compile postgresql dependencies and build the docker image.
Also Docker and Docker-Compose are required in order to run the service with the provided Docker compose definition file.
Finally a Pipenv and a Python Version 3.11 must be available to run the provided tool scripts. (Alternatively they can be run from inside the service container)
For an easy deployment a docker-compose.yaml Docker-Compose definition file is
provided, this compose file includes both the implemented service and a PostgreSQL
database server.
For the database access the relevant environment variables are already fixed on the compose file.
The following Docker and Docker-Compose commands will be used to activate and deactivate the service.
-
To deploy the full infrastructure and launch the services just run: (This will also build, if required, the backend service)
docker-compose up -d --build
-
To attach to the
backendservice logs just run:docker logs -f Training_Backend
-
To stop and remove the infrastructure just run:
docker-compose down
The backend server will be accesible through localhost:15345.
The database server will be accesible through localhost:31457.
After the first launch of the composed infrastructure the database server will be running but there will be no database created for the backend service.
In order to create it, its tables, the service user and required grants a convenience
set of scripts is provided at /tools folder:
The scripts must be run inside the virtual env and from the project's root folder.
The available tools are:
-
tools/db_create.sh: This is an stand alone script which will create the required database, user and provide the required grants.It will read the required data from the environment variables, easiest way to provide is to use the
template.envfile by renaming it to.envand let pipenv to load them automatically (Default behaviour)The given
template.envcomes with the same credentials as thedocker-compose.yaml -
tools/db_build.sh: Create all database tables. It depends on the service database models definitions. -
tools/db_drop.sh: Drops all database tables, the database itself is not removed. It depends on the service database models definitions. -
tools/db_prune.sh: Remove all data but keeps database structure. It depends on the service database models definitions.
So in order to create the required structure and credentials the following commands must be run after the first boot up of the infrastructure:
tools/db_create.sh
tools/db_build.sh-
ROOT:
/This endpoint just returns a text with a 200 status code.
-
HEALTH_CHECK:
/healthThis endpoint returns a health check response based on own service and database availability.
Response format based on the IETF draft (WIP): https://datatracker.ietf.org/doc/html/draft-inadarei-api-health-check