Add admin task
Closes #93 (closed)
In this MR
To ease automatic (re-)deployments, at KNMI it is preferred to use an admin script and/or admin container. The admin script should only run if it is explicitly called. In this MR the following changes are proposed:
- In
cli.py
a command optionenable_alembic
was added - A script
admin.sh
was added that calls theenable_alembic
command, followed by analembic upgrade head
command - In the
Dockerfile
two copy statements are added to include theadmin.sh
andcli.py
files - In the docker compose files
docker-compose.yml
,docker-compose-tests.yml
anddocker-compose-dev.yml
a health-check for the db service was added. The admin task will make sure to await a good health check and then run. - Finally, a new docker compose file for the admin task was created:
docker-compose-admin.yml
. In this file, an admin service can be set up, depending on a healthy status of the db-service and used the .env file. The entrypoint is theadmin.sh
script that will be run. - The readme was updated to show how the admin job can be used
You can now explicitly add the admin task in two ways
- Explicitly run
admin.sh
- Use it with docker compose, for example:
# For "production-like" deployment
docker compose -f docker-compose.yml -f docker-compose-admin.yml up -d --build
# For dev deployment
docker compose -f docker-compose-dev.yml -f docker-compose-admin.yml up -d --build
How to test
- Start the application by using the admin task explicitly
- Option 1:
- Start database
- Set .env file correctly
- Run
admin.sh
- Start application with uvicorn
- Option 2:
- Make sure the the .env file is set correctly
- Docker compose command:
docker compose -f docker-compose-dev.yml -f docker-compose-admin.yml up -d --build
- After starting the application, make sure database interactions have remained the same, no changed fucntionality
Edited by Mizzi van der Ven