refactor: 更新 Docker 配置,优化服务连接和健康检查
This commit is contained in:
parent
e1b02e0458
commit
6671c920c3
@ -3,9 +3,9 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: docker/api.Dockerfile
|
dockerfile: docker/api.Dockerfile
|
||||||
# args:
|
args:
|
||||||
# http_proxy: http://172.19.13.5:7890
|
http_proxy: ${HTTP_PROXY:-""}
|
||||||
# https_proxy: http://172.19.13.5:7890
|
https_proxy: ${HTTPS_PROXY:-""}
|
||||||
image: yuxi-api:0.1.0
|
image: yuxi-api:0.1.0
|
||||||
container_name: api-dev
|
container_name: api-dev
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
@ -31,12 +31,15 @@ services:
|
|||||||
- NEO4J_URI=bolt://graph:7687
|
- NEO4J_URI=bolt://graph:7687
|
||||||
- NEO4J_USERNAME=${NEO4J_USERNAME:-neo4j}
|
- NEO4J_USERNAME=${NEO4J_USERNAME:-neo4j}
|
||||||
- NEO4J_PASSWORD=${NEO4J_PASSWORD:-0123456789}
|
- NEO4J_PASSWORD=${NEO4J_PASSWORD:-0123456789}
|
||||||
- MILVUS_URI=http://127.0.0.1:19530
|
- MILVUS_URI=http://milvus:19530
|
||||||
- MINERU_OCR_URI=http://127.0.0.1:30000
|
- MINERU_OCR_URI=http://mineru:30000
|
||||||
- MODEL_DIR=/models
|
- MODEL_DIR=/models
|
||||||
- RUNNING_IN_DOCKER=true
|
- RUNNING_IN_DOCKER=true
|
||||||
command: uv run uvicorn server.main:app --host 0.0.0.0 --port 5050 --reload
|
command: uv run uvicorn server.main:app --host 0.0.0.0 --port 5050 --reload
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
milvus:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
web:
|
web:
|
||||||
build:
|
build:
|
||||||
@ -69,6 +72,12 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./docker/volumes/neo4j/data:/data
|
- ./docker/volumes/neo4j/data:/data
|
||||||
- ./docker/volumes/neo4j/logs:/var/lib/neo4j/logs
|
- ./docker/volumes/neo4j/logs:/var/lib/neo4j/logs
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "curl -f http://localhost:7474 || exit 1"]
|
||||||
|
interval: 20s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 5
|
||||||
|
start_period: 30s
|
||||||
environment:
|
environment:
|
||||||
- NEO4J_AUTH=${NEO4J_USERNAME:-neo4j}/${NEO4J_PASSWORD:-0123456789}
|
- NEO4J_AUTH=${NEO4J_USERNAME:-neo4j}/${NEO4J_PASSWORD:-0123456789}
|
||||||
- NEO4J_server_bolt_listen__address=0.0.0.0:7687
|
- NEO4J_server_bolt_listen__address=0.0.0.0:7687
|
||||||
@ -147,12 +156,14 @@ services:
|
|||||||
- app-network
|
- app-network
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
# lastest version: wget https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/docker/compose.yaml
|
# lastest version: wget https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/docker/compose.yaml
|
||||||
mineru-sglang:
|
mineru:
|
||||||
build:
|
build:
|
||||||
context: scripts/mineru-sglang
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: docker/mineru.Dockerfile
|
||||||
image: mineru-sglang:latest
|
image: mineru-sglang:latest
|
||||||
container_name: mineru-sglang
|
container_name: mineru
|
||||||
|
profiles:
|
||||||
|
- all
|
||||||
ports:
|
ports:
|
||||||
- 30000:30000
|
- 30000:30000
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@ -1,35 +0,0 @@
|
|||||||
# 使用基础镜像
|
|
||||||
FROM python:3.12
|
|
||||||
|
|
||||||
# 设置工作目录
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# 环境变量设置
|
|
||||||
ARG http_proxy
|
|
||||||
ARG https_proxy
|
|
||||||
ENV http_proxy=$http_proxy \
|
|
||||||
https_proxy=$https_proxy \
|
|
||||||
TZ=Asia/Shanghai
|
|
||||||
|
|
||||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
|
||||||
|
|
||||||
# 安装系统依赖
|
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
python3-dev \
|
|
||||||
ffmpeg \
|
|
||||||
libsm6 \
|
|
||||||
libxext6 \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# 升级 pip
|
|
||||||
RUN pip install --upgrade pip
|
|
||||||
|
|
||||||
# 复制项目配置文件
|
|
||||||
COPY ../pyproject.toml /app/pyproject.toml
|
|
||||||
|
|
||||||
# 安装依赖项
|
|
||||||
RUN pip install -e .
|
|
||||||
|
|
||||||
# 复制代码到容器中
|
|
||||||
COPY ../src /app/src
|
|
||||||
COPY ../server /app/server
|
|
||||||
@ -34,6 +34,10 @@ RUN --mount=type=cache,target=/root/.cache/uv \
|
|||||||
COPY ../src /app/src
|
COPY ../src /app/src
|
||||||
COPY ../server /app/server
|
COPY ../server /app/server
|
||||||
|
|
||||||
|
# 关闭代理设置
|
||||||
|
ENV http_proxy="" \
|
||||||
|
https_proxy=""
|
||||||
|
|
||||||
# 同步项目
|
# 同步项目
|
||||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
uv sync
|
uv sync
|
||||||
@ -103,8 +103,8 @@ class KnowledgeBase:
|
|||||||
from src.models.rerank_model import get_reranker
|
from src.models.rerank_model import get_reranker
|
||||||
self.reranker = get_reranker()
|
self.reranker = get_reranker()
|
||||||
|
|
||||||
if not self.connect_to_milvus():
|
connected = self.connect_to_milvus()
|
||||||
raise ConnectionError("Failed to connect to Milvus")
|
assert connected, ConnectionError("Failed to connect to Milvus")
|
||||||
|
|
||||||
# 知识库数据库操作方法
|
# 知识库数据库操作方法
|
||||||
def get_all_databases(self):
|
def get_all_databases(self):
|
||||||
@ -661,20 +661,20 @@ class KnowledgeBase:
|
|||||||
#* Below is the code for milvus #
|
#* Below is the code for milvus #
|
||||||
################################
|
################################
|
||||||
def connect_to_milvus(self):
|
def connect_to_milvus(self):
|
||||||
|
connected = False
|
||||||
try:
|
try:
|
||||||
uri = os.getenv('MILVUS_URI', config.get('milvus_uri', "http://milvus:19530"))
|
uri = os.getenv('MILVUS_URI', config.get('milvus_uri', "http://milvus:19530"))
|
||||||
self.client = MilvusClient(uri=uri)
|
self.client = MilvusClient(uri=uri)
|
||||||
self.client.list_collections() # Test connection
|
self.client.list_collections() # Test connection
|
||||||
logger.info(f"Successfully connected to Milvus at {uri}")
|
logger.info(f"Successfully connected to Milvus at {uri}")
|
||||||
return True
|
connected = True
|
||||||
except MilvusException as e:
|
except MilvusException as e:
|
||||||
logger.error(f"Failed to connect to Milvus: {e},请检查 milvus 的容器是否正常运行。{traceback.format_exc()}")
|
logger.error(f"Failed to connect to Milvus: {e} with {uri}。{traceback.format_exc()}")
|
||||||
logger.error("如果已退出,请重新启动 `docker restart milvus`。")
|
logger.error("请检查 milvus 的容器是否正常运行,如果已退出,请重新启动 `docker restart milvus`。")
|
||||||
return False
|
|
||||||
except Exception as e: # Catch other potential errors like requests.exceptions.ConnectionError
|
except Exception as e: # Catch other potential errors like requests.exceptions.ConnectionError
|
||||||
logger.error(f"An unexpected error occurred while connecting to Milvus at {uri}: {e}, {traceback.format_exc()}")
|
logger.error(f"An unexpected error occurred while connecting to Milvus at {uri}: {e}, {traceback.format_exc()}")
|
||||||
return False
|
|
||||||
|
|
||||||
|
return connected
|
||||||
|
|
||||||
def get_collection_names(self):
|
def get_collection_names(self):
|
||||||
return self.client.list_collections()
|
return self.client.list_collections()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user