forked from ZhuLinsen/daily_stock_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
84 lines (65 loc) · 2.1 KB
/
Copy pathDockerfile
File metadata and controls
84 lines (65 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# ===================================
# A股自选股智能分析系统 - Docker 镜像
# ===================================
# 多阶段构建:前端打包 + 后端运行
FROM node:20-slim AS web-builder
WORKDIR /app/apps/dsa-web
COPY apps/dsa-web/package.json apps/dsa-web/package-lock.json ./
RUN npm ci
COPY apps/dsa-web/ ./
RUN npm run build
# Pin to bookworm: wkhtmltopdf was removed from Debian testing (2025)
FROM python:3.11-slim-bookworm
# 设置工作目录
WORKDIR /app
# 设置时区为上海
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 安装系统依赖(wkhtmltopdf 含 wkhtmltoimage,用于 Markdown 转图片 Issue #289)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
curl \
wkhtmltopdf \
fontconfig \
libjpeg62-turbo \
libxrender1 \
libxext6 \
&& rm -rf /var/lib/apt/lists/*
# 创建非 root 用户 (UID 1000)
RUN groupadd -g 1000 dsa && \
useradd -u 1000 -g dsa -m dsa
# 复制依赖文件
COPY requirements.txt .
# 安装 Python 依赖
RUN pip install --no-cache-dir -r requirements.txt
# 复制应用代码
COPY *.py ./
COPY api/ ./api/
COPY data_provider/ ./data_provider/
COPY bot/ ./bot/
COPY patch/ ./patch/
COPY src/ ./src/
COPY strategies/ ./strategies/
COPY --from=web-builder /app/static ./static/
# 确保数据目录存在并授权给 non-root 用户
RUN mkdir -p /app/data /app/logs /app/reports && \
chown -R dsa:dsa /app
# 设置环境变量默认值
ENV PYTHONUNBUFFERED=1
ENV LOG_DIR=/app/logs
ENV DATABASE_PATH=/app/data/stock_analysis.db
# Web/API service
ENV WEBUI_HOST=0.0.0.0
ENV API_PORT=8000
# 切换到 non-root 用户
USER dsa
# 暴露 API 端口
EXPOSE 8000
# 数据卷(持久化数据)
VOLUME ["/app/data", "/app/logs", "/app/reports"]
# 健康检查(FastAPI 模式)
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8000/api/health || curl -f http://localhost:8000/health \
|| python -c "import sys; sys.exit(0)"
# 默认命令(可被覆盖)
CMD ["python", "main.py", "--schedule"]