|
| 1 | +# Hosting the Metadata Catalogue |
| 2 | +This page has information on how to host your own metadata catalogue. |
| 3 | +If you plan to locally develop the REST API, please follow the installation procedure in ["Contributing"](../contributing) instead. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | +The platform is tested on Linux, but should also work on Windows and MacOS. |
| 7 | +Additionally, it needs [Docker](https://docs.docker.com/get-docker/) and |
| 8 | +[Docker Compose](https://docs.docker.com/compose/install/) (version 2.21.0 or higher). |
| 9 | + |
| 10 | +## Installation |
| 11 | +Starting the metadata catalogue is as simple as spinning up the docker containers through docker compose. |
| 12 | +This means that other than the prerequisites, no installation steps are necessary. |
| 13 | +However, we do need to fetch files the latest release of the repository: |
| 14 | + |
| 15 | +=== "CLI (git)" |
| 16 | + ```commandline |
| 17 | + git clone https://github.com/aiondemand/AIOD-rest-api.git |
| 18 | + ``` |
| 19 | + |
| 20 | +=== "UI (browser)" |
| 21 | + |
| 22 | + * Navigate to the project page [aiondemand/AIOD-rest-api](https://github.com/aiondemand/AIOD-rest-api). |
| 23 | + * Click the green `<> Code` button and download the `ZIP` file. |
| 24 | + * Find the downloaded file on disk, and extract the content. |
| 25 | + |
| 26 | +## Starting the Metadata Catalogue |
| 27 | +From the root of the project directory (i.e., the directory with the `docker-compose.yaml` file), run: |
| 28 | + |
| 29 | +=== "Shorthand" |
| 30 | + We provide the following script as a convenience. |
| 31 | + This is especially useful when running with a non-default or development configuration, |
| 32 | + more on that later. |
| 33 | + ```commandline |
| 34 | + ./scripts/up.sh |
| 35 | + ``` |
| 36 | +=== "Docker Compose" |
| 37 | + ```commandline |
| 38 | + docker compose up -d |
| 39 | + ``` |
| 40 | + |
| 41 | +This will start a number of services running within one docker network: |
| 42 | + |
| 43 | + * Database: a [MySQL](https://dev.mysql.com) database that contains the metadata. |
| 44 | + * Keycloak: an authentication service, provides login functionality. |
| 45 | + * Metadata Catalogue REST API: |
| 46 | + * Elastic Search: indexes metadata catalogue data for faster keyword searches. |
| 47 | + * Logstash: Loads data into Elastic Search. |
| 48 | + * Deletion: Takes care of cleaning up deleted data. |
| 49 | + * nginx: Redirects network traffic within the docker network. |
| 50 | + * es_logstash_setup: Generates scripts for Logstash and creates Elastic Search indices. |
| 51 | + |
| 52 | +[//]: # (TODO: Make list items link to dedicated pages.) |
| 53 | +These services are described in more detail in their dedicated pages. |
| 54 | +After the previous command was executed successfully, you can navigate to [localhost](http://localhost.com) |
| 55 | +and see the REST API documentation. This should look similar to the [api.aiod.eu](https://api.aiod.eu) page, |
| 56 | +but is connected to your local database and services. |
| 57 | + |
| 58 | +### Starting Connector Services |
| 59 | +To start connector services that automatically index data from external platforms into the metadata catalogue, |
| 60 | +you must specify their docker-compose profiles (as defined in the `docker-compose.yaml` file). |
| 61 | +For example, you can use the following commands when starting the connectors for OpenML and Zenodo. |
| 62 | + |
| 63 | +=== "Shorthand" |
| 64 | + ```commandline |
| 65 | + ./scripts/up.sh openml zenodo-datasets |
| 66 | + ``` |
| 67 | +=== "Docker Compose" |
| 68 | + ```commandline |
| 69 | + docker compose --profile openml --profile zenodo-datasets up -d |
| 70 | + ``` |
| 71 | + |
| 72 | +The full list of connector profiles are: |
| 73 | + |
| 74 | +- openml: indexes datasets and models from OpenML. |
| 75 | +- zenodo-datasets: indexes datasets from Zenodo. |
| 76 | +- huggingface-datasets: indexes datasets from Hugging Face. |
| 77 | +- examples: fills the database with some example data. Do not use in production. |
| 78 | + |
| 79 | +[//]: # (TODO: Link to docs or consolidate in dedicated page.) |
| 80 | + |
| 81 | +## Configuration |
| 82 | +There are two main places to configure the metadata catalogue services: |
| 83 | +environment variables configured in `.env` files, and REST API configuration in a `.toml` file. |
| 84 | +The default files are `./.env` and `./src/config.default.toml` shown below. |
| 85 | + |
| 86 | +If you want to use non-default values, we strongly encourage you not to overwrite the contents of these files. |
| 87 | +Instead, you can create `./override.env` and `./config.override.toml` files to override those files. |
| 88 | +When using the `./scripts/up.sh` script to launch your services, these overrides are automatically taken into account. |
| 89 | + |
| 90 | +=== "`./src/config/default.toml`" |
| 91 | + ```toml |
| 92 | + --8<-- "./src/config.default.toml" |
| 93 | + ``` |
| 94 | + |
| 95 | +=== "`./.env`" |
| 96 | + ```.env |
| 97 | + --8<-- ".env" |
| 98 | + ``` |
| 99 | + |
| 100 | +Overwriting these files directly will likely complicate updating to newer releases due to merge conflicts. |
| 101 | + |
| 102 | +## Updating to New Releases |
| 103 | + |
| 104 | +[//]: # (TODO: Publish to docker hub and have the default docker-compose.yaml pull from docker hub instead.) |
| 105 | + |
| 106 | +First, stop running services: |
| 107 | +```commandline |
| 108 | +./scripts/down.sh |
| 109 | +``` |
| 110 | +Then get the new release: |
| 111 | +```commandline |
| 112 | +git fetch origin |
| 113 | +git checkout vX.Y.Z |
| 114 | +``` |
| 115 | +A new release might come with a database migration. |
| 116 | +If that is the case, follow the instructions in ["Database Schema Migration"](#database-schema-migration) below. |
| 117 | +The database schema migration must be performed before resuming operations. |
| 118 | + |
| 119 | +Then run the startup commands again (either `up.sh` or `docker compose`). |
| 120 | + |
| 121 | +### Database Schema Migration |
| 122 | + |
| 123 | +We use [Alembic](https://alembic.sqlalchemy.org/en/latest/tutorial.html#running-our-first-migration) to automate database schema migrations |
| 124 | +(e.g., adding a table, altering a column, and so on). |
| 125 | +Please refer to the Alembic documentation for more information. |
| 126 | +Commands below assume that the root directory of the project is your current working directory. |
| 127 | + |
| 128 | +!!! warning |
| 129 | + |
| 130 | + Database migrations may be irreversible. Always make sure there is a backup of the old database. |
| 131 | + |
| 132 | +Build the database schema migration docker image with: |
| 133 | +```commandline |
| 134 | +docker build -f alembic/Dockerfile . -t aiod-migration |
| 135 | +``` |
| 136 | + |
| 137 | +With the sqlserver container running, you can migrate to the latest schema with |
| 138 | + |
| 139 | +```commandline |
| 140 | +docker run -v $(pwd)/alembic:/alembic:ro -v $(pwd)/src:/app -it --network aiod-rest-api_default aiod-migration |
| 141 | +``` |
| 142 | + |
| 143 | +since the default entrypoint of the container specifies to upgrade the database to the latest schema. |
| 144 | + |
| 145 | +Make sure that the specified `--network` is the docker network that has the `sqlserver` container. |
| 146 | +The alembic directory is mounted to ensure the latest migrations are available, |
| 147 | +the src directory is mounted so the migration scripts can use defined classes and variable from the project. |
| 148 | + |
| 149 | +[//]: # (TODO: Write documentation for when some of the migrations are not applicable. E.g., when a database was created in a new release.) |
0 commit comments