2025-10-20 10:34:38 +08:00
|
|
|
|
# 多阶段构建 - 构建阶段
|
|
|
|
|
|
FROM node:20-alpine AS builder
|
2025-10-13 14:37:25 +08:00
|
|
|
|
|
2025-10-27 14:56:13 +08:00
|
|
|
|
# 接受构建参数
|
|
|
|
|
|
ARG BUILD_MODE=production
|
2025-11-10 11:09:22 +08:00
|
|
|
|
ARG RAGFLOW_BASE=/ragflow/
|
|
|
|
|
|
ENV RAGFLOW_BASE=${RAGFLOW_BASE}
|
2025-10-27 14:56:13 +08:00
|
|
|
|
|
2025-10-13 14:37:25 +08:00
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
2025-11-10 16:18:37 +08:00
|
|
|
|
# 复制包管理文件(包含工作空间定义)
|
|
|
|
|
|
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
2025-10-20 10:34:38 +08:00
|
|
|
|
|
2025-11-10 11:09:22 +08:00
|
|
|
|
# 安装 pnpm 和依赖(工作空间)
|
2025-11-10 16:19:24 +08:00
|
|
|
|
RUN npm install -g pnpm
|
2025-10-13 14:37:25 +08:00
|
|
|
|
|
2025-10-20 10:34:38 +08:00
|
|
|
|
# 复制源代码
|
2025-10-13 14:37:25 +08:00
|
|
|
|
COPY . .
|
|
|
|
|
|
|
2025-11-10 16:18:37 +08:00
|
|
|
|
# 复制完工作空间后,安装并链接所有子包依赖
|
|
|
|
|
|
RUN pnpm -r install
|
|
|
|
|
|
|
2025-11-10 11:09:22 +08:00
|
|
|
|
# 设置环境文件(用于根应用的构建)
|
2025-10-27 14:56:13 +08:00
|
|
|
|
RUN if [ "$BUILD_MODE" = "flask" ]; then \
|
|
|
|
|
|
cp .env.flask .env; \
|
|
|
|
|
|
else \
|
|
|
|
|
|
cp .env.production .env; \
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
2025-11-10 16:14:04 +08:00
|
|
|
|
# 构建根 Vite 应用
|
|
|
|
|
|
RUN pnpm --filter ./ run build
|
|
|
|
|
|
|
|
|
|
|
|
# 构建 ragflow_web 前端(Umi 应用)
|
|
|
|
|
|
RUN pnpm --filter ragflow_web run build
|
2025-10-20 10:34:38 +08:00
|
|
|
|
|
|
|
|
|
|
# 生产阶段 - nginx
|
|
|
|
|
|
FROM nginx:alpine AS production
|
|
|
|
|
|
|
2025-11-10 11:09:22 +08:00
|
|
|
|
# 接受端口与子路径参数
|
2025-10-27 14:56:13 +08:00
|
|
|
|
ARG PORT=5173
|
2025-11-10 11:09:22 +08:00
|
|
|
|
ARG RAGFLOW_BASE=/ragflow/
|
2025-10-27 14:56:13 +08:00
|
|
|
|
|
2025-11-10 11:09:22 +08:00
|
|
|
|
# 复制自定义 nginx 配置,分别部署两个前端
|
2025-10-27 14:56:13 +08:00
|
|
|
|
RUN cat > /etc/nginx/conf.d/default.conf << EOF
|
2025-10-20 10:34:38 +08:00
|
|
|
|
server {
|
2025-10-27 14:56:13 +08:00
|
|
|
|
listen ${PORT};
|
2025-10-20 10:34:38 +08:00
|
|
|
|
server_name localhost;
|
|
|
|
|
|
root /usr/share/nginx/html;
|
|
|
|
|
|
index index.html;
|
|
|
|
|
|
|
2025-11-10 11:09:22 +08:00
|
|
|
|
# 根应用(Vite)SPA 路由
|
2025-10-20 10:34:38 +08:00
|
|
|
|
location / {
|
|
|
|
|
|
try_files \$uri \$uri/ /index.html;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-10 11:09:22 +08:00
|
|
|
|
# ragflow_web(Umi)部署在子路径,支持 SPA 路由
|
|
|
|
|
|
location ${RAGFLOW_BASE} {
|
|
|
|
|
|
alias /usr/share/nginx/html/ragflow/;
|
2025-11-10 16:11:21 +08:00
|
|
|
|
# 注意:使用别名目录时,SPA 回退必须指向子路径下的 index.html
|
|
|
|
|
|
# 否则会错误地回退到根应用的 index.html,导致页面刷新后空白或错路由
|
|
|
|
|
|
try_files \$uri \$uri/ ${RAGFLOW_BASE}index.html;
|
2025-11-10 11:09:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:34:38 +08:00
|
|
|
|
# 静态资源缓存
|
|
|
|
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
|
|
|
|
|
expires 1y;
|
|
|
|
|
|
add_header Cache-Control "public, immutable";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# 安全头
|
|
|
|
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
|
|
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
|
|
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
|
|
|
|
|
|
|
|
|
|
# Gzip 压缩
|
|
|
|
|
|
gzip on;
|
|
|
|
|
|
gzip_vary on;
|
|
|
|
|
|
gzip_min_length 1024;
|
|
|
|
|
|
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
|
|
|
|
|
|
}
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
2025-11-10 11:09:22 +08:00
|
|
|
|
# 从构建阶段复制构建产物:根应用与 ragflow_web
|
2025-10-20 10:34:38 +08:00
|
|
|
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
2025-11-10 11:09:22 +08:00
|
|
|
|
COPY --from=builder /app/ragflow_web/dist /usr/share/nginx/html/ragflow
|
2025-10-20 10:34:38 +08:00
|
|
|
|
|
2025-11-10 11:09:22 +08:00
|
|
|
|
# 暴露端口
|
2025-10-27 14:56:13 +08:00
|
|
|
|
EXPOSE ${PORT}
|
2025-10-13 14:37:25 +08:00
|
|
|
|
|
2025-10-20 10:34:38 +08:00
|
|
|
|
# 启动 nginx
|
|
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|