feat: 添加 Dockerfile 和 docker-compose.yml 部署方案
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.venv/
|
||||
.pytest_cache/
|
||||
.ruff_cache/
|
||||
.mypy_cache/
|
||||
.vscode/
|
||||
.git/
|
||||
.gitignore
|
||||
.env
|
||||
data/
|
||||
*.egg-info/
|
||||
dist/
|
||||
build/
|
||||
.coverage
|
||||
coverage.xml
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
# Dockerfile — md-vector-db 生产镜像
|
||||
FROM python:3.13-slim-bookworm
|
||||
|
||||
LABEL org.opencontainers.image.title="md-vector-db"
|
||||
LABEL org.opencontainers.image.description="Markdown 文档向量数据库"
|
||||
|
||||
# 系统依赖
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 先复制依赖文件以利用 Docker 层缓存
|
||||
COPY pyproject.toml uv.lock ./
|
||||
|
||||
# 安装 uv 并同步依赖(CPU 模式)
|
||||
RUN pip install --no-cache-dir uv \
|
||||
&& uv sync --frozen --no-dev \
|
||||
&& uv cache clean
|
||||
|
||||
# 复制源码和配置
|
||||
COPY config.yaml .env.example ./
|
||||
COPY src/ ./src/
|
||||
COPY scripts/ ./scripts/
|
||||
|
||||
# 创建数据目录
|
||||
RUN mkdir -p /app/data
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 8000
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/health')" || exit 1
|
||||
|
||||
# 默认启动 HTTP 服务
|
||||
CMD ["uv", "run", "md-vector-db", "serve", "--port", "8000"]
|
||||
@@ -0,0 +1,66 @@
|
||||
# docker-compose.yml — md-vector-db 本地开发与生产部署
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
md-vector-db:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: md-vector-db:latest
|
||||
container_name: md-vector-db
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "${MD_VECTOR_PORT:-8000}:8000"
|
||||
volumes:
|
||||
# 持久化 ChromaDB 数据
|
||||
- ./data:/app/data
|
||||
# 挂载配置文件
|
||||
- ./config.yaml:/app/config.yaml:ro
|
||||
# 挂载待入库文档目录
|
||||
- ${MD_VECTOR_DOCS_DIR:-./md_docs}:/app/md_docs:ro
|
||||
environment:
|
||||
- MD_VECTOR_CONFIG=/app/config.yaml
|
||||
- MD_VECTOR_DB_DATA_DIR=/app/data
|
||||
- MD_VECTOR_API_KEY=${MD_VECTOR_API_KEY:-}
|
||||
- EMBED_API_KEY=${EMBED_API_KEY:-}
|
||||
- CORS_ORIGINS=${CORS_ORIGINS:-http://localhost:3000}
|
||||
- MAX_REQUEST_BODY_SIZE=${MAX_REQUEST_BODY_SIZE:-10485760}
|
||||
env_file:
|
||||
- .env
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/health')"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 60s
|
||||
|
||||
# 可选:GPU 版本(需 nvidia-container-toolkit)
|
||||
md-vector-db-gpu:
|
||||
profiles: ["gpu"]
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: md-vector-db:latest
|
||||
container_name: md-vector-db-gpu
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "${MD_VECTOR_PORT:-8000}:8000"
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
- ./config.yaml:/app/config.yaml:ro
|
||||
- ${MD_VECTOR_DOCS_DIR:-./md_docs}:/app/md_docs:ro
|
||||
environment:
|
||||
- MD_VECTOR_CONFIG=/app/config.yaml
|
||||
- MD_VECTOR_DB_DATA_DIR=/app/data
|
||||
- MD_VECTOR_API_KEY=${MD_VECTOR_API_KEY:-}
|
||||
- EMBED_API_KEY=${EMBED_API_KEY:-}
|
||||
- CORS_ORIGINS=${CORS_ORIGINS:-http://localhost:3000}
|
||||
env_file:
|
||||
- .env
|
||||
deploy:
|
||||
resources:
|
||||
reservations:
|
||||
devices:
|
||||
- driver: nvidia
|
||||
count: 1
|
||||
capabilities: [gpu]
|
||||
Reference in New Issue
Block a user