Part 5: DevOps, Deployment, and Security

Introduction

A great app running on your laptop is worthless if users can't access it. In this part, I'll walk through my production deployment process—from containerization to CI/CD to monitoring.

We'll deploy the POS API from Part 4 to Kubernetes with proper security and observability.

Containerization with Docker

Multi-Stage Dockerfile

# Build stage
FROM node:20-alpine AS builder

WORKDIR /app

# Copy package files
COPY package*.json ./
COPY prisma ./prisma/

# Install dependencies (including dev dependencies)
RUN npm ci

# Copy source code
COPY . .

# Build TypeScript
RUN npm run build

# Generate Prisma client
RUN npx prisma generate

# Production stage
FROM node:20-alpine AS production

# Security: Run as non-root user
RUN addgroup -g 1001 -S nodejs && \
    adduser -S nodejs -u 1001

WORKDIR /app

# Copy package files and install prod dependencies only
COPY package*.json ./
RUN npm ci --only=production && npm cache clean --force

# Copy built app from builder
COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
COPY --from=builder --chown=nodejs:nodejs /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder --chown=nodejs:nodejs /app/prisma ./prisma

# Set user
USER nodejs

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
  CMD node -e "require('http').get('http://localhost:3000/health', (r) => r.statusCode === 200 ? process.exit(0) : process.exit(1))"

EXPOSE 3000

CMD ["node", "dist/main.js"]

Docker Compose for Local Development

Testing the Container

CI/CD Pipeline with GitHub Actions

Pipeline Architecture

spinner

GitHub Actions Workflow

Kubernetes Deployment

Deployment Manifest

Service and Ingress

ConfigMap and Secrets

Note: In production, use external secret managers like:

  • AWS Secrets Manager

  • HashiCorp Vault

  • Sealed Secrets

Security Hardening

Network Policies

Pod Security Policy

Monitoring and Observability

Exposing Metrics

Metrics Middleware

Grafana Dashboard

Key Takeaways

  1. Containerize properly: Multi-stage builds, non-root user, health checks

  2. Automate deployment: CI/CD prevents human error

  3. Security first: Network policies, secrets management, image scanning

  4. Monitor everything: Metrics, logs, traces

  5. Plan for failure: Rollback strategy, health checks, readiness probes

What's Next

In Part 6 (final), we'll cover:

  • Documentation strategies

  • Common pitfalls when using AI

  • How software development has changed

  • What's next for developers


DevOps isn't a job title—it's a mindset. Automate, secure, monitor. See you in the final part.

Last updated