Dockerfile 794 B

123456789101112131415161718192021222324252627
  1. # 合并构建用户端前端和管理后台前端
  2. # 阶段1: 构建用户端前端
  3. FROM node:18-alpine AS user-builder
  4. WORKDIR /app
  5. COPY frontend/package.json ./
  6. RUN npm install --registry https://registry.npmmirror.com
  7. COPY frontend/ .
  8. ENV VITE_API_BASE_URL=
  9. RUN npm run build
  10. # 阶段2: 构建管理后台前端
  11. FROM node:18-alpine AS admin-builder
  12. WORKDIR /app
  13. COPY admin-frontend/package.json ./
  14. RUN npm install --registry https://registry.npmmirror.com
  15. COPY admin-frontend/ .
  16. ENV VITE_API_BASE_URL=
  17. ENV VITE_API_BASE=
  18. RUN npm run build
  19. # 阶段3: Nginx 运行
  20. FROM nginx:alpine
  21. COPY nginx.conf /etc/nginx/conf.d/default.conf
  22. COPY --from=user-builder /app/dist /usr/share/nginx/user
  23. COPY --from=admin-builder /app/dist /usr/share/nginx/admin
  24. EXPOSE 80
  25. CMD ["nginx", "-g", "daemon off;"]