准备部署

This commit is contained in:
AgentLabCn
2026-06-15 21:21:20 +08:00
parent 4167714149
commit 6c22cf9ef7
17 changed files with 898 additions and 2 deletions
+37
View File
@@ -0,0 +1,37 @@
# ============================================================
# 青叶 —— 生产环境后端镜像
# ------------------------------------------------------------
# 与开发用 Dockerfile 的区别:
# 1. 不切换国内镜像源(使用 Debian / PyPI 官方源,适合全球部署)
# 2. 运行命令固定为「单进程 uvicorn + proxy-headers」,不带 --reload
# 3. 不挂载源码(运行镜像内 COPY 进来的代码)
#
# ⚠️ 关键约束:必须单进程!WebSocket 连接管理器(ConnectionManager)是
# 进程内存单例。若改用 --workers N 或 gunicorn 多 worker,连接会被拆分到
# 不同进程,导致跨用户实时消息(聊天、撤回、好友请求等)无法投递。
# 水平扩展前需先把 manager 迁移到 Redis pub/sub。
# ============================================================
FROM python:3.12-slim
WORKDIR /app
# 安装系统依赖(使用官方源,便于全球部署)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# 安装 Python 依赖
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# 复制项目代码(backend/.dockerignore 已排除 __pycache__/.env/uploads 等)
COPY . .
# 创建上传目录
RUN mkdir -p /app/uploads
EXPOSE 8000
# 生产运行:单 worker + proxy-headers(信任 Nginx 转发的 X-Forwarded-*
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"]