Files
yunke/yunke-server/Dockerfile
T
浅念 35bfebd3e3 chore(backend): list_order迁移补齐+Task14类型修正落链+moments每页日志+MsgTypeParam派生+3处文档修正+Dockerfile打包migrations+DEPLOY补迁移步骤
- 9b0d0c133035: wechat_account.list_order 进迁移链(此前仅模型声明,
  干净库 /api/accounts 即 500);sa.inspect 幂等守卫兼容已手动加列的
  smoke.db
- fe63c6789e94(验证中发现的预存缺口,超出原清单): Task 14 的 5 列模型
  类型修正(4×URL String(1024)→Text, db_size Integer→BigInteger)从未落
  链——纯 alembic 新库会复活 >1KB 链接截断;对齐后干净库 alembic check
  全绿。SQLite message 表 batch 重建会掉 FTS 触发器+rowid 脱节(docstring
  记明 ensure_fts+rebuild_fts 修复,smoke.db 已修复验证)
- scrape_via_page: _iter_moments_pages 每页一行进度日志(镜像 _fetch_pages)
- messages: MsgTypeParam=Literal[tuple(_MSG_TYPE_FILTER)] 派生,杜绝
  双处罗列漂移(openapi enum 验证一致,492 绿含 422 行为)
- 文档: ChatGroup 复合PK docstring/groups room_id 多行表述/测试名去
  单行假设;Dockerfile 补 alembic.ini+migrations;DEPLOY 增「数据库
  迁移」节(新库/旧库stamp路径/回填脚本显式DB_URL)+运维表升级行

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-25 20:32:25 +08:00

70 lines
2.7 KiB
Docker

# Backend image: FastAPI + APScheduler + Alembic + scrapers.
#
# Keeps the image small (python:3.12-slim) and the layer cache hot by copying
# only pyproject.toml first and installing deps before the source lands. The
# same image serves both the API (uvicorn) and the scheduler
# (``python -m app.sync.cli scheduler``) — the docker-compose ``command:`` key
# selects which entrypoint runs.
FROM python:3.12-slim
# Build-time / runtime deps for asyncmy (compiled C extension) + httpx +
# cryptography.``libmariadb`` is what asyncmy links against on Debian.
# Playwright 系统依赖:Chromium headless 需要的共享库(libnss3/libatk/libx11
# 等,playwright install-deps 的等价精简集,2026-08-21 部署阻塞点#1)。
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
libmariadb-dev \
libffi-dev \
# Chromium headless 依赖(playwright 官方 install-deps 清单)
libnss3 \
libnspr4 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2 \
libpango-1.0-0 \
libcairo2 \
libatspi2.0-0 \
libx11-6 \
libxcb1 \
libxext6 \
libexpat1 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Install dependencies first (cache-friendly: only re-installs when
# pyproject.toml changes). The project itself is installed in editable-like
# mode by copying the package in afterwards.
COPY pyproject.toml ./
COPY app/__init__.py app/__init__.py
COPY app/ ./app/
# scripts/ — 调度器的页面抓取入口(scripts/scrape_via_page.py 与
# full_sync_all.sh 由 scheduler._page_subprocess 以 cwd=/app 调起,
# 2026-08-21 部署阻塞点#2:镜像里必须带上)。
COPY scripts/ ./scripts/
# alembic.ini + migrations/ — 容器内可跑 `alembic upgrade head`(DB_URL
# 环境变量已由 compose 注入;entrypoint 不自动迁移,由运维手动执行,
# 见 docs/DEPLOY.md「数据库迁移」)。alembic.ini 的 script_location 用
# %(here)s 相对 ini 自身,落在 /app/migrations 正好对上。
COPY alembic.ini ./
COPY migrations/ ./migrations/
# Install the package + dev dependencies (the dev extras include aiosqlite +
# pytest, which are tiny and convenient for in-container smoke checks). Pin
# the install to the local source so the package import path resolves.
RUN pip install --no-cache-dir -e ".[dev]" \
&& playwright install chromium --with-deps
# Default command — overridden per-service in docker-compose. The API service
# runs uvicorn; the scheduler service runs the CLI.
CMD ["uvicorn", "app.api.main:app", "--host", "0.0.0.0", "--port", "8000"]