feat(student-portal): 完整实现 student-portal 微前端
包含 src 全部实现、Dockerfile、配置文件、contracts 包等
This commit is contained in:
58
apps/student-portal/Dockerfile
Normal file
58
apps/student-portal/Dockerfile
Normal file
@@ -0,0 +1,58 @@
|
||||
# 多阶段构建:student-portal 生产镜像(ai14,P6 硬化)
|
||||
# 用法:docker build -t edu/student-portal:latest -f apps/student-portal/Dockerfile .
|
||||
# 端口:4001(004 §1.2 强制 4 端 4000-4003)
|
||||
|
||||
# ============ Stage 1: 装依赖 ============
|
||||
FROM node:22-alpine AS deps
|
||||
WORKDIR /app
|
||||
|
||||
# 启用 pnpm
|
||||
RUN corepack enable && corepack prepare pnpm@9.12.0 --activate
|
||||
|
||||
# 先拷依赖清单,利用缓存
|
||||
COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml* ./
|
||||
COPY apps/student-portal/package.json ./apps/student-portal/
|
||||
# 安装依赖(含 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: 运行时 ============
|
||||
FROM node:22-alpine AS runner
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
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
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/apps/student-portal/next.config.js ./next.config.js
|
||||
|
||||
USER nextjs
|
||||
EXPOSE 4001
|
||||
|
||||
# 健康检查(liveness)
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
|
||||
CMD wget --quiet --spider http://localhost:4001/api/health || exit 1
|
||||
|
||||
CMD ["node_modules/.bin/next", "start", "-p", "4001"]
|
||||
Reference in New Issue
Block a user