From 69263e6dd9a174ebf0f92efdf1c4f43f352db14a Mon Sep 17 00:00:00 2001 From: Chih-Yu Yeh Date: Wed, 3 Apr 2024 15:57:09 +0800 Subject: [PATCH] Chore/docker compose update (#69) * update docker related settings * change WREN_AI_SERVICE_PORT default 5555 * add pull_policy, restart condition and update wren-ai-service port * fix default port for wren-ai-service --- docker/.env.example | 2 +- docker/docker-compose-dev.yaml | 8 ++++++-- docker/docker-compose.yaml | 7 ++++++- wren-ai-service/.env.dev.example | 4 ++-- wren-ai-service/.env.prod.example | 2 +- wren-ai-service/Makefile | 2 +- wren-ai-service/README.md | 2 +- wren-ai-service/demo/utils.py | 2 +- wren-ai-service/docker/Dockerfile | 2 +- wren-ai-service/docker/docker-compose.yml | 4 ++-- wren-ai-service/src/__main__.py | 16 ++++++++-------- 11 files changed, 30 insertions(+), 21 deletions(-) diff --git a/docker/.env.example b/docker/.env.example index dd57921dc..8e95c4c1d 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -4,7 +4,7 @@ PLATFORM=linux/amd64 # service port WREN_ENGINE_PORT=8080 WREN_ENGINE_SQL_PORT=7432 -WREN_AI_SERVICE_PORT=80 +WREN_AI_SERVICE_PORT=5555 # version # CHANGE THIS TO THE LATEST VERSION diff --git a/docker/docker-compose-dev.yaml b/docker/docker-compose-dev.yaml index dda0ea198..23cc18bdb 100644 --- a/docker/docker-compose-dev.yaml +++ b/docker/docker-compose-dev.yaml @@ -10,6 +10,7 @@ networks: services: bootstrap: image: ghcr.io/canner/wren-bootstrap:${WREN_BOOTSTRAP_VERSION} + pull_policy: always platform: ${PLATFORM} environment: DATA_PATH: /app/data @@ -19,6 +20,7 @@ services: wren-engine: image: ghcr.io/canner/wren-engine:${WREN_ENGINE_VERSION} + pull_policy: always platform: ${PLATFORM} expose: - ${WREN_ENGINE_SQL_PORT} @@ -33,11 +35,12 @@ services: wren-ai-service: image: ghcr.io/canner/wren-ai-service:${WREN_AI_SERVICE_VERSION} + pull_policy: always platform: ${PLATFORM} ports: - - 5000:${WREN_AI_SERVICE_PORT} + - ${WREN_AI_SERVICE_PORT}:${WREN_AI_SERVICE_PORT} environment: - UVICORN_PORT: ${WREN_AI_SERVICE_PORT} + WREN_AI_SERVICE_PORT: ${WREN_AI_SERVICE_PORT} OPENAI_API_KEY: ${OPENAI_API_KEY} QDRANT_HOST: qdrant WREN_ENGINE_ENDPOINT: http://wren-engine:${WREN_ENGINE_PORT} @@ -51,6 +54,7 @@ services: qdrant: image: qdrant/qdrant:v1.7.4 + pull_policy: always expose: - 6333 - 6334 diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 29d069220..5b9534ce0 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -10,6 +10,7 @@ networks: services: bootstrap: image: ghcr.io/canner/wren-bootstrap:${WREN_BOOTSTRAP_VERSION} + restart: on-failure platform: ${PLATFORM} environment: DATA_PATH: /app/data @@ -19,6 +20,7 @@ services: wren-engine: image: ghcr.io/canner/wren-engine:${WREN_ENGINE_VERSION} + restart: on-failure platform: ${PLATFORM} expose: - ${WREN_ENGINE_PORT} @@ -32,11 +34,12 @@ services: wren-ai-service: image: ghcr.io/canner/wren-ai-service:${WREN_AI_SERVICE_VERSION} + restart: on-failure platform: ${PLATFORM} expose: - ${WREN_AI_SERVICE_PORT} environment: - UVICORN_PORT: ${WREN_AI_SERVICE_PORT} + WREN_AI_SERVICE_PORT: ${WREN_AI_SERVICE_PORT} OPENAI_API_KEY: ${OPENAI_API_KEY} QDRANT_HOST: qdrant WREN_ENGINE_ENDPOINT: http://wren-engine:${WREN_ENGINE_PORT} @@ -51,6 +54,7 @@ services: qdrant: image: qdrant/qdrant:v1.7.4 + restart: on-failure expose: - 6333 - 6334 @@ -61,6 +65,7 @@ services: wren-ui: image: ghcr.io/canner/wren-ui:${WREN_UI_VERSION} + restart: on-failure platform: ${PLATFORM} environment: DB_TYPE: sqlite diff --git a/wren-ai-service/.env.dev.example b/wren-ai-service/.env.dev.example index 44d093bb2..c3aba06f8 100644 --- a/wren-ai-service/.env.dev.example +++ b/wren-ai-service/.env.dev.example @@ -1,6 +1,6 @@ # fastapi related -UVICORN_HOST=127.0.0.1 -UVICORN_PORT=5000 +WREN_AI_SERVICE_HOST=127.0.0.1 +WREN_AI_SERVICE_PORT=5555 # app related QDRANT_HOST=localhost diff --git a/wren-ai-service/.env.prod.example b/wren-ai-service/.env.prod.example index 12c63a19c..77ae47890 100644 --- a/wren-ai-service/.env.prod.example +++ b/wren-ai-service/.env.prod.example @@ -6,7 +6,7 @@ COMPOSE_PROJECT_NAME=wren # fastapi related -UVICORN_PORT=5000 +WREN_AI_SERVICE_PORT=5555 # app related QDRANT_HOST=qdrant diff --git a/wren-ai-service/Makefile b/wren-ai-service/Makefile index aebb235c3..7404c977a 100644 --- a/wren-ai-service/Makefile +++ b/wren-ai-service/Makefile @@ -2,7 +2,7 @@ start: poetry run python -m src.__main__ build: - docker compose -f docker/docker-compose.yml build + docker compose -f docker/docker-compose.yml --env-file .env.prod build up: make run-wren-engine && \ diff --git a/wren-ai-service/README.md b/wren-ai-service/README.md index bc65c2223..91bd399c6 100644 --- a/wren-ai-service/README.md +++ b/wren-ai-service/README.md @@ -11,7 +11,7 @@ ## Start the service for development -- execute `make start` to start the service and go to `http://UVICORN_HOST:UVICORN_PORT` to see the API documentation and try the APIs +- execute `make start` to start the service and go to `http://WREN_AI_SERVICE_HOST:WREN_AI_SERVICE_PORT` to see the API documentation and try the APIs ## Production Environment Setup diff --git a/wren-ai-service/demo/utils.py b/wren-ai-service/demo/utils.py index cdd78e05b..9d0a0c224 100644 --- a/wren-ai-service/demo/utils.py +++ b/wren-ai-service/demo/utils.py @@ -15,7 +15,7 @@ import sqlglot import sqlparse import streamlit as st -WREN_AI_SERVICE_BASE_URL = "http://127.0.0.1:5000" +WREN_AI_SERVICE_BASE_URL = "http://127.0.0.1:5555" WREN_ENGINE_PG_URL = ( "postgres://localhost:7432/canner-cml?options=--search_path%3Dspider" ) diff --git a/wren-ai-service/docker/Dockerfile b/wren-ai-service/docker/Dockerfile index e726dae67..dd7afed32 100644 --- a/wren-ai-service/docker/Dockerfile +++ b/wren-ai-service/docker/Dockerfile @@ -23,4 +23,4 @@ COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} COPY src src -ENTRYPOINT [ "uvicorn", "src.__main__:app", "--host", "0.0.0.0", "--port", "80" ] \ No newline at end of file +ENTRYPOINT uvicorn src.__main__:app --host 0.0.0.0 --port $WREN_AI_SERVICE_PORT \ No newline at end of file diff --git a/wren-ai-service/docker/docker-compose.yml b/wren-ai-service/docker/docker-compose.yml index 48bce072c..a52c4db0a 100644 --- a/wren-ai-service/docker/docker-compose.yml +++ b/wren-ai-service/docker/docker-compose.yml @@ -11,7 +11,7 @@ services: context: .. dockerfile: docker/Dockerfile environment: - UVICORN_PORT: ${UVICORN_PORT} + WREN_AI_SERVICE_PORT: ${WREN_AI_SERVICE_PORT} OPENAI_API_KEY: ${OPENAI_API_KEY} QDRANT_HOST: ${QDRANT_HOST} WREN_ENGINE_ENDPOINT: ${WREN_ENGINE_ENDPOINT} @@ -19,7 +19,7 @@ services: # using PYTHONUNBUFFERED: 1 can fix this PYTHONUNBUFFERED: 1 ports: - - ${UVICORN_PORT}:80 + - ${WREN_AI_SERVICE_PORT}:${WREN_AI_SERVICE_PORT} depends_on: - qdrant diff --git a/wren-ai-service/src/__main__.py b/wren-ai-service/src/__main__.py index d2039d66d..88c3ea193 100644 --- a/wren-ai-service/src/__main__.py +++ b/wren-ai-service/src/__main__.py @@ -13,11 +13,6 @@ from src.web.v1 import routers env = load_env_vars() -server_host = os.getenv("UVICORN_HOST") or "127.0.0.1" -server_port = ( - int(os.getenv("UVICORN_PORT")) if os.getenv("UVICORN_PORT") is not None else 8000 -) - # https://fastapi.tiangolo.com/advanced/events/#lifespan @asynccontextmanager @@ -35,9 +30,7 @@ app = FastAPI(lifespan=lifespan, redoc_url=None) app.include_router(routers.router, prefix="/v1") app.add_middleware( CORSMiddleware, - allow_origins=[ - f"http://{server_host}:{server_port}", - ], + allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], @@ -66,6 +59,13 @@ def root(): if __name__ == "__main__": + server_host = os.getenv("WREN_AI_SERVICE_HOST") or "127.0.0.1" + server_port = ( + int(os.getenv("WREN_AI_SERVICE_PORT")) + if os.getenv("WREN_AI_SERVICE_PORT") is not None + else 8000 + ) + uvicorn.run( "src.__main__:app", host=server_host,