Browse Source

write some config to docker-compose

chenhaiyang 1 năm trước cách đây
mục cha
commit
8efbf772aa
4 tập tin đã thay đổi với 22 bổ sung7 xóa
  1. 3 1
      app/services/duckling.py
  2. 3 2
      app/services/milvus.py
  3. 5 3
      app/services/milvus_helpers.py
  4. 11 1
      docker-compose.yml

+ 3 - 1
app/services/duckling.py

@@ -1,3 +1,5 @@
+import os
+
 from httpx import AsyncClient, URL
 
 from app.core.config import settings
@@ -12,7 +14,7 @@ class Duckling:
     def __init__(self, client: AsyncClient, server_settings=settings):
         super(Duckling, self).__init__()
         self._client = client
-        self._host = URL(server_settings.DUCKLING_HOST)
+        self._host = URL(os.getenv("DUCKLING_HOST", settings.DUCKLING_HOST))
 
     @api_exception
     async def parse(self, text: str, locale: str = "zh_CN") -> dict:

+ 3 - 2
app/services/milvus.py

@@ -1,3 +1,4 @@
+import os
 import time
 
 from loguru import logger
@@ -12,8 +13,8 @@ class Milvus:
     """
 
     def __init__(self) -> None:
-        self._host = settings.MILVUS_HOST
-        self._port = settings.MILVUS_PORT
+        self._host = os.getenv("MILVUS_HOST", settings.MILVUS_HOST)
+        self._port = os.getenv("MILVUS_PORT", settings.MILVUS_PORT)
 
     async def query_embedding_by_pk(
             self,

+ 5 - 3
app/services/milvus_helpers.py

@@ -1,3 +1,4 @@
+import os
 import sys
 
 from loguru import logger
@@ -18,12 +19,13 @@ class MilvusHelper:
         try:
             self.collection = None
             connections.connect(
-                host=settings.MILVUS_HOST,
-                port=settings.MILVUS_PORT,
+                host=os.getenv("MILVUS_HOST", settings.MILVUS_HOST),
+                port=os.getenv("MILVUS_PORT", settings.MILVUS_PORT),
             )
             logger.debug(
                 f"Successfully connect to Milvus with IP: "
-                f"{settings.MILVUS_HOST} and PORT: {settings.MILVUS_PORT}"
+                f"{os.getenv('MILVUS_HOST', settings.MILVUS_HOST)} "
+                f"and PORT: {os.getenv('MILVUS_PORT', settings.MILVUS_PORT)}"
             )
         except Exception as e:
             logger.error(f"Failed to connect Milvus: {e}")

+ 11 - 1
docker-compose.yml

@@ -2,7 +2,7 @@ version: "3"
 
 services:
   app:
-      image: registry.persagy.com/sagacloud/saga_algo_api:0.5.20
+      image: registry.persagy.com/sagacloud/saga_algo_api:0.5.21
       container_name: saga_algo_api
       ports:
         - "8002:8002"
@@ -10,6 +10,16 @@ services:
         PLATFORM_HOST: "http://api.sagacloud.cn/data-platform-3"
         TRANSFER_HOST: "http://api.sagacloud.cn/duoduo-service/transfer"
         CUSTOM_HOST: "http://api.sagacloud.cn/duoduo-service/custom-service"
+
+        MILVUS_HOST: "172.18.0.1"
+        MILVUS_PORT: "19530"
+
+        REDIS_HOST: "172.17.11.179"
+        REDIS_PORT: "6379"
+        REDIS_DB: 0
+        REDIS_PASSWORD: "123456"
+
+        DUCKLING_HOST: "http://172.18.0.1:8000"
       extra_hosts:
         - "api.sagacloud.cn:172.17.161.77"
       restart: always