# Build stage (coord-final-decisions G1: 多阶段构建首次实现即用)
FROM node:22-alpine AS builder
WORKDIR /app
RUN npm install -g pnpm
COPY package.json pnpm-lock.yaml* ./
# 复制 workspace 配置以解析 @edu/shared-ts 依赖
COPY pnpm-workspace.yaml ./
COPY packages/shared-ts ./packages/shared-ts
COPY packages/shared-proto ./packages/shared-proto
RUN pnpm install --frozen-lockfile
COPY tsconfig.json nest-cli.json ./
COPY src ./src
RUN pnpm run build

# Runtime stage
FROM node:22-alpine
WORKDIR /app
RUN npm install -g pnpm
COPY package.json pnpm-lock.yaml* ./
COPY pnpm-workspace.yaml ./
COPY packages/shared-ts ./packages/shared-ts
COPY packages/shared-proto ./packages/shared-proto
RUN pnpm install --prod --frozen-lockfile
COPY --from=builder /app/dist ./dist
EXPOSE 3009
CMD ["node", "dist/main.js"]
