Files
aiot-platform-ui/Dockerfile
lzh 874c06fa51
All checks were successful
Web UI CI/CD / build-and-deploy (push) Successful in 3m31s
fix: 优化构建速度,后端容器名
2025-12-18 14:03:54 +08:00

58 lines
1.8 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 会复用缓存,跳过后续步骤
# pnpm-workspace.yaml 包含 catalog 配置pnpm 需要它来解析 catalog: 引用
COPY package.json pnpm-lock.yaml turbo.json pnpm-workspace.yaml ./
# 复制所有 package.jsonMonorepo 需要)
# internal 目录包含构建工具包(@vben/tsconfig, @vben/vite-config 等),构建时需要
COPY packages packages
COPY apps apps
COPY internal internal
# 安装依赖
# 使用 BuildKit 缓存挂载加速依赖安装
# 缓存 pnpm store即使 package.json 变了,已下载的包也能复用
# pnpm store 默认路径:~/.local/share/pnpm/store (Linux)
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
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;"]