diff --git a/.gitignore b/.gitignore index 99d44d9..c630f3a 100644 --- a/.gitignore +++ b/.gitignore @@ -186,4 +186,7 @@ cython_debug/ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data # refer to https://docs.cursor.com/context/ignore-files .cursorignore -.cursorindexingignore \ No newline at end of file +.cursorindexingignore + +**/data/* +**/docker/* \ No newline at end of file diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..ddec2af --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,13 @@ +.venv +.git +__pycache__ +*.pyc +*.pyo +*.pyd +.pytest_cache +.mypy_cache +.cache +.env +*.log +dist +build \ No newline at end of file diff --git a/backend/app/main.py b/backend/app/main.py index 896d8e5..b74b4ed 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -38,9 +38,9 @@ scheduler = AsyncIOScheduler() @asynccontextmanager async def lifespan(app: FastAPI): # 1. 数据库建表 - print("正在初始化数据库表...") + logging.info("正在初始化数据库表...") Base.metadata.create_all(bind=engine) - print("数据库表初始化完成!") + logging.info("数据库表初始化完成!") # 2. 配置并启动定时任务 scheduler.add_job( @@ -69,9 +69,9 @@ async def lifespan(app: FastAPI): ) scheduler.start() - print(f"定时抓取任务已启动,每 {CRAWL_INTERVAL} 分钟执行一次") - print(f"AI 摘要生成任务已启动,每 {SUMMARY_INTERVAL} 分钟执行一次") - print("邮件推送调度已启动,每分钟检查一次") + logging.info(f"定时抓取任务已启动,每 {CRAWL_INTERVAL} 分钟执行一次") + logging.info(f"AI 摘要生成任务已启动,每 {SUMMARY_INTERVAL} 分钟执行一次") + logging.info("邮件推送调度已启动,每分钟检查一次") # 为了测试方便,启动时立即执行一次 # await fetch_and_save_trending_data() @@ -82,7 +82,7 @@ async def lifespan(app: FastAPI): # 优雅关闭 scheduler.shutdown() - print("定时任务已安全关闭") + logging.info("定时任务已安全关闭") # 初始化 FastAPI diff --git a/backend/dockerfile b/backend/dockerfile new file mode 100644 index 0000000..3fc42e6 --- /dev/null +++ b/backend/dockerfile @@ -0,0 +1,31 @@ +FROM python:3.11-slim AS builder + +WORKDIR /insightradar + +COPY pyproject.toml uv.lock ./ + +RUN --mount=type=cache,target=/root/.cache/uv \ + pip install --no-cache-dir uv && \ + uv sync --frozen --no-dev + +COPY app app +COPY main.py main.py + +#----------------------------------------------- + +FROM python:3.11-slim + +WORKDIR /insightradar + +# 👇 复制虚拟环境 +COPY --from=builder /insightradar/.venv /insightradar/.venv + +COPY app app +COPY main.py main.py + +# 👇 关键:用 venv 里的 python +ENV PATH="/insightradar/.venv/bin:$PATH" + +EXPOSE 8000 + +CMD ["python","main.py"] \ No newline at end of file