Files
aiot-platform-ui/Dockerfile
lzh 25ebd947b8
Some checks failed
Web UI CI/CD / build-and-deploy (push) Has been cancelled
chore: 改为本地构建,传dist文件到服务端
2025-12-23 13:43:32 +08:00

68 lines
2.2 KiB
Docker
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
# 设置工作目录
WORKDIR /app
# ------------------------------
# 设置 npm / pnpm registry
# ------------------------------
# npm 镜像源(淘宝镜像加速)
RUN npm config set registry https://registry.npmmirror.com && \
echo "registry=https://registry.npmmirror.com" > ~/.npmrc
# pnpm registry 指向 Verdaccio
ARG PNPM_REGISTRY=http://1Panel-verdaccio-Ynee:4873/
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable && corepack prepare pnpm@10.22.0 --activate
RUN pnpm config set registry $PNPM_REGISTRY
RUN pnpm config set store-dir /pnpm/store
# ------------------------------
# Docker BuildKit 缓存 pnpm store
# ------------------------------
# 复制依赖描述文件,利用缓存层
COPY package.json pnpm-lock.yaml turbo.json pnpm-workspace.yaml ./
# 复制源码文件
COPY packages packages
COPY apps apps
COPY internal internal
# 安装依赖
# network-concurrency 限制并发下载,降低带宽占用
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
pnpm install --frozen-lockfile --network-concurrency 2
# 限制turbo并发构建降低资源占用仅CI/CD构建时生效
# 并发数设为1Vite构建阶段非常消耗资源串行构建更稳定
# 降低Node.js内存限制避免占用过多内存影响其他服务服务器8GB内存
# 限制为1024MB为系统和其他服务预留更多内存约7GB
# 限制Node.js线程池大小减少并发线程数降低CPU占用
ENV NODE_OPTIONS=--max-old-space-size=1024
ENV UV_THREADPOOL_SIZE=2
# 设置垃圾回收更频繁,减少内存峰值
ENV NODE_OPTIONS="$NODE_OPTIONS --expose-gc"
RUN pnpm exec turbo build --filter=@vben/web-antd --concurrency=1
# ==============================
# 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
# 复制构建产物
COPY --from=builder /app/apps/web-antd/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]