-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.gpu.cn
More file actions
85 lines (74 loc) · 3.29 KB
/
Copy pathDockerfile.gpu.cn
File metadata and controls
85 lines (74 loc) · 3.29 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
85
# 前后端合并部署镜像(国内镜像源版本)
# 构建命令: docker build -f Dockerfile.cn -t shipyard:latest .
#
# 注意:Flutter 前端由 CI 的 frontend:build_web job 在 gitlab-runner 机器上
# 直接编译(不再在 Docker 容器内编译 Flutter SDK),本 Dockerfile 仅将构建
# 产物 frontend/build/web 拷贝进镜像。产物需先打包成单个 tar.gz
# (COPY 目录会因大量文件导致 NAS docker daemon 卡死被杀,见 360 流水线)。
# 直接在本机手动构建时,需先执行:
# cd frontend && flutter build web --no-tree-shake-icons && tar -czf build/web.tar.gz -C build web
# 全局 ARG — 在第一个 FROM 之前声明,所有阶段可用
ARG RUNTIME_IMAGE=docker.1ms.run/python:3.11-slim
FROM ${RUNTIME_IMAGE}
# 设置工作目录
WORKDIR /app
# pip 镜像源(国内用户构建时可通过 --build-arg 覆盖)
ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
# 安装系统依赖:nginx + supervisor + git
RUN apt-get update \
&& apt-get install -y --fix-missing --no-install-recommends \
nginx \
supervisor \
git \
&& rm -rf /var/lib/apt/lists/*
# 复制后端依赖文件并安装 Python 依赖
COPY backend/requirements.txt .
RUN pip install --no-cache-dir --retries 5 -i ${PIP_INDEX_URL} -r requirements.txt
# 复制后端代码
COPY backend/ .
# 复制前端构建产物(由 CI frontend:build_web job 在 runner 上编译,
# 打包成单个 tar.gz 传入构建上下文——单文件 COPY 避免 NAS daemon 卡死)
# ⚠️ tar 包内含 web/ 顶层目录,必须 --strip-components=1 去掉前缀,
# 否则 index.html 落在 /usr/share/nginx/html/web/ 下,nginx root
# 404(366 流水线实测:镜像验证通过但部署健康检查失败)。
COPY frontend/build/web.tar.gz /tmp/web-build.tar.gz
RUN mkdir -p /usr/share/nginx/html \
&& tar -xzf /tmp/web-build.tar.gz --strip-components=1 -C /usr/share/nginx/html \
# 首帧优化:预压缩 wasm/js(canvaskit.wasm 7MB → ~2.8MB,-60%),
# 配合 nginx gzip_static 直接返回 .gz(零运行时 CPU 开销)
&& find /usr/share/nginx/html -type f \( -name '*.wasm' -o -name '*.js' -o -name '*.mjs' \) -exec gzip -k -9 {} + \
&& rm /tmp/web-build.tar.gz
# 复制 nginx 配置,并将 API 代理地址改为本地
COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf
RUN sed -i 's|http://mobile_portainer-api:8000|http://127.0.0.1:8000|g' /etc/nginx/conf.d/default.conf \
&& rm -f /etc/nginx/sites-enabled/default
# 写入 supervisord 配置
RUN printf '[supervisord]\n\
nodaemon=true\n\
user=root\n\
logfile=/dev/stdout\n\
logfile_maxbytes=0\n\
\n\
[program:backend]\n\
command=uvicorn main:app --host 127.0.0.1 --port 8000 --reload\n\
directory=/app\n\
autostart=true\n\
autorestart=true\n\
stdout_logfile=/dev/stdout\n\
stdout_logfile_maxbytes=0\n\
stderr_logfile=/dev/stderr\n\
stderr_logfile_maxbytes=0\n\
\n\
[program:nginx]\n\
command=/usr/sbin/nginx -g "daemon off;"\n\
autostart=true\n\
autorestart=true\n\
stdout_logfile=/dev/stdout\n\
stdout_logfile_maxbytes=0\n\
stderr_logfile=/dev/stderr\n\
stderr_logfile_maxbytes=0\n\
' > /etc/supervisor/conf.d/supervisord.conf
# 暴露端口
EXPOSE 80
# 启动 supervisord 管理前后端进程
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]