# harbor-ci-cd-demo Learning Harbor + Gitea Actions CI/CD integration # ๐Ÿ–ฅ๏ธ System Monitoring Dashboard A comprehensive Node.js application for real-time system monitoring with a beautiful web dashboard. Built to demonstrate Harbor CI/CD integration with Gitea Actions. ## โœจ Features - **๐Ÿš€ Real-time System Monitoring**: CPU, memory, disk usage, and load averages - **๐Ÿ“Š Interactive Dashboard**: Beautiful, responsive web interface with live data - **๐Ÿ” Health Checks**: Kubernetes-style readiness and liveness probes - **๐Ÿ“ก REST API**: Complete API for system metrics and monitoring data - **๐Ÿงช Comprehensive Testing**: Unit tests with coverage reporting - **๐Ÿ”’ Security**: Helmet.js security headers, input validation - **๐Ÿ“ˆ Metrics Collection**: Request tracking, response times, error rates - **๐Ÿณ Container Ready**: Optimized Docker configuration - **โšก Production Ready**: Proper error handling, logging, and monitoring ## ๐Ÿš€ Quick Start ### Prerequisites - Node.js 18+ - Docker (optional) - Git ### Local Development ```bash # Clone the repository git clone https://git.maverickapplications.com/[username]/harbor-ci-cd-demo.git cd harbor-ci-cd-demo # Install dependencies npm install # Start development server npm run dev # Open your browser open http://localhost:3000 ``` ### Using Docker ```bash # Build and run with Docker docker build -t monitoring-dashboard . docker run -p 3000:3000 monitoring-dashboard # Or use Docker Compose docker-compose up ``` ## ๐Ÿ“š API Documentation ### System Information - **GET /api/system** - System hardware and OS information - **GET /api/memory** - Memory usage statistics - **GET /api/process** - Node.js process information - **GET /api/metrics** - Application metrics and counters ### Health Checks - **GET /health** - Basic health status - **GET /health/detailed** - Comprehensive health information - **GET /health/ready** - Readiness probe (Kubernetes compatible) - **GET /health/live** - Liveness probe (Kubernetes compatible) ### Testing - **GET /api/test** - API connectivity test endpoint ## ๐Ÿงช Testing ```bash # Run all tests npm test # Run tests with coverage npm run test:coverage # Run tests in watch mode npm run test:watch # Run linting npm run lint # Fix linting issues npm run lint:fix ``` ## ๐Ÿ“Š Dashboard Features ### System Overview - Hostname, platform, and architecture - CPU cores and load averages - Total system memory - System uptime - Node.js version information ### Memory Monitoring - System memory usage with visual bars - Process heap memory tracking - RSS and external memory statistics - Warning indicators for high usage ### Health Status - Overall system health indicator - Memory status monitoring - Process uptime tracking - Environment information ### API Metrics - Request counters by endpoint - Average response times - Service uptime tracking - Real-time performance data ### Process Information - Process ID and parent process - Working directory - Node.js version details - Environment configuration ## ๐Ÿ”ง Configuration ### Environment Variables ```bash PORT=3000 # Server port (default: 3000) NODE_ENV=production # Environment mode ``` ### Docker Environment ```dockerfile ENV NODE_ENV=production ENV PORT=3000 EXPOSE 3000 ``` ## ๐Ÿณ Container Deployment ### Building the Image ```bash # Build locally docker build -t monitoring-dashboard:latest . # Build for Harbor registry docker build -t registry.maverickapplications.com/infrastructure/monitoring-dashboard:latest . ``` ### Running in Production ```bash # Run with resource limits docker run -d \ --name monitoring-dashboard \ --memory=512m \ --cpus=1 \ -p 3000:3000 \ -e NODE_ENV=production \ --restart=unless-stopped \ monitoring-dashboard:latest ``` ## ๐Ÿ”„ CI/CD Pipeline This application includes a complete CI/CD pipeline with: - **๐Ÿงช Automated Testing**: Unit tests and coverage reporting - **๐Ÿ”’ Security Scanning**: npm audit and vulnerability checks - **๐Ÿ—๏ธ Multi-platform Builds**: AMD64 and ARM64 support - **๐Ÿ“ฆ Harbor Integration**: Automatic image building and pushing - **๐Ÿ›ก๏ธ Vulnerability Scanning**: Trivy security scanning - **๐Ÿš€ Automated Deployment**: Environment-based deployment - **๐Ÿ“‹ SBOM Generation**: Software Bill of Materials ### Pipeline Stages 1. **Test & Lint** - Code quality and functionality validation 2. **Security Scan** - Dependency vulnerability checking 3. **Build & Push** - Multi-platform Docker image creation 4. **Image Scan** - Container vulnerability assessment 5. **Deploy** - Environment-specific deployment 6. **Cleanup** - Resource management ## ๐Ÿ“ˆ Monitoring & Observability ### Health Check Endpoints ```bash # Basic health check curl http://localhost:3000/health # Detailed health information curl http://localhost:3000/health/detailed # Kubernetes readiness probe curl http://localhost:3000/health/ready # Kubernetes liveness probe curl http://localhost:3000/health/live ``` ### Metrics Collection The application automatically tracks: - HTTP request counters - Response time histograms - Error rate monitoring - Memory usage patterns - System resource utilization ### Dashboard Access - **Main Dashboard**: http://localhost:3000 - **API Documentation**: http://localhost:3000/api - **Health Status**: http://localhost:3000/health/detailed ## ๐Ÿ› ๏ธ Development ### Project Structure ``` harbor-ci-cd-demo/ โ”œโ”€โ”€ .gitea/workflows/ # CI/CD pipeline configuration โ”œโ”€โ”€ src/ # Application source code โ”‚ โ”œโ”€โ”€ routes/ # API route handlers โ”‚ โ”œโ”€โ”€ middleware/ # Custom middleware โ”‚ โ”œโ”€โ”€ utils/ # Utility functions โ”‚ โ””โ”€โ”€ public/ # Frontend assets โ”œโ”€โ”€ tests/ # Test suites โ”œโ”€โ”€ Dockerfile # Container configuration โ”œโ”€โ”€ docker-compose.yml # Local development setup โ””โ”€โ”€ package.json # Node.js configuration ``` ### Adding New Features 1. **API Endpoints**: Add routes in `src/routes/` 2. **Middleware**: Create middleware in `src/middleware/` 3. **Tests**: Add tests in `tests/` directory 4. **Frontend**: Update dashboard in `src/public/` ### Code Style - ESLint configuration with recommended rules - Prettier formatting (optional) - Jest testing framework - Security-first approach ## ๐Ÿ”’ Security Features - **Helmet.js**: Security headers and protections - **CORS**: Cross-origin resource sharing control - **Input Validation**: Request data validation - **Error Handling**: Secure error responses - **Health Checks**: System monitoring capabilities - **Container Security**: Non-root user execution ## ๐Ÿ“– Learn More This application demonstrates: - **Modern Node.js Development**: ES6+, async/await, modules - **RESTful API Design**: Resource-based endpoints - **Real-time Monitoring**: Live system metrics - **Container Best Practices**: Multi-stage builds, security - **CI/CD Integration**: Automated testing and deployment - **Production Readiness**: Logging, monitoring, health checks ## ๐Ÿค Contributing 1. Fork the repository 2. Create a feature branch 3. Add tests for new functionality 4. Ensure all tests pass 5. Submit a pull request ## ๐Ÿ“„ License MIT License - see LICENSE file for details --- **Built with โค๏ธ for Harbor CI/CD Demo** This application showcases enterprise-grade Node.js development with comprehensive monitoring, testing, and deployment automation.