准备部署

This commit is contained in:
AgentLabCn
2026-06-15 21:21:20 +08:00
parent 4167714149
commit 6c22cf9ef7
17 changed files with 898 additions and 2 deletions
+41
View File
@@ -0,0 +1,41 @@
# ============================================================
# 青叶 —— 生产环境前端镜像(多阶段构建)
# Stage 1: Node 构建 Vite 生产包
# Stage 2: Nginx 提供静态文件 + SPA 路由回退
# ------------------------------------------------------------
# 构建「域名无关」:不设置任何 VITE_* 变量。前端代码在没有 VITE_API_BASE_URL /
# VITE_WS_BASE_URL 时,会自动使用页面同源地址(API 走相对路径 /api/v1
# WebSocket 走 wss://<当前域名>)。因此同一份镜像可部署到任意域名。
# ============================================================
# ===== Stage 1: 构建 =====
FROM node:20-alpine AS builder
WORKDIR /app
# 复制依赖描述(package-lock.json 可选 —— 仓库未提交锁文件,用 npm install
COPY package.json package-lock.json* ./
# 安装依赖(使用 npm 官方源)
RUN npm install
# 复制源码(frontend/.dockerignore 已排除 node_modules / dist / .env 等)
COPY . .
# 直接调用 vite build,跳过 vue-tsc 类型检查
# (避免仓库中既有的类型错误阻断生产部署;类型检查请在 CI / 发布前单独执行)
# 如需严格的类型门禁,可改为 `npm run build`。
RUN npx vite build
# ===== Stage 2: 运行(Nginx 静态服务) =====
FROM nginx:alpine
# 复制构建产物
COPY --from=builder /app/dist /usr/share/nginx/html
# 复制 SPA 专用 Nginx 配置(createWebHistory 需要 try_files 回退)
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]