diff --git a/README.md b/README.md index 9efd5fb3..261a1177 100644 --- a/README.md +++ b/README.md @@ -76,31 +76,7 @@ To authenticate as admin to Keycloak the predefined user is: admin and password: To use a different DNS hostname replace localhost with it in .env and src/config.toml \ This configuration is intended for development, DO NOT use it in production. -Use the following instructions if you prefer to use Docker instead of Docker Compose. - -### Starting a MySQL Server - -We use the default [MySQL Docker image](https://hub.docker.com/_/mysql). -By default, the database is stored within the docker container and will thus be deleted when the container is removed. -Instructions on using a persistent storage can be found at the end of this section. - -First, we define a docker network to allow our server to be reachable from other docker containers: - -```bash -docker network create sql-network -``` - -Then, start the MySQL Server: - -```bash -docker run -e MYSQL_ROOT_PASSWORD=ok --name sqlserver --network sql-network -d mysql -``` - -That's all! You should be able to connect to the server now, though no database is present yet: - -```bash -docker run -it --network sql-network --rm mysql mysql -hsqlserver -uroot -pok -``` +To connect to the database use `./scripts/database-connect.sql`. ```bash mysql> SHOW DATABASES; @@ -115,48 +91,8 @@ mysql> SHOW DATABASES; 4 rows in set (0.03 sec) ``` -For ease of use, you can also make use of the script in `scripts/run_mysql_server.sh`. - -#### Persistent Storage +Now, you can visit the server from your browser at `localhost:8000/docs`. -The data is persistent when simply stopping and restarting the server: - -```bash -docker stop sqlserver -docker start sqlserver -``` - -However, all data is lost when the container is deleted. -To ensure data can persist even if the container is deleted, allow the Docker container to write to a directory on the -host machine. -To do that, mount a volume by adding `-v /ABSOLUTE/PATH/TO/HOST/DIR:/var/lib/mysql` to the docker command that starts -the server -(it's also possible to create a docker -volume ([docs](https://docs.docker.com/engine/reference/commandline/run/#mount-volume--v---read-only))). -If you want to use a path within this repository directory, we recommend naming the directory `data` since then it will -automatically be ignored by git. -For more information, see "Where to Store Data" in the linked documentation. - -### Starting the REST API - -The repository provides a Dockerfile to run the REST API in a containerized environment. - -#### Using the Docker container - -First, build the docker image from the dockerfile: - -```bash -docker build --tag ai4eu_server_demo:latest -f Dockerfile . -``` - -then create a container from that image, remember to forward the port and connect to the right -docker network (alternatively you can use the script at `scripts/run_apiserver.sh`) - -```bash -docker run --network sql-network -it --rm -p 8000:8000 --name apiserver ai4eu_server_demo -``` - -At this point you should be able to visit the server from your browser at `localhost:8000/docs`. #### Local Installation @@ -199,7 +135,7 @@ The `--reload` argument will automatically restart the app if changes are made t 3. Run using DevContainer (see next subsection) ### Authentication -Currently, the code is on default coupled with a keycloak running on test.openml.org. To make +Currently, the code is by default running using the local Keycloak. To make this work, you need to set an environment variable. You can do this by setting the `KEYCLOAK_CLIENT_SECRET` in `src/.env`. @@ -208,9 +144,6 @@ this work, you need to set an environment variable. You can do this by setting t KEYCLOAK_CLIENT_SECRET=[SECRET] ``` -Please ask Jos van der Velde (j.d.v.d.velde@tue.nl) for the keycloak secret, and to give your -user the correct roles. - Alternatively, you can connect to a different keycloak instance by modifying `src/.env`. EGI Checkin can for instance be used on a deployed instance - not on local host. Marco Rorro is the go-to person to request the usage of the EGI Checkin. @@ -255,11 +188,6 @@ You can change this behavior through parameters of the script: Following the installation instructions above, the server may be reached at `127.0.0.1:8000`. REST API documentation is automatically built and can be viewed at `127.0.0.1:8000/docs`. -#### Editing Files Locally - -While developing the server it is often convenient to edit the files on the host machine. -To avoid rebuilding the docker container each time you edit the files, you can mount the host files into the container. -Mount your repository's `src` directory into the container's `/app` directory by adding `-v $(pwd)/src:/app`. #### Automatically Restart on Change diff --git a/src/main.py b/src/main.py index 5b99c699..7f0c6b57 100644 --- a/src/main.py +++ b/src/main.py @@ -94,7 +94,6 @@ def create_app() -> FastAPI: }, ) engine = sqlmodel_engine(args.rebuild_db) - add_delete_triggers(AIoDConcept) with engine.connect() as connection: AIoDConcept.metadata.create_all(connection, checkfirst=True) connection.commit() @@ -104,6 +103,11 @@ def create_app() -> FastAPI: session.add_all([Platform(name=name) for name in PlatformName]) session.commit() + # this is a bit of a hack: instead of checking whether the triggers exist, we check + # whether platforms are already present. If platforms were not present, the db is + # empty, and so the triggers should still be added. + add_delete_triggers(AIoDConcept) + add_routes(app, engine, url_prefix=args.url_prefix) return app