Files
aiot-platform-ui/Dockerfile
2025-12-18 13:36:13 +08:00

52 lines
1.4 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 1. 构建阶段
FROM node:20-alpine AS builder
# 设置 npm 和 pnpm 镜像源为淘宝源(加速下载)
RUN npm config set registry https://registry.npmmirror.com && \
echo "registry=https://registry.npmmirror.com" > ~/.npmrc
WORKDIR /app
# 启用 pnpm (使用 corepack)
# 设置环境变量让 Corepack 也从镜像源下载
ENV COREPACK_NPM_REGISTRY=https://registry.npmmirror.com
RUN corepack enable && corepack prepare pnpm@10.22.0 --activate
# 配置 pnpm 使用淘宝镜像源
RUN pnpm config set registry https://registry.npmmirror.com
# 单独复制依赖描述文件,利用 Docker 缓存层
# 先只复制这些文件如果它们没变Docker 会复用缓存,跳过后续步骤
COPY package.json pnpm-lock.yaml turbo.json ./
# 复制所有 package.jsonMonorepo 需要)
COPY packages packages
COPY apps apps
# 安装依赖
# 使用 --frozen-lockfile 确保版本一致
RUN pnpm install --frozen-lockfile
# 构建指定项目 (根据 package.json 里的 scripts)
# 这里我们构建 antd 版本
RUN pnpm build:antd
# 2. 运行阶段
FROM nginx:alpine
# 移除默认配置
RUN rm /etc/nginx/conf.d/default.conf
# 复制自定义 Nginx 配置
COPY apps/web-antd/nginx.conf /etc/nginx/conf.d/default.conf
# 复制构建产物
# 注意Vben 5 的产物目录通常在 apps/web-antd/dist
COPY --from=builder /app/apps/web-antd/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]