首页/ AI 技能 / @skilllib/skill-2014279393571450881
Skill站外收录 @skilllib/skill-2014279393571450881

deployment

面向 NestJS 应用的生产级部署能力,涵盖基于多阶段构建的轻量安全 Docker 镜像制作、Node.js 内存参数精细化调优(如 max old space size)、Kubernetes 环境下的优雅停机控制,以及通过 Init Container 实现数据库迁移与主应用启动的可靠解耦。

0.0 (0) 532 次安装 原作者 编程导航
收录于 2026-01-22
开发运维 AI 技能

Skills.MD

# Deployment & Ops Standards ## **Priority: P1 (OPERATIONAL)** Docker optimization and production deployment standards for NestJS applications. ## Docker Optimization - **Multi-Stage Builds**: Mandatory. 1. **Build Stage**: Install `devDependencies`, build NestJS (`nest build`). 2. **Run Stage**: Copy only `dist` and `node_modules` (pruned), use `node:alpine`. - **Security**: Do not run as `root`. - **Dockerfile**: `USER node`. ## Runtime Tuning (Node.js) - **Memory Config**: Container memory != Node memory. - **Rule**: Explicitly set Max Old Space. - **Command**: `node --max-old-space-size=XXX dist/main` - **Calculation**: Set to ~75-80% of Kubernetes Limit. (Limit: 1GB -> OldSpace: 800MB). - **Graceful Shutdown**: - **Signal**: Listen to `SIGTERM`. - **NestJS**: `app.enableShutdownHooks()` is mandatory. - **Sleep**: Add a "Pre-Stop" sleep in K8s (5-10s) to allow Load Balancer to drain connections before Node process stops accepting traffic. ## Init Patterns - **Database Migrations**: - **Anti-Pattern**: Running migration in `main.ts` on startup. - **Pro Pattern**: Use an **Init Container** in Kubernetes that runs `npm run typeorm:migration:run` before the app container starts.

评论 0

还没有评论,来抢沙发。