Skip to content

Latest commit

 

History

History
114 lines (78 loc) · 3.26 KB

README.md

File metadata and controls

114 lines (78 loc) · 3.26 KB

DCFS Metadata Service

Docker release GitHub workflow Codacy coverage Codacy grade Dependabot Badge License

The Metadata Service provides API for retrieving JSON metadata of GUIDs.

The server is built with FastAPI and packaged with Poetry.

View API Documentation

Installation

Install required software:

Then use poetry install to install the dependencies. Before that, a virtualenv is recommended. If you don't manage your own, Poetry will create one for you during poetry install, and you must activate it by:

poetry shell

Development

Create a file .env in the root directory of the checkout: (uncomment to override the default)

# DB_HOST = "..."     # default: localhost
# DB_PORT = ...       # default: 5432
# DB_USER = "..."     # default: current user
# DB_PASSWORD = "..." # default: empty
# DB_DATABASE = "..." # default: current user

Run database schema migration:

alembic upgrade head

Run the server with auto-reloading:

python run.py

Try out the API at: http://localhost:8000/docs.

Run tests

pytest --cov=src --cov=migrations/versions tests

Please note that, the name of the test database is prepended with "test_", you need to create that database too.

Develop with Docker

Use Docker compose:

docker-compose up

Run database schema migration as well:

docker-compose exec mds poetry run alembic upgrade head

Create test database:

docker-compose exec db createdb -U mds test_mds

Run tests:

docker-compose exec mds poetry run pytest --cov=src --cov=migrations/versions tests

Deployment

For production, use gunicorn:

gunicorn mds.asgi:app -k uvicorn.workers.UvicornWorker -c gunicorn.conf.py

Or use the Docker image built from the Dockerfile, using environment variables with the same name to configure the server.

Other than database configuration, please also set:

DEBUG=0
ADMIN_LOGINS=alice:123,bob:456

Except that, don't use 123 or 456 as the password.