test-frontend/Dockerfile

45 lines
1018 B
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.

# ============================================
# 前端 Docker 镜像 — 多阶段构建
# Stage 1: Node + pnpm 编译
# Stage 2: Nginx 托管静态文件
# ============================================
# ---- Stage 1: 编译 ----
FROM node:22-alpine AS builder
# 限制 Node 内存,防止低配服务器 OOM
ENV NODE_OPTIONS="--max-old-space-size=512"
RUN corepack enable && corepack prepare pnpm@9 --activate
WORKDIR /build
# 先复制依赖声明,利用缓存
COPY package.json pnpm-lock.yaml .npmrc ./
RUN pnpm install --frozen-lockfile
# 复制源码
COPY . .
# 构建Vite 会把 .env.production 里的变量编译进去)
RUN pnpm build
# ---- Stage 2: Nginx ----
FROM nginx:alpine
LABEL maintainer="ghb-base deploy"
# 删除默认配置
RUN rm /etc/nginx/conf.d/default.conf
# 复制自定义 nginx 配置
COPY deploy/nginx/default.conf /etc/nginx/conf.d/default.conf
# 复制构建产物
COPY --from=builder /build/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]