Skip to content

Add admin task

Mizzi van der Ven requested to merge 93-be-create-admin-task-for-opmet-be into main

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 option enable_alembic was added
  • A script admin.sh was added that calls the enable_alembic command, followed by an alembic upgrade head command
  • In the Dockerfile two copy statements are added to include the admin.sh and cli.py files
  • In the docker compose files docker-compose.yml, docker-compose-tests.yml and docker-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 the admin.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

  1. Explicitly run admin.sh
  2. 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:
    1. Start database
    2. Set .env file correctly
    3. Run admin.sh
    4. Start application with uvicorn
  • Option 2:
    1. Make sure the the .env file is set correctly
    2. 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

Merge request reports