Files
Edu/services/student-bff/Dockerfile

54 lines
1.9 KiB
Docker
Raw Permalink 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.
# Build stage
FROM node:22-alpine AS builder
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@11.13.0 --activate
# 复制 workspace 配置 + tsconfig.base.json (shared-ts tsconfig 继承自它, 提供 skipLibCheck 等)
COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml tsconfig.base.json ./
# 复制 shared-protogRPC proto-loader 运行时加载)
COPY packages/shared-proto ./packages/shared-proto
# 复制 shared-tsGraphQL schema 文件 + BFF 抽象)
COPY packages/shared-ts ./packages/shared-ts
# 复制 student-bff 源码
COPY services/student-bff ./services/student-bff
# 安装依赖(仅 student-bff 及其 workspace 依赖,过滤掉 scripts/arch-scan 的 better-sqlite3
RUN pnpm install --frozen-lockfile --filter @edu/student-bff... --ignore-scripts
# 构建 shared-tsstudent-bff 运行时依赖 @edu/shared-ts/bff 的 dist 产物)
WORKDIR /app/packages/shared-ts
RUN pnpm build
# 构建 student-bff
WORKDIR /app/services/student-bff
RUN pnpm build
# Runtime stage
FROM node:22-alpine
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@11.13.0 --activate
# 复制 workspace 配置
COPY package.json pnpm-lock.yaml* pnpm-workspace.yaml tsconfig.base.json ./
# 复制 shared-proto + shared-ts 源码(运行时需要 schema + BFF 抽象)
COPY packages/shared-proto ./packages/shared-proto
COPY packages/shared-ts ./packages/shared-ts
# 复制 shared-ts 构建产物runtime 需要 @edu/shared-ts/bff 的 dist
COPY --from=builder /app/packages/shared-ts/dist ./packages/shared-ts/dist
# 复制 student-bff含 package.json 用于依赖解析)
COPY services/student-bff ./services/student-bff
WORKDIR /app/services/student-bff
RUN pnpm install --prod --frozen-lockfile --filter @edu/student-bff... --ignore-scripts
# 复制构建产物
COPY --from=builder /app/services/student-bff/dist ./dist
EXPOSE 3009
CMD ["node", "dist/main.js"]