mirror of
https://github.com/stardrophere/InsightRadar.git
synced 2026-06-05 23:07:51 +08:00
后端的docker构建
This commit is contained in:
+4
-1
@@ -186,4 +186,7 @@ cython_debug/
|
|||||||
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
||||||
# refer to https://docs.cursor.com/context/ignore-files
|
# refer to https://docs.cursor.com/context/ignore-files
|
||||||
.cursorignore
|
.cursorignore
|
||||||
.cursorindexingignore
|
.cursorindexingignore
|
||||||
|
|
||||||
|
**/data/*
|
||||||
|
**/docker/*
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
.venv
|
||||||
|
.git
|
||||||
|
__pycache__
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.pyd
|
||||||
|
.pytest_cache
|
||||||
|
.mypy_cache
|
||||||
|
.cache
|
||||||
|
.env
|
||||||
|
*.log
|
||||||
|
dist
|
||||||
|
build
|
||||||
+6
-6
@@ -38,9 +38,9 @@ scheduler = AsyncIOScheduler()
|
|||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
# 1. 数据库建表
|
# 1. 数据库建表
|
||||||
print("正在初始化数据库表...")
|
logging.info("正在初始化数据库表...")
|
||||||
Base.metadata.create_all(bind=engine)
|
Base.metadata.create_all(bind=engine)
|
||||||
print("数据库表初始化完成!")
|
logging.info("数据库表初始化完成!")
|
||||||
|
|
||||||
# 2. 配置并启动定时任务
|
# 2. 配置并启动定时任务
|
||||||
scheduler.add_job(
|
scheduler.add_job(
|
||||||
@@ -69,9 +69,9 @@ async def lifespan(app: FastAPI):
|
|||||||
)
|
)
|
||||||
|
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
print(f"定时抓取任务已启动,每 {CRAWL_INTERVAL} 分钟执行一次")
|
logging.info(f"定时抓取任务已启动,每 {CRAWL_INTERVAL} 分钟执行一次")
|
||||||
print(f"AI 摘要生成任务已启动,每 {SUMMARY_INTERVAL} 分钟执行一次")
|
logging.info(f"AI 摘要生成任务已启动,每 {SUMMARY_INTERVAL} 分钟执行一次")
|
||||||
print("邮件推送调度已启动,每分钟检查一次")
|
logging.info("邮件推送调度已启动,每分钟检查一次")
|
||||||
|
|
||||||
# 为了测试方便,启动时立即执行一次
|
# 为了测试方便,启动时立即执行一次
|
||||||
# await fetch_and_save_trending_data()
|
# await fetch_and_save_trending_data()
|
||||||
@@ -82,7 +82,7 @@ async def lifespan(app: FastAPI):
|
|||||||
|
|
||||||
# 优雅关闭
|
# 优雅关闭
|
||||||
scheduler.shutdown()
|
scheduler.shutdown()
|
||||||
print("定时任务已安全关闭")
|
logging.info("定时任务已安全关闭")
|
||||||
|
|
||||||
|
|
||||||
# 初始化 FastAPI
|
# 初始化 FastAPI
|
||||||
|
|||||||
@@ -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"]
|
||||||
Reference in New Issue
Block a user