3.3 KiB
3.3 KiB
name, description
| name | description |
|---|---|
| deployment-patterns | CI/CD pipeline patterns, Docker containerization, health checks, blue-green deployment, canary releases, rollback strategies. Use when setting up deployment pipelines, containerizing apps, or planning release strategies. |
Deployment Patterns
Based on ECC deployment-patterns skill.
CI/CD Pipeline Structure
lint → test → build → security-scan → staging-deploy → e2e-test → prod-deploy
Essential Steps
- Lint: Code style, static analysis
- Test: Unit + integration tests
- Build: Docker image, compile
- Security: Dependency scan, SAST
- Staging: Deploy to staging environment
- E2E: Run end-to-end tests on staging
- Production: Deploy to production (with rollback plan)
Health Checks
Liveness Probe (Am I alive?)
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
Readiness Probe (Am I ready to serve?)
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
Deployment Strategies
Blue-Green (Zero Downtime)
- Run current version on "blue"
- Deploy new version to "green"
- Test green thoroughly
- Switch DNS/load-balancer to green
- Keep blue for rollback
Canary (Gradual Rollout)
- Deploy to small % of users (5%)
- Monitor error rates, latency
- If OK → increase to 25%, then 50%, then 100%
- If problems → rollback immediately
Rolling (Default for Kubernetes)
- Replace pods one by one
- Built-in to Kubernetes
- Can have mixed versions briefly
Docker Patterns
Multi-Stage Build
FROM node:20-alpine AS builder
COPY . .
RUN npm ci --production=false
RUN npm run build
FROM node:20-alpine AS runtime
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./
RUN npm ci --only=production
EXPOSE 3000
CMD ["node", "dist/main.js"]
Docker Compose
services:
app:
build: .
ports: ["3000:3000"]
depends_on: [db, redis]
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/healthz"]
db:
image: postgres:16
volumes: [pgdata:/var/lib/postgresql/data]
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
Rollback Strategy
Pre-deployment checklist
- Health checks configured
- Logs being captured
- Metrics dashboards ready
- Rollback procedure documented
- Last known good version tagged
Quick rollback commands
# Kubernetes
kubectl rollout undo deployment/app
# Docker Compose
docker compose down && docker compose up -d --no-build # use previous image
# Nginx
ln -sfn /var/www/blue /var/www/current && nginx -s reload
Environment Configuration
- Use environment variables for all config
- No hardcoded secrets, URLs, ports
- Separate configs: dev, staging, production
- Use .env files for local, vault/K8s secrets for production
Checklist
- CI pipeline covers lint → test → build → scan → deploy
- Health checks (liveness + readiness) defined
- Deployment strategy chosen (blue-green, canary, rolling)
- Rollback procedure tested
- Environment variables managed securely
- Docker image is multi-stage (small final image)
- Logs structured (JSON format with correlation IDs)