From 90114bf2b1b83437183a5659fb2bedc1d7b2e4ce Mon Sep 17 00:00:00 2001 From: NishaSharma14 Date: Mon, 6 Nov 2023 14:56:05 +0100 Subject: [PATCH 1/4] fix; update docker installation --- Dockerfile | 6 ++++-- app/scripts/nmr-cli/Dockerfile | 2 -- app/scripts/nmr-respredict/Dockerfile | 2 -- docker-compose.yml | 12 +++++------- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index be2d9f6..2cf88a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ FROM continuumio/miniconda3 AS nmrkit-ms ENV PYTHON_VERSION=3.10 -ENV RDKIT_VERSION=2023.03.1 ENV OPENBABEL_VERSION=v3.1 ARG RELEASE_VERSION @@ -15,10 +14,13 @@ RUN apt-get update && \ apt-get install -y curl && \ conda update -n base -c defaults conda +RUN apt-get update && apt-get -y install docker.io + RUN conda install -c conda-forge python>=PYTHON_VERSION -RUN conda install -c conda-forge rdkit>=RDKIT_VERSION RUN conda install -c conda-forge openbabel>=OPENBABEL_VERSION +RUN pip3 install rdkit + RUN python3 -m pip install -U pip ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64/ diff --git a/app/scripts/nmr-cli/Dockerfile b/app/scripts/nmr-cli/Dockerfile index 194176f..7aaf2e9 100644 --- a/app/scripts/nmr-cli/Dockerfile +++ b/app/scripts/nmr-cli/Dockerfile @@ -12,8 +12,6 @@ COPY package.json ./ COPY package-lock.json ./ RUN npm install -RUN apk add docker - COPY . ./ #install the nmr-cli as a global package diff --git a/app/scripts/nmr-respredict/Dockerfile b/app/scripts/nmr-respredict/Dockerfile index f7eabae..58d6ead 100644 --- a/app/scripts/nmr-respredict/Dockerfile +++ b/app/scripts/nmr-respredict/Dockerfile @@ -1,7 +1,6 @@ FROM continuumio/miniconda3 AS nmr-respredict-ms ENV PYTHON_VERSION=3.10 -ENV RDKIT_VERSION=2023.09.1 # Install runtime dependencies RUN apt-get update && \ @@ -11,7 +10,6 @@ RUN apt-get update && \ conda update -n base -c defaults conda RUN conda install -c conda-forge python>=PYTHON_VERSION -# RUN conda install -c conda-forge rdkit>=RDKIT_VERSION RUN python3 -m pip install -U pip RUN pip3 install rdkit diff --git a/docker-compose.yml b/docker-compose.yml index 97d8bff..00c8020 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,12 +2,14 @@ version: "3.8" services: web: - build: - context: ./ - dockerfile: Dockerfile + # build: + # context: ./ + # dockerfile: Dockerfile + image: nfdi4chem/nmrkit:dev-latest container_name: nmrkit-api volumes: - ./app:/code/app + - "/var/run/docker.sock:/var/run/docker.sock" ports: - "80:80" healthcheck: @@ -29,15 +31,11 @@ services: entrypoint: /bin/sh stdin_open: true tty: true - volumes: - - "/var/run/docker.sock:/var/run/docker.sock" nmr-respredict: build: ./app/scripts/nmr-respredict entrypoint: /bin/sh stdin_open: true tty: true - volumes: - - "/var/run/docker.sock:/var/run/docker.sock" prometheus: image: prom/prometheus container_name: nmrkit_prometheus From 3d98e3565d74ac35f93597954a65eae74f19177c Mon Sep 17 00:00:00 2001 From: NishaSharma14 Date: Thu, 9 Nov 2023 14:06:53 +0100 Subject: [PATCH 2/4] add converter router(wip) --- app/main.py | 3 +- app/routers/converter.py | 79 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 app/routers/converter.py diff --git a/app/main.py b/app/main.py index d1ac427..1563e86 100644 --- a/app/main.py +++ b/app/main.py @@ -5,7 +5,7 @@ from .routers import registration from .routers import chem -from .routers import spectra +from .routers import spectra, converter from fastapi.middleware.cors import CORSMiddleware from app.core import config, tasks @@ -31,6 +31,7 @@ app.include_router(registration.router) app.include_router(chem.router) app.include_router(spectra.router) +app.include_router(converter.router) app.add_event_handler("startup", tasks.create_start_app_handler(app)) app.add_event_handler("shutdown", tasks.create_stop_app_handler(app)) diff --git a/app/routers/converter.py b/app/routers/converter.py new file mode 100644 index 0000000..20dfbe2 --- /dev/null +++ b/app/routers/converter.py @@ -0,0 +1,79 @@ +import subprocess +from fastapi import APIRouter, HTTPException, status +from app.schemas import HealthCheck +from urllib.parse import unquote + + +router = APIRouter( + prefix="/convert", + tags=["converter"], + dependencies=[], + responses={404: {"description": "Not Found"}}, +) + +@router.get("/", include_in_schema=False) +@router.get( + "/health", + tags=["healthcheck"], + summary="Perform a Health Check on Converter Module", + response_description="Return HTTP Status Code 200 (OK)", + status_code=status.HTTP_200_OK, + include_in_schema=False, + response_model=HealthCheck, +) +def get_health() -> HealthCheck: + """ + ## Perform a Health Check + Endpoint to perform a healthcheck on. This endpoint can primarily be used by Docker + to ensure a robust container orchestration and management are in place. Other + services that rely on the proper functioning of the API service will not deploy if this + endpoint returns any other HTTP status code except 200 (OK). + Returns: + HealthCheck: Returns a JSON response with the health status + """ + return HealthCheck(status="OK") + + +@router.get( + "/nmrLoadSave", + tags=["converter"], + summary="Conversion through nmr-load save", + # response_model=List[int], + response_description="Conversion through nmr-load save", + status_code=status.HTTP_200_OK, +) +async def nmr_load_save(url: str): + """ + ## Return nmr_load save result + + Returns: + Return nmr_load save result + """ + # url = "https://cheminfo.github.io/bruker-data-test/data/zipped/aspirin-1h.zip" + # command = f"docker exec -it nmrkit_nmr-load-save_1 nmr-cli -u {url}" + try: + process = subprocess.run("docker exec -it nmrkit_nmr-load-save_1 nmr-cli -u " + unqoute(url), + stdout=subprocess.PIPE, + capture_output=True, + shell=True) + # process = subprocess.run(['docker', 'exec', '-it', 'nmrkit_nmr-load-save_1', 'nmr-cli', '-u', unquote(url)], capture_output=True, shell=True) + # print('printing result..') + # print(process.stdout) + # return {"output": process.stdout} + # (output, err) = process.communicate() + # process_status = process.wait() + # print (output) + # return str(output) + while True: + output = process.stdout.readline() + print(output.strip()) + # Do something else + return_code = process.poll() + if return_code is not None: + print('RETURN CODE', return_code) + # Process has finished, read rest of the output + for output in process.stdout.readlines(): + print(output.strip()) + break + except Exception as e: + raise HTTPException(status_code=500, detail="Internal Server Error" + e.message) From 85f1ea35dee7e3e08e665b4d2d3fda540432c186 Mon Sep 17 00:00:00 2001 From: Venkata Chandra Sekhar Nainala Date: Thu, 9 Nov 2023 16:17:14 +0100 Subject: [PATCH 3/4] fix: implemented subprocess to exec nmr-cli on converter image --- app/routers/converter.py | 46 +++++++++++++--------------------------- docker-compose.yml | 9 ++++---- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/app/routers/converter.py b/app/routers/converter.py index 20dfbe2..446cc35 100644 --- a/app/routers/converter.py +++ b/app/routers/converter.py @@ -1,8 +1,8 @@ import subprocess -from fastapi import APIRouter, HTTPException, status +from fastapi import APIRouter, HTTPException, status, Response from app.schemas import HealthCheck from urllib.parse import unquote - +import json router = APIRouter( prefix="/convert", @@ -11,6 +11,7 @@ responses={404: {"description": "Not Found"}}, ) + @router.get("/", include_in_schema=False) @router.get( "/health", @@ -38,7 +39,7 @@ def get_health() -> HealthCheck: "/nmrLoadSave", tags=["converter"], summary="Conversion through nmr-load save", - # response_model=List[int], + # response_model=List[int], response_description="Conversion through nmr-load save", status_code=status.HTTP_200_OK, ) @@ -49,31 +50,14 @@ async def nmr_load_save(url: str): Returns: Return nmr_load save result """ - # url = "https://cheminfo.github.io/bruker-data-test/data/zipped/aspirin-1h.zip" - # command = f"docker exec -it nmrkit_nmr-load-save_1 nmr-cli -u {url}" - try: - process = subprocess.run("docker exec -it nmrkit_nmr-load-save_1 nmr-cli -u " + unqoute(url), - stdout=subprocess.PIPE, - capture_output=True, - shell=True) - # process = subprocess.run(['docker', 'exec', '-it', 'nmrkit_nmr-load-save_1', 'nmr-cli', '-u', unquote(url)], capture_output=True, shell=True) - # print('printing result..') - # print(process.stdout) - # return {"output": process.stdout} - # (output, err) = process.communicate() - # process_status = process.wait() - # print (output) - # return str(output) - while True: - output = process.stdout.readline() - print(output.strip()) - # Do something else - return_code = process.poll() - if return_code is not None: - print('RETURN CODE', return_code) - # Process has finished, read rest of the output - for output in process.stdout.readlines(): - print(output.strip()) - break - except Exception as e: - raise HTTPException(status_code=500, detail="Internal Server Error" + e.message) + process = subprocess.Popen( + ["docker exec nmr-converter nmr-cli -u " + url], + stdout=subprocess.PIPE, + shell=True, + ) + (output, err) = process.communicate() + process.wait() + if err: + raise HTTPException(status_code=500, detail=err) + else: + return Response(content=output, media_type="application/json") diff --git a/docker-compose.yml b/docker-compose.yml index 00c8020..a36d7f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,10 +2,10 @@ version: "3.8" services: web: - # build: - # context: ./ - # dockerfile: Dockerfile - image: nfdi4chem/nmrkit:dev-latest + build: + context: ./ + dockerfile: Dockerfile + # image: nfdi4chem/nmrkit:dev-latest container_name: nmrkit-api volumes: - ./app:/code/app @@ -31,6 +31,7 @@ services: entrypoint: /bin/sh stdin_open: true tty: true + container_name: nmr-converter nmr-respredict: build: ./app/scripts/nmr-respredict entrypoint: /bin/sh From 56d2bfda13d3ed45816914c46065d8f2994af884 Mon Sep 17 00:00:00 2001 From: NishaSharma14 Date: Thu, 9 Nov 2023 16:43:53 +0100 Subject: [PATCH 4/4] fix: update converter api decription --- app/routers/converter.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/routers/converter.py b/app/routers/converter.py index 446cc35..4f6a358 100644 --- a/app/routers/converter.py +++ b/app/routers/converter.py @@ -36,19 +36,19 @@ def get_health() -> HealthCheck: @router.get( - "/nmrLoadSave", + "/spectra", tags=["converter"], - summary="Conversion through nmr-load save", - # response_model=List[int], - response_description="Conversion through nmr-load save", + summary="Load and convert NMR raw data", + #response_model=List[int], + response_description="Load and convert NMR raw data", status_code=status.HTTP_200_OK, ) async def nmr_load_save(url: str): """ - ## Return nmr_load save result + ## Return nmrium json Returns: - Return nmr_load save result + Return nmrium json """ process = subprocess.Popen( ["docker exec nmr-converter nmr-cli -u " + url],