RAIL Backend serves as a backend application for RAIL service. This backend consists of a REST API service (FastAPI) and a non-relational database (MongoDB).
- Create
.envfile containing relevant ENV variables required for the service defined in.env.sample.- Mongo setup:
MONGODB_DBNAME: Name of the database
- Connection to other AIoD services:
AIOD_API__BASE_URL: URL of the running AIoD API (Metadata Catalogue)AIOD_LIBRARY_API__BASE_URL: URL of the running AIoD MyLibraryAIOD_ENHANCED_SEARCH_API__BASE_URL: URL of the running AIoD Enhanced Interaction
- AIoD Keycloack authentication service:
AIOD_KEYCLOAK__*: Env variables related to authentication using Keycloak
- REANA setup:
REANA_SERVER_URL: Define the URL used for connecting to REANA serverREANA_ACCESS_TOKEN: Define the access token used for connecting to REANA server
- Docker registry setup (create your own Docker registry where you store images to):
DOCKER_REGISTRY_URL: Define a path to a repository that we want to use for storing docker images of individual ExperimentTemplatesDOCKER_REGISTRY_USERNAME: Define a username for a Docker Hub profile that has push permissions to a repository defined in variableDOCKER_REGISTRY_URLDOCKER_REGISTRY_PASSWORD: Define a password for a Docker Hub profile that has push permissions to a repository defined in variableDOCKER_REGISTRY_URL
- RAIL experiment setup:
MAX_PARALLEL_IMAGE_BUILDS: Define a maximum number of Python (asyncio) tasks that build and push docker images in parallelMAX_PARALLEL_CONTAINERS: Define a maximum number of Python (asyncio) tasks that run REANA workflows in parallelMAX_IMAGE_BUILDS_ATTEMPTS: Define a maximum number of ATTEMPTS that are executed for each failing process of building a docker imageMAX_EXPERIMENT_RUN_ATTEMPTS: Define a maximum number of ATTEMPTS that are executed for each failing experiment run
- Mongo setup:
This repository contains two systems; the database and the REST API. As a database we use a containerized MongoDB server (through Docker), the REST API can be run locally or containerized.
- Create
.envfile containing relevant ENV variables required for the service defined in.env.sample. The required variables are described in greater detail in the Deployment section. - Start the service using the following command:
docker compose up -d --build
IMPORTANT: Make sure you check and potentially modify the host port mappings for specific components in docker-compose.yml file.
- Create two arbitrarily located folders that will be used to store:
- MongoDB database, e.g.
./db - files corresponding to individual experiments (throughout this documentation we tend to call this
folder
eee-data, however you can name this directory however you would like)
- MongoDB database, e.g.
- Create MongoDB container using following
command:
docker run --name eee-mongo -p 27017:27017 -d -v <PATH_TO_DB_FOLDER>:/data/db mongo:6.0.6 - [IF YOU'RE ON WINDOWS] Open specific port for Docker to listen to, so that you can communicate with it. Specifically
use Docker Desktop application and:
- Go to "settings"
- Go to "general"
- Check "Expose daemon on tcp://localhost:2375 without TLS" if its unchecked
- Create
.envfile containing relevant ENV variables required for the service defined in.env.sample. The required variables are described in greater detail in the Deployment section. - Install Python >= 3.10 if you haven't done so already. We recommend using Python version 3.10 as this particular version has been tested and used for the development of this project.
- Install dependencies by executing following command:
pip install -r requirements.txt. - Create additional ENV variables (these variables can be also added to the created
.envfile):MONGODB_URI: URL of mongodb, if you created mongodb instance using command in the previous step then use valuemongodb://localhost:27017for this variableDOCKER_BASE_URL: Use valuetcp://localhost:2375if you're on Windows and not using WSL; otherwise useunix:///var/run/docker.sockEEE_DATA_PATH: Not necessarily an absolute path of the so calledeee-datafolder you have created beforehand in the step 1.2.
- Manually export REANA env variables in the terminal you shall use for running the application:
export REANA_SERVER_URL=<URL_PLACEHOLDER> && export REANA_ACCESS_TOKEN=<TOKEN_PLACEHOLDER> - Start the FastAPI server using the following command:
uvicorn app.main:app --reload
Note: These scripts doesn't currently work as they haven't been updated to the current RAIL version.
Execute Python script found on the path: dev-scripts/experiments/create_experiment_template.py that creates one
ExperimentTemplate that will be stored in MongoDB database.
IMPORTANT:
- Run the script from the directory
dev-scripts/experiments - Don't forget to change the port in said script to the one your FastAPI server is listening on
By default, the application stores data in a named volume eee-data mounted folder on /data/eee path.
Example of a resulting folder structure after creation of one ExperimentTemplate and a successful execution of ExperimentRun:
/data/eee/
├── experiment-templates
│ └── template-64940e38a8784c37c5f9a529
│ ├── Dockerfile
│ ├── reana.yaml
│ ├── requirements.txt
│ └── script.py
└── experiments-userdata
└── run-64d22795090f4a38dbbf9764
├── .env
├── log.txt
├── reana.yaml
├── script.py
└── output
└── metrics.jsonpip install -r requirements-dev.txtpre-commit installYou can also trigger the execution of pre-commit hooks on all files manually by running the following command:
pre-commit run --all-filesThis project uses pytest framework for testing.
You need to run the unit tests from root directory backend where also the config file pytest.ini is located.
The execution of all tests can be then simply done by running the command:
pytestThe configuration makes sure that code coverage is computed by pytest-cov as well.
You can browse the generated coverage report in HTML format found in directory htmlcov.