/Basic-CI-CD

A basic CI/CD project to learn GitOps best practices and tools

Primary LanguageShell

Basic CI/CD Pipeline Project

CI/CD Pipeline Jenkins GitLab Nexus Kubernetes Terraform ArgoCD Sonarqube Prometheus Grafana License

A robust end-to-end CI/CD pipeline demonstrating modern DevOps practices through the integration of industry-standard tools. This project automates the complete software development lifecycle from code commit to production deployment and observability of a Python Flask application.

๐Ÿ” For detailed setup and usage instructions, please see How to Use Guide.

Table of Contents

๐ŸŒŸ Overview

This project showcases a complete CI/CD pipeline with integrated monitoring that automates the software development lifecycle. It leverages modern DevOps tools to create a scalable, maintainable, and secure solution for continuous delivery and monitoring of a Python Flask application.

The implementation focuses on DevOps best practices including:

  • Infrastructure as Code (IaC)
  • Containerization
  • Continuous Integration
  • Continuous Deployment with GitOps
  • Automated Testing
  • Code Quality Enforcement
  • Comprehensive Monitoring
  • Multi-Environment Support

๐Ÿงฉ Core Principles

This project embodies several core DevOps principles:

  1. Automation ๐Ÿ”„: Eliminate manual processes through automation of building, testing, and deployment
  2. Continuous Integration ๐Ÿ› ๏ธ: Frequent code integration with automated verification
  3. Continuous Delivery ๐Ÿš€: Reliable, low-risk deployments through automation
  4. GitOps ๐Ÿ“: Git as the single source of truth for infrastructure and application deployment
  5. Shift Left ๐Ÿ”: Early testing, security scanning, and quality checks
  6. Infrastructure as Code ๐Ÿ—๏ธ: Define and version infrastructure alongside application code
  7. Observability ๐Ÿ“Š: Comprehensive monitoring and metrics collection
  8. Environment Parity ๐Ÿ”„: Consistent configurations across environments

๐Ÿ›๏ธ Architecture

The architecture integrates several key components:

  1. Version Control (GitLab): Central repository for application code, Helm charts, and deployment configurations
  2. CI Pipeline (Jenkins): Orchestrates building, testing, and artifact creation processes
  3. Artifact Storage (Nexus): Securely stores versioned application binaries
  4. Quality Gates (Sonarqube): Enforces code quality standards and test coverage
  5. Infrastructure Provisioning (Terraform): Manages Kubernetes infrastructure declaratively
  6. GitOps Engine (ArgoCD): Ensures deployment state matches Git definitions
  7. Container Orchestration (Kubernetes): Manages application containers
  8. Monitoring Stack: Tracks application and infrastructure health and performance

The workflow connects these components into a seamless pipeline where code changes automatically flow through verification, building, and deployment stages while maintaining observability.

โœจ Key Features

  • Complete CI/CD Automation: End-to-end pipeline from code commit to deployment
  • GitOps with ArgoCD: App of Apps pattern for multi-environment deployments
  • Infrastructure as Code: Terraform-managed Kubernetes with reusable modules
  • Multi-Environment Support: Separate dev and prod configurations
  • Advanced Flask Application: Rate limiting, metrics collection, and health monitoring
  • Comprehensive Testing: Automated functional, security, and metrics tests
  • Code Quality Enforcement: Static analysis, security scanning, and Sonarqube integration
  • Artifact Management: Versioned binary storage with Nexus
  • Containerized Development: Docker Compose for consistent local environment
  • Detailed Monitoring: Prometheus metrics collection with Grafana dashboards
  • Alerting: Configurable thresholds with Alertmanager integration

๐Ÿงฐ Components

๐Ÿ“ Version Control with GitLab

GitLab serves as the central source code repository, providing:

  • Version control for application code
  • CI/CD integration with Jenkins
  • Repository for deployment configurations
  • Separate branch for ArgoCD configurations

๐Ÿ”„ Continuous Integration with Jenkins

Jenkins orchestrates the CI process with a pipeline that:

  • Runs automated tests with pytest
  • Performs static code analysis with Ruff
  • Conducts security scanning with Bandit
  • Analyzes code quality with Sonarqube
  • Builds application binaries with PyInstaller
  • Uploads artifacts to Nexus repository
  • Updates deployment configurations
  • Creates dedicated ArgoCD branch

๐Ÿ“ฆ Artifact Management with Nexus

Nexus provides a central repository for:

  • Storing versioned application binaries
  • Managing latest and timestamped releases
  • Providing a reliable artifact source for deployments

