chore: 优化 Docker 配置,添加生产环境部署脚本和文档
All checks were successful
Deploy to Server / deploy (push) Successful in 19s

This commit is contained in:
爽哒哒
2026-03-18 22:48:36 +08:00
parent f655aa0ede
commit e3a620b395
8 changed files with 610 additions and 43 deletions

View File

@@ -1,13 +1,10 @@
# Use an official Node runtime as a parent image
FROM node:22-alpine
# 构建阶段
FROM node:20-alpine AS builder
# Set working directory
# 设置工作目录
WORKDIR /app
# Install build dependencies for native modules
RUN apk add --no-cache autoconf automake libtool make g++ zlib-dev nasm python3
# Install dependencies
# 安装依赖
COPY package.json package-lock.json* ./
RUN npm install --registry=https://registry.npmmirror.com
@@ -16,14 +13,22 @@ COPY . .
# 接收构建参数
ARG VITE_API_URL=/api
# 设置环境变量供构建时使用
ENV VITE_API_URL=$VITE_API_URL
ENV VITE_API_URL=${VITE_API_URL}
# 构建生产环境代码
RUN npm run build
# 暴露应用运行的端口
EXPOSE 15173
# 生产阶段 - 使用 Nginx
FROM nginx:alpine
# 启动应用 (Preview 模式)
CMD ["npm", "run", "preview", "--", "--host", "0.0.0.0", "--port", "15173"]
# 复制 Nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 从构建阶段复制构建产物
COPY --from=builder /app/dist /usr/share/nginx/html
# 暴露端口
EXPOSE 80
# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]