diff --git a/Dockerfile b/Dockerfile index 90908a86..2576e61c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,45 +1,21 @@ -# 阶段1: 构建阶段 -FROM node:24.7.0-slim AS builder +# 构建阶段 +FROM node:20-alpine AS builder WORKDIR /app - -RUN npm config set registry https://registry.npmmirror.com \ - && npm install -g pnpm \ - && pnpm config set registry https://registry.npmmirror.com - -# 复制依赖文件 COPY package.json pnpm-lock.yaml ./ - -RUN pnpm install --force \ - && pnpm add -D @unocss/eslint-plugin@0.57.7 - +RUN npm install -g pnpm +RUN pnpm install COPY . . +RUN pnpm run build:prod # 生成 dist-prod 目录 -# 【新增1】创建缺失的cancel.svg文件(解决文件不存在错误) -RUN mkdir -p /app/src/assets/svgs/bpm/ \ - && echo '' > /app/src/assets/svgs/bpm/cancel.svg - -RUN pnpm eslint --fix /app/src/components/Table/src/Table.vue \ - && rm -rf /tmp/* - -RUN ESLINT_NO_DEV_ERRORS=true pnpm run build:prod - -RUN ls -la /app/ - -# 阶段2: 生产运行阶段 -FROM node:24.7.0-slim - -WORKDIR /app - -RUN npm config set registry https://registry.npmmirror.com \ - && npm install -g pnpm \ - && pnpm config set registry https://registry.npmmirror.com - -COPY --from=builder /app . +# 运行阶段 +FROM nginx:alpine -ENV PORT 8088 -ENV NODE_ENV production +# 关键:复制的是 dist-prod 而不是 dist +COPY --from=builder /app/dist-prod /usr/share/nginx/html -EXPOSE 8088 +# 复制 Nginx 配置(确保这个文件存在) +COPY nginx.conf /etc/nginx/nginx.conf -CMD ["pnpm", "vite", "preview", "--port", "8088", "--outDir", "dist-prod"] \ No newline at end of file +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..050079a3 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,28 @@ +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server { + listen 80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; + } + + # 代理 API 请求到后端容器 + location /api { + proxy_pass http://besure_server:48081; # ← Docker Compose 服务名 + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } +} \ No newline at end of file