Skip to content

ksatriow/kstore-lab

Repository files navigation

Microservices Demo - K-Store Lab

Microservices demo dengan Product, Order, dan Notification services menggunakan Docker Compose dan Kubernetes.

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose
  • Make (optional, untuk perintah yang lebih singkat)
  • Node.js 18+ (untuk development lokal)

Menggunakan Make (Recommended)

# Setup lengkap (install dependencies, build, start, init DB, check health)
make dev

# Atau step by step:
make install      # Install dependencies
make build        # Build Docker images
make up           # Start semua services
make init-db      # Initialize database
make health       # Check service health

Tanpa Make

# Install dependencies
npm install (di setiap service directory)

# Build dan start
docker compose up --build -d

# Initialize database
docker compose exec mysql mysql -uroot -proot productdb < scripts/init-db.sql

# Check health
curl http://localhost:4020/health

πŸ“‹ Make Commands

Jalankan make help atau make untuk melihat semua perintah yang tersedia.

Quick Reference

Command Description
make dev πŸš€ Full setup (install, build, start, init db, health check)
make quick-start ⚑ Quick start (build, start, init db)
make up ▢️ Start semua services
make down ⏹️ Stop semua services
make restart πŸ”„ Restart semua services
make logs πŸ“‹ View logs semua services
make health ❀️ Check health semua services
make status πŸ“Š Show container status
make test βœ… Run tests semua services
make clean 🧹 Remove containers, volumes, images

Detailed Commands

# Development
make install          # Install dependencies
make build            # Build Docker images
make dev              # Full development setup

# Service Management
make up               # Start services
make down             # Stop services
make restart          # Restart services
make status           # Container status

# Logs
make logs             # All services
make logs-product     # Product service only
make logs-order       # Order service only
make logs-notification # Notification service only

# Testing & Quality
make test             # Run all tests
make test-product     # Test product-service
make lint             # Run linter

# Database
make init-db          # Initialize database schema
make shell-mysql      # MySQL shell
make shell-mongo      # MongoDB shell

# Utilities
make health           # Health check all services
make shell-product    # Shell into product-service
make clean            # Remove everything
make clean-volumes    # Remove volumes only

🌐 Access Services

Setelah services running, akses:

πŸ“ Project Structure

.
β”œβ”€β”€ product-service/      # Product microservice (MySQL)
β”œβ”€β”€ order-service/        # Order microservice (MongoDB + RabbitMQ)
β”œβ”€β”€ notification-service/ # Notification service (RabbitMQ consumer)
β”œβ”€β”€ docker-compose.yml    # Local development setup
β”œβ”€β”€ k8s/                  # Kubernetes manifests
β”œβ”€β”€ helm/                 # Helm charts
β”œβ”€β”€ scripts/              # Deployment scripts
β”œβ”€β”€ .github/workflows/    # CI/CD pipelines
└── Makefile             # Make commands untuk development

πŸ”„ Development Workflow

Testing

make test              # Run semua tests
make test-product      # Test product-service saja
make lint              # Run linter

Logs & Debugging

make logs              # Semua services
make logs-product      # Product service saja
make shell-mysql       # MySQL shell
make shell-mongo       # MongoDB shell

Cleanup

make down              # Stop services
make clean             # Remove semua (containers, volumes, images)
make clean-volumes    # Remove volumes saja

🚒 CI/CD

Setup GitHub Secrets

Set repository secrets di GitHub:

  • REGISTRY - Container registry URL
  • REGISTRY_USERNAME - Registry username
  • REGISTRY_PASSWORD - Registry password
  • IMAGE_PREFIX - Image prefix/namespace
  • KUBECONFIG_STAGING - Base64 kubeconfig untuk staging
  • KUBECONFIG_PRODUCTION - Base64 kubeconfig untuk production

Deployment Flow

  • Push to develop β†’ Deploy ke staging environment
  • Push to main β†’ Canary release ke production (10% β†’ 100%)

Lihat docs/CI-CD.md untuk dokumentasi lengkap.

☸️ Kubernetes Deployment

# Deploy menggunakan manifests
kubectl apply -f k8s/

# Atau menggunakan Helm
helm install micro-demo ./helm/micro-demo \
  --set product.image=your-registry/product-service \
  --set order.image=your-registry/order-service \
  --set notification.image=your-registry/notification-service

πŸ“š Documentation

Quick Start

Detailed Documentation

🎯 Features

  • βœ… Multi-stage Docker builds
  • βœ… Health checks & graceful shutdown
  • βœ… Structured logging (Winston)
  • βœ… Request validation & rate limiting
  • βœ… Connection retry logic
  • βœ… Canary deployment strategy
  • βœ… Security scanning (Trivy)
  • βœ… Test coverage reporting
  • βœ… Resource limits & monitoring

πŸ› οΈ Troubleshooting

Services tidak start

make status    # Check container status
make logs      # Check logs untuk error
make health    # Check health endpoints

Database connection error

make shell-mysql    # Test MySQL connection
make init-db        # Re-initialize database

Port sudah digunakan

Edit docker-compose.yml atau buat file .env untuk override ports.

πŸ“ License

MIT