# Build stage FROM node:20-alpine AS builder WORKDIR /app # Install pnpm RUN corepack enable && corepack prepare pnpm@9.15.0 --activate # Copy package files COPY package.json pnpm-lock.yaml* ./ # Install dependencies (ignore optional native modules) RUN pnpm install --frozen-lockfile --ignore-scripts || pnpm install --ignore-scripts # Copy source COPY . . # Build RUN pnpm build # Production stage FROM node:20-alpine AS runner WORKDIR /app # Install pnpm RUN corepack enable && corepack prepare pnpm@9.15.0 --activate # Create data directory for bot storage RUN mkdir -p /app/data # Copy package files COPY package.json pnpm-lock.yaml* ./ # Install production dependencies only (ignore optional native modules) RUN pnpm install --prod --frozen-lockfile --ignore-scripts || pnpm install --prod --ignore-scripts # Copy built files COPY --from=builder /app/dist ./dist # Create non-root user RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nestjs RUN chown -R nestjs:nodejs /app USER nestjs # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3311/health || exit 1 EXPOSE 3311 CMD ["node", "dist/main.js"]