refactor: 更新 Docker 配置,优化服务连接和健康检查
This commit is contained in:
parent
e1b02e0458
commit
6671c920c3
@ -3,9 +3,9 @@ services:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/api.Dockerfile
|
||||
# args:
|
||||
# http_proxy: http://172.19.13.5:7890
|
||||
# https_proxy: http://172.19.13.5:7890
|
||||
args:
|
||||
http_proxy: ${HTTP_PROXY:-""}
|
||||
https_proxy: ${HTTPS_PROXY:-""}
|
||||
image: yuxi-api:0.1.0
|
||||
container_name: api-dev
|
||||
working_dir: /app
|
||||
@ -31,12 +31,15 @@ services:
|
||||
- NEO4J_URI=bolt://graph:7687
|
||||
- NEO4J_USERNAME=${NEO4J_USERNAME:-neo4j}
|
||||
- NEO4J_PASSWORD=${NEO4J_PASSWORD:-0123456789}
|
||||
- MILVUS_URI=http://127.0.0.1:19530
|
||||
- MINERU_OCR_URI=http://127.0.0.1:30000
|
||||
- MILVUS_URI=http://milvus:19530
|
||||
- MINERU_OCR_URI=http://mineru:30000
|
||||
- MODEL_DIR=/models
|
||||
- RUNNING_IN_DOCKER=true
|
||||
command: uv run uvicorn server.main:app --host 0.0.0.0 --port 5050 --reload
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
milvus:
|
||||
condition: service_healthy
|
||||
|
||||
web:
|
||||
build:
|
||||
@ -69,6 +72,12 @@ services:
|
||||
volumes:
|
||||
- ./docker/volumes/neo4j/data:/data
|
||||
- ./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:
|
||||
- NEO4J_AUTH=${NEO4J_USERNAME:-neo4j}/${NEO4J_PASSWORD:-0123456789}
|
||||
- NEO4J_server_bolt_listen__address=0.0.0.0:7687
|
||||
@ -147,12 +156,14 @@ services:
|
||||
- app-network
|
||||
restart: unless-stopped
|
||||
# lastest version: wget https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/docker/compose.yaml
|
||||
mineru-sglang:
|
||||
mineru:
|
||||
build:
|
||||
context: scripts/mineru-sglang
|
||||
dockerfile: Dockerfile
|
||||
context: .
|
||||
dockerfile: docker/mineru.Dockerfile
|
||||
image: mineru-sglang:latest
|
||||
container_name: mineru-sglang
|
||||
container_name: mineru
|
||||
profiles:
|
||||
- all
|
||||
ports:
|
||||
- 30000:30000
|
||||
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 ../server /app/server
|
||||
|
||||
# 关闭代理设置
|
||||
ENV http_proxy="" \
|
||||
https_proxy=""
|
||||
|
||||
# 同步项目
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
uv sync
|
||||
@ -103,8 +103,8 @@ class KnowledgeBase:
|
||||
from src.models.rerank_model import get_reranker
|
||||
self.reranker = get_reranker()
|
||||
|
||||
if not self.connect_to_milvus():
|
||||
raise ConnectionError("Failed to connect to Milvus")
|
||||
connected = self.connect_to_milvus()
|
||||
assert connected, ConnectionError("Failed to connect to Milvus")
|
||||
|
||||
# 知识库数据库操作方法
|
||||
def get_all_databases(self):
|
||||
@ -661,20 +661,20 @@ class KnowledgeBase:
|
||||
#* Below is the code for milvus #
|
||||
################################
|
||||
def connect_to_milvus(self):
|
||||
connected = False
|
||||
try:
|
||||
uri = os.getenv('MILVUS_URI', config.get('milvus_uri', "http://milvus:19530"))
|
||||
self.client = MilvusClient(uri=uri)
|
||||
self.client.list_collections() # Test connection
|
||||
logger.info(f"Successfully connected to Milvus at {uri}")
|
||||
return True
|
||||
connected = True
|
||||
except MilvusException as e:
|
||||
logger.error(f"Failed to connect to Milvus: {e},请检查 milvus 的容器是否正常运行。{traceback.format_exc()}")
|
||||
logger.error("如果已退出,请重新启动 `docker restart milvus`。")
|
||||
return False
|
||||
logger.error(f"Failed to connect to Milvus: {e} with {uri}。{traceback.format_exc()}")
|
||||
logger.error("请检查 milvus 的容器是否正常运行,如果已退出,请重新启动 `docker restart milvus`。")
|
||||
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()}")
|
||||
return False
|
||||
|
||||
return connected
|
||||
|
||||
def get_collection_names(self):
|
||||
return self.client.list_collections()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user