2025-12-23 05:02:10 +00:00
|
|
|
|
# 构建阶段
|
2025-12-23 05:43:01 +00:00
|
|
|
|
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/node:18-alpine AS builder
|
2025-12-23 05:02:10 +00:00
|
|
|
|
|
|
|
|
|
|
# 设置工作目录
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
|
|
# 设置 npm 使用淘宝镜像
|
|
|
|
|
|
RUN npm config set registry https://registry.npmmirror.com
|
|
|
|
|
|
|
|
|
|
|
|
# 复制 package 文件
|
|
|
|
|
|
COPY package.json yarn.lock* package-lock.json* ./
|
|
|
|
|
|
|
2025-12-25 04:41:32 +00:00
|
|
|
|
# 清理并安装依赖(解决 Alpine Linux 下 rollup 的 optional dependencies bug)
|
|
|
|
|
|
RUN rm -rf package-lock.json node_modules && npm install
|
2025-12-23 05:02:10 +00:00
|
|
|
|
|
|
|
|
|
|
# 复制项目文件
|
|
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
|
|
|
|
# 构建生产版本
|
|
|
|
|
|
RUN npm run build
|
|
|
|
|
|
|
|
|
|
|
|
# 生产阶段
|
2025-12-23 05:43:01 +00:00
|
|
|
|
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:alpine
|
2025-12-23 05:02:10 +00:00
|
|
|
|
|
|
|
|
|
|
# 复制构建产物到 nginx
|
|
|
|
|
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
|
|
|
|
|
|
|
|
|
|
|
# 复制 nginx 配置
|
|
|
|
|
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
|
|
|
|
|
|
|
|
|
|
# 暴露端口
|
|
|
|
|
|
EXPOSE 80
|
|
|
|
|
|
|
|
|
|
|
|
# 启动 nginx
|
|
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|