-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (45 loc) · 1.35 KB
/
Dockerfile
File metadata and controls
64 lines (45 loc) · 1.35 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
# MD Audit Docker Image
# 多阶段构建:前端构建 + 后端运行
# ===== 阶段1:构建前端 =====
FROM node:20-alpine AS frontend-builder
WORKDIR /app
# 复制整个项目结构(需要web目录作为输出目标)
COPY frontend/ ./frontend/
COPY web/ ./web/
WORKDIR /app/frontend
# 安装依赖
RUN npm install --legacy-peer-deps
# 构建前端(输出到 ../web/static)
RUN npm run build
# ===== 阶段2:Python运行环境 =====
FROM python:3.11-slim
WORKDIR /app
# 安装系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# 复制Python依赖
COPY requirements.txt .
# 安装Python依赖
RUN pip install --no-cache-dir -r requirements.txt
# 复制项目代码
COPY md_audit/ ./md_audit/
COPY web/ ./web/
COPY config/ ./config/
COPY setup.py ./
# 从前端构建阶段复制静态文件
COPY --from=frontend-builder /app/web/static ./web/static/
# 安装项目
RUN pip install -e .
# 创建数据目录
RUN mkdir -p /app/data /app/uploads
# 环境变量
ENV PYTHONUNBUFFERED=1
ENV MD_AUDIT_ALLOWED_ORIGINS="*"
# 暴露端口
EXPOSE 8000
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/api/health || exit 1
# 启动命令
CMD ["uvicorn", "web.main:app", "--host", "0.0.0.0", "--port", "8000"]