๐Ÿ—๏ธ Infrastructure Management with Terraform

Terraform enables infrastructure as code by:

  • Creating and configuring Kind Kubernetes clusters
  • Setting up ArgoCD with the App of Apps pattern
  • Managing Kubernetes resources with reusable modules
  • Connecting cluster to external services like Nexus

๐Ÿš€ GitOps Deployment with ArgoCD

ArgoCD implements GitOps practices by:

  • Using the App of Apps pattern for hierarchical management
  • Automatically synchronizing Git changes to the cluster
  • Supporting multiple environments (dev, prod)
  • Self-healing deployments that maintain desired state
  • Providing visibility into deployment status and history

โš™๏ธ Application Deployment with Helm

Helm charts provide declarative application management:

  • Environment-specific configurations via values files
  • Consistent deployment templates
  • Support for versioned releases
  • Integration with Nexus for artifact retrieval

๐Ÿ“Š Monitoring with Prometheus and Grafana

The monitoring stack delivers comprehensive observability:

  • Application metrics from the Flask /metrics endpoint
  • Pipeline performance metrics from Jenkins
  • Container and system metrics from cAdvisor
  • Custom dashboards for different aspects of the system
  • Alerting based on defined thresholds

๐Ÿ”„ Workflow

The CI/CD workflow follows these steps:

  1. Code Commit ๐Ÿ“: Developer pushes changes to GitLab main branch
  2. CI Pipeline ๐Ÿงช: Jenkins tests, analyzes, builds and packages the application
  3. Artifact Storage ๐Ÿ“ฆ: Binary is versioned and stored in Nexus
  4. GitOps Update ๐Ÿ”„: Jenkins updates Helm chart and ArgoCD branch
  5. Automatic Deployment ๐Ÿš€: ArgoCD detects changes and syncs applications to Kubernetes
  6. Multi-Environment Deployment ๐ŸŒ: Applications deploy to dev and prod environments
  7. Continuous Monitoring ๐Ÿ“Š: Prometheus collects metrics from all components
  8. Performance Visualization ๐Ÿ“ˆ: Grafana displays real-time metrics and trends

This workflow embodies the principle of continuous delivery by providing a reliable, repeatable path to production with built-in quality gates and observability.

๐Ÿ“ Directory Structure

basic-ci-cd/
โ”œโ”€โ”€ appflask/                     # Flask application source
โ”‚   โ”œโ”€โ”€ agent/                    # Jenkins agent configuration
โ”‚   โ”œโ”€โ”€ appflask/                 # Application source code
โ”‚   โ”œโ”€โ”€ argocd-apps/              # ArgoCD application definitions
โ”‚   โ”‚   โ”œโ”€โ”€ apps/                 # App of Apps child applications
โ”‚   โ”‚   โ””โ”€โ”€ helm/                 # Helm charts for applications
โ”‚   โ”œโ”€โ”€ tests/                    # Test suites
โ”‚   โ””โ”€โ”€ test_scripts/             # Monitoring test scripts
โ”‚
โ”œโ”€โ”€ docs/                         # Documentation files
โ”‚   โ”œโ”€โ”€ how-to-use.md             # Comprehensive usage guide
โ”‚   โ”œโ”€โ”€ monitoring/               # Monitoring documentation
โ”‚   โ”œโ”€โ”€ progresses/               # Project progress tracking
โ”‚   โ””โ”€โ”€ subjects/                 # Project requirements
โ”‚
โ”œโ”€โ”€ srcs/                         # Docker environment files
โ”‚   โ”œโ”€โ”€ docker-compose.yaml       # Service composition
โ”‚   โ””โ”€โ”€ requirements/             # Service-specific files
โ”‚
โ”œโ”€โ”€ terraform/                    # Terraform configurations
โ”‚   โ”œโ”€โ”€ environments/             # Environment-specific configs
โ”‚   โ”œโ”€โ”€ modules/                  # Reusable modules
โ”‚   โ”‚   โ”œโ”€โ”€ cluster/              # Kind cluster module
โ”‚   โ”‚   โ””โ”€โ”€ k8s_resources/        # Kubernetes resources modules
โ”‚   โ””โ”€โ”€ scripts/                  # Helper scripts
โ”‚
โ”œโ”€โ”€ Makefile                      # Build automation
โ””โ”€โ”€ README.md                     # This documentation

๐Ÿ“š Documentation

Comprehensive documentation is available in the docs directory:

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Developed with โค๏ธ by [Nihilantropy]