feat: Docker 化部署(nginx-proxy-manager 反代,单域名 /api 路由)

- docker-compose.yml: backend + frontend 两服务,挂 NPM 所在外部网络、不暴露宿主端口;
  data/uploads 用 bind mount 持久化(deploy/ 下,gitignored)
- backend/Dockerfile: python:3.12-slim + 清华 PyPI 镜像(ARG 可覆盖)
- frontend/Dockerfile: 多阶段 node:22 + npm ci + next build(NEXT_PUBLIC_API_BASE 构建期
  注入,npmmirror 默认)→ next start
- .env.example: 全量部署环境变量模板(compose 替换变量 + 后端密钥)
- deploy/README.md: 服务器部署手册(NPM 配置 / DNS / 数据迁移 / 运维 / 大陆网络)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-10-25 15:35:20 +08:00
co-authored by Claude Code
parent 8f9957ad9b
commit f63c0c55c9
7 changed files with 293 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
# BookMate 后端镜像:FastAPI + SQLAlchemy async + SQLite
# 构建上下文是仓库根目录(docker-compose context: .),COPY 路径相对仓库根。
FROM python:3.12-slim
WORKDIR /app
ENV PYTHONUNBUFFERED=1 \
PYTHONIOENCODING=utf-8 \
PIP_NO_CACHE_DIR=1
# 先装依赖(利用层缓存)。大陆网络默认走清华 PyPI 镜像;可在构建时用 --build-arg 覆盖:
# docker compose build --build-arg PIP_INDEX_URL=https://pypi.org/simple backend
ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
COPY backend/requirements.txt /app/requirements.txt
RUN pip install -i "$PIP_INDEX_URL" -r /app/requirements.txt
# 应用代码;密钥与数据不打包进镜像(.env 由 compose env_file 注入,data/uploads 由卷挂载)
COPY backend/app /app/app
EXPOSE 8000
# 生产用:不挂 --reload
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]