forked from starsvictor/NexusAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (55 loc) · 1.81 KB
/
Dockerfile
File metadata and controls
68 lines (55 loc) · 1.81 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
# Stage 1: 构建前端
FROM node:20-slim AS frontend-builder
WORKDIR /app/frontend
# 先复制 package 文件利用 Docker 缓存
COPY frontend/package.json frontend/pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile
# 复制前端源码并构建
COPY frontend/ ./
RUN pnpm run build
# Stage 2: 最终运行时镜像
FROM python:3.11-slim
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
TZ=Asia/Shanghai
# 安装 Python 依赖和浏览器依赖(合并为单一 RUN 指令以减少层数)
COPY requirements.txt .
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc \
curl \
tzdata \
chromium chromium-driver \
dbus dbus-x11 \
xvfb xauth \
libglib2.0-0 libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 \
libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 \
libxfixes3 libxrandr2 libgbm1 libasound2 libpango-1.0-0 \
libcairo2 fonts-liberation fonts-noto-cjk && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
pip install --no-cache-dir -r requirements.txt && \
apt-get purge -y gcc && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# 复制后端代码
COPY main.py .
COPY core ./core
COPY util ./util
COPY scripts ./scripts
# 从 builder 阶段只复制构建好的静态文件
COPY --from=frontend-builder /app/static ./static
# 创建数据目录
RUN mkdir -p ./data
# 复制启动脚本
COPY entrypoint.sh .
RUN chmod +x entrypoint.sh
# 声明数据卷
VOLUME ["/app/data"]
# 声明端口
EXPOSE 7860
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:7860/admin/health || exit 1
# 启动服务
CMD ["./entrypoint.sh"]