Files
yunke/yunke-server/Dockerfile
T
浅念 df29dd027a feat: scheduler + CLI + docker-compose + README
M6 — the scheduling/deployment layer. Makes the system runnable as a
scheduled service + deployable via Docker.

Part A — SyncScheduler (app/sync/scheduler.py):
- APScheduler (AsyncIOScheduler) wraps the orchestrator's sync_* functions.
- Daily full sync at FULL_SYNC_HOUR (default 02:00 local) + incremental
  message sync every MESSAGE_INTERVAL_HOURS (default 4).
- ENTITY_FUNCS registry dispatches run_once("<entity>") to the right runner
  (departments/accounts/friends/groups/voice_calls/phone_calls/sms/messages/
  all_wechat/all).
- Conversations for the message run are discovered from the local customer
  mirror (no extra upstream call).
- Failure policy: every run is wrapped — a blown entity is logged + swallowed
  so the scheduler keeps its next appointment.
- Per-run JSON-line log (level=info/warning/error, totals, failed entities).

Part B — CLI entry point (app/sync/cli.py):
- `python -m app.sync.cli sync [--entity <name>] [--quiet]` — one-shot sync.
- `python -m app.sync.cli scheduler [--full-sync-hour H] [--message-interval-hours N]`
  — long-running scheduler (blocks until SIGINT/SIGTERM).
- Uses _push_settings_into_environ + build_client_from_env (session-cookie
  mode preferred; pcLogin deferred).
- Base.metadata.create_all on every command (fresh-checkout friendly).
- Exit codes: 0 success, 1 generic failure, 2 bad CLI / auth misconfig.

Part C — Docker stack:
- yunke-server/Dockerfile: python:3.12-slim, installs deps + app, single
  image serves both API (uvicorn) + scheduler (CLI).
- yunkes/Dockerfile: multi-stage node:20 build → nginx serves dist/ +
  reverse-proxies /api → backend:8000.
- yunkes/nginx.conf: /api proxy with proxy_buffering off (streaming media),
  SPA fallback, asset caching.
- docker-compose.yml: mysql (8.0, healthcheck, volume) + redis (7-alpine) +
  backend + scheduler + frontend (port 5173 → 80). Env-driven creds + cadence.

Part D — README.md at repo root: dev mode + docker mode quick-start, config
table, architecture overview, current limitations (pcLogin deferred, WA voice/
media deferred, conservative pacing, conversation discovery is local-only).

Verification:
- pytest: 323 passed (was 294; +29 new for scheduler + CLI).
- npm run build: clean.
- python -m app.sync.cli --help: prints usage.
- docker compose config: VALID.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-05 12:11:29 +08:00

36 lines
1.5 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.
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
libmariadb-dev \
libffi-dev \
&& 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/
# 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]"
# 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"]