NestJS Deployment
Deployment & Ops Standards
Priority: P1 (OPERATIONAL)
Docker optimization and production deployment standards for NestJS applications.
Docker Optimization
- Multi-Stage Builds: Mandatory.
- Build Stage: Install
devDependencies, build NestJS (nest build). - Run Stage: Copy only
distandnode_modules(pruned), usenode:alpine.
- Build Stage: Install
- Security: Do not run as
root.- Dockerfile:
USER node.
- Dockerfile:
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.
- Signal: Listen to
Init Patterns
- Database Migrations:
- Anti-Pattern: Running migration in
main.tson startup. - Pro Pattern: Use an Init Container in Kubernetes that runs
npm run typeorm:migration:runbefore the app container starts.
- Anti-Pattern: Running migration in
Environment Variables & CI/CD
- CI/CD Pipelines (GitHub, GitLab, Azure, etc.):
- If you modify
src/config/env.validation.tsto add a new environment variable, you MUST map it explicitly in your deployment pipeline/infrastructure-as-code. - Platform Context:
- Cloud Run/ECS: Variables must be explicitly passed in the service definition.
- Kubernetes: New variables must be added to the
Deploymentmanifest orConfigMap/Secret. - Lambda/Serverless: Must be added to
serverless.ymlor provider console.
- Fundamental Rule: Application code configuration changes are "breaking changes" for the infrastructure layer. Never assume environment inheritance.
- If you modify
More from diegosouzapw/awesome-omni-skill
music-assistant
Control Home Assistant Music Assistant - browse library, search, play, manage preferences and moods.
12agent-code-generator
Generates Agent definitions (.md files) based on user intent and standard templates.
6terragrunt-generator
Comprehensive toolkit for generating best practice Terragrunt configurations (HCL files) following current standards and conventions. Use this skill when creating new Terragrunt resources (root configs, child modules, stacks, environment setups), or building multi-environment Terragrunt projects.
6api contract sync manager
Validate OpenAPI, Swagger, and GraphQL schemas match backend implementation. Detect breaking changes, generate TypeScript clients, and ensure API documentation stays synchronized. Use when working with API spec files (.yaml, .json, .graphql), reviewing API changes, generating frontend types, or validating endpoint implementations.
5upstash/workflow typescript sdk skill
Lightweight guidance for using the Upstash Workflow SDK to define, trigger, and manage workflows. Use this Skill whenever a user wants to create workflow endpoints, run steps, or interact with the Upstash Workflow client.
5upstash/search typescript sdk
Entry point for documentation skills covering Upstash Search quick starts, core concepts, and TypeScript SDK usage. Use when a user asks how to get started, how indexing works, or how to use the TS client.
5