From d5fc85f500f98dc628391dcb6f285a383cb8d7fb Mon Sep 17 00:00:00 2001 From: "Kavitha.Raju" Date: Tue, 2 Jan 2024 12:57:00 +0530 Subject: [PATCH] integrate the vachan-tbt app via docker compose service and nginx routing --- app/main.py | 21 +++++++++++---------- docker/docker-compose.yml | 28 ++++++++++++++++++++++++++++ docker/nginx/default.conf | 8 ++++++++ docker/nginx/prod/app.conf.template | 8 ++++++++ 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/app/main.py b/app/main.py index e4b2cdaf..e1e13006 100644 --- a/app/main.py +++ b/app/main.py @@ -17,7 +17,7 @@ import db_models from database import engine from dependencies import get_db, log -from routers import content_apis, translation_apis, auth_api, media_api, filehandling_apis +from routers import content_apis, auth_api, media_api, filehandling_apis from auth.authentication import create_super_user # pylint: enable=E0401 @@ -28,9 +28,14 @@ create_super_user() +root_url = os.getenv("VACHAN_DOMAIN", 'http://localhost:8000') +if root_url is not None and not root_url.startswith("http://"): + root_url = "http://" + root_url + app = FastAPI(title="Vachan-API", version="2.0.0", - description="The server application that provides APIs to interact \ -with the underlying Databases and modules in Vachan-Engine.") + description=f"The server application that provides APIs to interact \ +with the underlying Databases and modules in Vachan-Engine. \ +\n • For Vachan-TBT docs: {root_url}/v2/text/translate/token-based/docs") template = Jinja2Templates(directory="templates") app.mount("/static", StaticFiles(directory="static"), name="static") @@ -214,9 +219,6 @@ def test(request: Request,db_: Session = Depends(get_db)): '''Tests if app is running and the DB connection is active * Also displays API documentation page upon successful connection on root endpoint''' db_.query(db_models.Language).first() - root_url = os.getenv("VACHAN_DOMAIN") - if root_url is not None and not root_url.startswith("http://"): - root_url = "http://" + root_url return template.TemplateResponse( "landing_page.html", { @@ -227,7 +229,6 @@ def test(request: Request,db_: Session = Depends(get_db)): app.include_router(auth_api.router) app.include_router(content_apis.router) -app.include_router(translation_apis.router) app.include_router(media_api.router) app.include_router(filehandling_apis.router) @@ -235,7 +236,6 @@ def test(request: Request,db_: Session = Depends(get_db)): "/graphql", # Specify the paths of the beta endpoints "/v2/resources/bibles/{resource_name}/versification", "/v2/resources/bibles/{resource_name}/books/{book_code}/export/{output_format}", - "/v2/text/translate/token-based/project/versification", "/v2/media/gitlab/stream", "/v2/media/gitlab/download", "/v2/files/usfm/to/{output_format}" @@ -244,8 +244,9 @@ def test(request: Request,db_: Session = Depends(get_db)): def custom_openapi(): '''Modify the auto generated openapi schema for API docs''' openapi_schema = get_openapi(title="Vachan-API", version="2.0.0", - description="The server application that provides APIs to interact \ - with the underlying Databases and modules in Vachan-Engine.", + description=f"The server application that provides APIs to interact \ +with the underlying Databases and modules in Vachan-Engine. \ +
Vachan-TBT docs ", routes=app.routes) # Add version information to specific endpoints diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 02b74e45..3797e8d9 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -208,6 +208,33 @@ services: networks: - VE-network + vachan-tbt: + image: kavitha3797/vachan-tbt:v2.0.0-alpha.4 + expose: + - 8003 + command: uvicorn main:app --host 0.0.0.0 --port 8003 + restart: always + environment: + - VACHAN_POSTGRES_HOST=vachan-db + - VACHAN_POSTGRES_PORT=5432 + - VACHAN_POSTGRES_USER=${VACHAN_POSTGRES_USER:-postgres} + - VACHAN_POSTGRES_PASSWORD=${VACHAN_POSTGRES_PASSWORD:-password} + - VACHAN_POSTGRES_DATABASE=${VACHAN_POSTGRES_DATABASE:-vachan_dev} + - VACHAN_POSTGRES_SCHEMA=vachan_tbt + - VACHAN_LOGGING_LEVEL=INFO + - VACHAN_DOMAIN=${VACHAN_DOMAIN:-http://localhost} + - VACHAN_CMS_DOMAIN=http://vachan-api + volumes: + - logs-vol:/app/logs + - vachan-tbt-ml-models-vol:/app/ml-models + depends_on: + - vachan-db + profiles: + - local-run + - deployment + networks: + - VE-network + vachan-cms-graphql: image: athulyams/graphql-12:v2.0.0-alpha.1 ports: @@ -379,3 +406,4 @@ volumes: logs-test-vol: vachan-db-backup: kratos-db-backup: + vachan-tbt-ml-models-vol: diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf index 462ba7d2..eb3af0f5 100644 --- a/docker/nginx/default.conf +++ b/docker/nginx/default.conf @@ -19,6 +19,14 @@ server { proxy_set_header X-Forwarded-Proto $scheme; } + location /v2/text/translate/token-based/ { + proxy_pass http://vachan-tbt:8003; + } + + location /v2/nlp/ { + proxy_pass http://vachan-tbt:8003; + } + location /v2/demos/ { # Important, make sure you always remove the trailing slash proxy_pass http://vachan-demos:8002; diff --git a/docker/nginx/prod/app.conf.template b/docker/nginx/prod/app.conf.template index d4f47161..0fc3031c 100644 --- a/docker/nginx/prod/app.conf.template +++ b/docker/nginx/prod/app.conf.template @@ -40,6 +40,14 @@ server { location /graphql/ { proxy_pass http://vachan-cms-graphql:8004; } + + location /v2/text/translate/token-based/ { + proxy_pass http://vachan-tbt:8003; + } + + location /v2/nlp/ { + proxy_pass http://vachan-tbt:8003; + } location /v2/demos/ { proxy_pass http://vachan-demos:8002;