feat(student-portal): 完成Docker构建验证+全量测试通过+nextstep下游依赖文档

This commit is contained in:
SpecialX
2026-07-13 16:49:31 +08:00
parent 64b2016fa8
commit 40f07b7a16
27 changed files with 4742 additions and 31 deletions

View File

@@ -2,35 +2,43 @@
# 用法docker build -t edu/student-portal:latest -f apps/student-portal/Dockerfile .
# 端口4001004 §1.2 强制 4 端 4000-4003
# ============ Stage 1: 装依赖 ============
FROM node:22-alpine AS deps
# ============ Stage 1: 构建 ============
FROM node:22-alpine AS builder
WORKDIR /app
# 启用 pnpm
RUN corepack enable && corepack prepare pnpm@9.12.0 --activate
# 先拷依赖清单,利用缓存
# 构建参数:控制 MSW mock 是否启用(生产构建默认 disabled
# --build-arg NEXT_PUBLIC_API_MOCKING=disabled
ARG NEXT_PUBLIC_API_MOCKING=disabled
ENV NEXT_PUBLIC_API_MOCKING=${NEXT_PUBLIC_API_MOCKING}
# MF 默认关闭(独立壳模式)
ARG NEXT_PUBLIC_MF_ENABLED=false
ENV NEXT_PUBLIC_MF_ENABLED=${NEXT_PUBLIC_MF_ENABLED}
# GraphQL 端点
ARG NEXT_PUBLIC_GRAPHQL_ENDPOINT=/api/v1/student/graphql
ENV NEXT_PUBLIC_GRAPHQL_ENDPOINT=${NEXT_PUBLIC_GRAPHQL_ENDPOINT}
# 拷贝整个 workspace 配置 + 源码pnpm workspace 需要所有包的 package.json + 源码)
COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml* ./
COPY apps/student-portal/package.json ./apps/student-portal/
COPY tsconfig.base.json ./
COPY apps/student-portal ./apps/student-portal
# 拷贝 workspace 共享包student-portal 的 transpilePackages 依赖)
COPY packages/contracts ./packages/contracts
COPY packages/hooks ./packages/hooks
COPY packages/ui-components ./packages/ui-components
COPY packages/ui-tokens ./packages/ui-tokens
COPY packages/shared-ts ./packages/shared-ts
# 安装依赖(含 devDependencies构建需要
RUN pnpm install --filter @edu/student-portal... --frozen-lockfile || pnpm install --filter @edu/student-portal...
# ============ Stage 2: 构建 ============
FROM node:22-alpine AS builder
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@9.12.0 --activate
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/apps/student-portal/node_modules ./apps/student-portal/node_modules
COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml* ./
COPY apps/student-portal ./apps/student-portal
# 构建生产产物(禁用 telemetry
ENV NEXT_TELEMETRY_DISABLED=1
RUN pnpm --filter @edu/student-portal run build
# ============ Stage 3: 运行时 ============
# ============ Stage 2: 运行时 ============
FROM node:22-alpine AS runner
WORKDIR /app
@@ -41,12 +49,14 @@ ENV PORT=4001
# 非 root 用户运行
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
# 拷构建产物与必要清单
COPY --from=builder /app/apps/student-portal/package.json ./package.json
COPY --from=builder /app/apps/student-portal/.next ./.next
COPY --from=builder /app/apps/student-portal/public ./public
# 拷构建产物 + node_modules保留 workspace 目录结构以保持 pnpm 符号链接)
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/apps/student-portal/next.config.js ./next.config.js
COPY --from=builder /app/apps/student-portal/package.json ./apps/student-portal/package.json
COPY --from=builder /app/apps/student-portal/.next ./apps/student-portal/.next
COPY --from=builder /app/apps/student-portal/node_modules ./apps/student-portal/node_modules
COPY --from=builder /app/apps/student-portal/next.config.js ./apps/student-portal/next.config.js
WORKDIR /app/apps/student-portal
USER nextjs
EXPOSE 4001