添加 Docker 部署支持和环境变量配置

添加了完整的 Docker 部署方案,包括:
- 创建 .env.example 环境变量配置模板文件
- 新增 docker-compose.yml 用于全栈服务编排
- 为前后端分别创建 Dockerfile 实现容器化部署
- 添加 nginx.conf 配置前端反向代理
- 在 README.md 中详细说明 Docker 部署流程
- 集成 Celery 任务队列支持异步处理
- 配置多数据库服务 (MongoDB, MySQL, Redis) 的连接
- 实现健康检查和服务依赖管理
This commit is contained in:
2026-04-21 20:39:12 +08:00
parent be302839ee
commit d2e3c2db3e
7 changed files with 459 additions and 0 deletions

40
backend/Dockerfile Normal file
View File

@@ -0,0 +1,40 @@
# ============================================================
# FilesReadSystem Backend Docker Image
# ============================================================
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# 安装系统依赖 (FAISS, Pillow, tesseract 等)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
libgl1-mesa-glx \
libglib2.0-0 \
tesseract-ocr \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# 先复制依赖文件,再安装(利用 Docker 缓存)
COPY requirements.txt .
# 安装 Python 依赖
RUN pip install --no-cache-dir -r requirements.txt
# 复制应用代码
COPY app/ ./app/
# 创建数据目录
RUN mkdir -p /app/data/uploads /app/data/faiss /app/data/logs
# 暴露端口
EXPOSE 8000
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD python -c "import httpx; httpx.get('http://localhost:8000/health')" || exit 1
# 启动命令
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

27
backend/app/celery_app.py Normal file
View File

@@ -0,0 +1,27 @@
# ============================================================
# Celery 应用配置
# ============================================================
from celery import Celery
# 优先使用环境变量,否则使用默认值
import os
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "redis://localhost:6379/1")
CELERY_RESULT_BACKEND = os.getenv("CELERY_RESULT_BACKEND", "redis://localhost:6379/2")
celery_app = Celery(
"filesread",
broker=CELERY_BROKER_URL,
backend=CELERY_RESULT_BACKEND,
)
celery_app.conf.update(
task_serializer="json",
accept_content=["json"],
result_serializer="json",
timezone="Asia/Shanghai",
enable_utc=True,
task_track_started=True,
task_time_limit=3600, # 1小时超时
worker_prefetch_multiplier=1,
)