Skip to content

Commit

Permalink
integrate the vachan-tbt app via docker compose service and nginx rou…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
kavitharaju committed Jan 2, 2024
1 parent ac9756d commit d5fc85f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
21 changes: 11 additions & 10 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")

Expand Down Expand Up @@ -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",
{
Expand All @@ -227,15 +229,13 @@ 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)

beta_endpoints = [
"/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}"
Expand All @@ -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. \
<br> • <a href=\"{root_url}/v2/text/translate/token-based/docs\" > Vachan-TBT docs </a>",
routes=app.routes)

# Add version information to specific endpoints
Expand Down
28 changes: 28 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -379,3 +406,4 @@ volumes:
logs-test-vol:
vachan-db-backup:
kratos-db-backup:
vachan-tbt-ml-models-vol:
8 changes: 8 additions & 0 deletions docker/nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions docker/nginx/prod/app.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d5fc85f

Please sign in to comment.