Skip to content

CAiMIRA API development

Luis Aleixo requested to merge feature/backend_separation into master

With the REST API implementation the repository now contains two different Python packages:

  • The caimira, containing all the backend logic. This package will be the one published in PyPI.
  • The cern_caimira, that imports the previous, along with the CERN-specific UI implementation.

The new folder layout is as follows, following the best practices described here:

.
├── README.md
├── app-config
│   ...
├── caimira
│   ├── LICENSE
│   ├── README.md
│   ├── pyproject.toml
│   ├── setup.cfg
│   ├── setup.py
│   ├── src
│   │   ├── caimira
│   │   ├── ...
├── cern_caimira
│   ├── LICENSE
│   ├── README.md
│   ├── pyproject.toml
│   ├── requirements.txt
│   ├── setup.py
│   ├── src
│   │   ├── cern_caimira
│   │   └── ...
│   └── tests
├── open-source-licences
│   ├── ...
└── server-performance-tests
    ├── ...

Given that the cern_caimira package imports the caimira one, the entire cern_caimira package was deployed in the OKD platform. For external dependencies, with a custom UI implementation, the caimira package alone can be deployed, working as an API that provides all the backend functionality. Tests adapted and divided into the respective directories: backend tests in caimira and frontend tests in cern_caimira.

This MR contains the latest changes from the master branch. Related issue: #380

From now on, the procedure for deployment in PROD and TEST environments is as follows:

  • For any push, for any branch except live/caimira-test, the tests will run. master branch will behave as a regular branch, knowing that contain changes ready to be deployed with a new tag/release.
  • If a new tag is created, the tests will run, the Docker images will be created and stored in GitLab's container registry. Then, it is expected the developer to manually update the target image to deploy in OKD corresponding to PROD. The resulting changes are available here: https://caimira.web.cern.ch/
  • If changes are pushed to live/caimira-test, the Docker images will be created and stored in GitLabs's container registry, and then deployed in OKD, available here: https://caimira-test.web.cern.ch/

Tags will now be named with the following naming convention: v5.0.0, corresponding to MAJOR.MINOR.PATCH updates.

The GitLab CI/CD pipeline was configured as follows, with 3 different stages: test, docker-build, and deploy:

Every branch (including master, any tag, and except live/caimira-test: test stage only

  • test_caimira_py311, testing the caimira package with Python 3.11
  • test_caimira_py39, testing the caimira package with Python 3.9
  • test_cern_caimira_py311, testing the cern_caimira package with Python 3.11
  • test_cern_caimira_py39, testing the cern_caimira package with Python 3.9

live/caimira-test branch: test, docker-build and deploy stages:

  • test: check-openshift-config-test - testing the OKD TEST configuration
  • docker-build: docker-build-auth-service-test - building the TEST auth Docker image and saving it in the container registry
  • docker-build: docker-build-calculator-app-service-test - building the TEST calculator app Docker image and saving it in the container registry.
  • deploy: deploy-auth-service-test - deploying in OKD the auth image
  • deploy: deploy-calculator-app-test - deploying in OKD the calculator app image
  • deploy: deploy-calculator-open-app-test - deploying in OKD the open calculator app image (defined with the THEME variable)

Tag: test and docker-build stages:

  • test: check-openshift-config-prod - testing the OKD PROD configuration
  • docker-build: docker-build-auth-service-release - building the PROD auth Docker image and saving it in the container registry
  • docker-build: docker-build-calculator-app-service-release - building the PROD calculator app Docker image and saving it in the container

Changes in OKD:

  1. Removed all build configs and image streams
  2. New service account + secret (not needed if we decide to continue with the manual update of OKD). Discussions on authentication still needed
  3. Changed router and config map
  4. Changed calculator app deployment to use image available in GitLab registry, and adjusted the config
  5. Adapted the THEME variable

CAiMIRA API - example of usage:

  1. After cloning the repository, navigate to the caimira folder: cd caimira.
  2. Install all the required dependencies: pip install -e .
  3. Run the backend: python -m caimira.api.app and notice that: Tornado server is running on port 8088

Afterwards, one can test the API functionallity with Postman, by send a post request to http://localhost:8088/report with the required inputs in the body (you can have an example of the required inputs here). The resulting message should have the following format:

{
    "status": "success",
    "message": "Results generated successfully",
    "report_data": {
                    ...
    },
    ...

One can already incorporate the API response from any external dependency.

Still to do:

  • test the prod deployment
  • update README
  • update the OpenShift configs in the repo, the tests fail
Edited by Luis Aleixo

Merge request reports

Loading