Skip to content

This repository houses a robust CI/CD solution leveraging Jenkins pipelines for seamless integration and deployment of a Spring Boot Angular application.With integrated tools;

Notifications You must be signed in to change notification settings

BadisLaffet1/CI-CD-Jenkins-pipeline-solution-for-Springboot-Angular-application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI/CD Jenkins Pipeline Solution for Spring Boot Angular Application

Based on various DevOps best practices, this repository houses a robust CI/CD solution leveraging Jenkins pipelines for seamless integration and deployment of a Spring Boot Angular application. The project includes a MySQL database and is integrated with Jenkins, SonarQube, Nexus, Prometheus, and Grafana.

Table of Contents

Prerequisites

We should have the following software and tools installed before setting up and running the project. Links to official documentation or download pages are provided for reference.

Getting Started

This is the stage view of the example pipeline image

Follow these steps to set up and run the project.

Installation

Clone the repository:

git clone https://github.com/BadisLaffet1/CI-CD-Jenkins-pipeline-solution-for-Springboot-Angular-application.git
cd CI-CD-Jenkins-pipeline-solution-for-Springboot-Angular-application

Configuration

Before running the project, we sgiykd have completed the following configuration steps:

  1. Database Configuration:

    • Create a MySQL database for the application.
    • Update the application.properties file located in the src/main/resources directory with your database credentials:
      spring.datasource.url=jdbc:mysql://(MYSQL_CONTAINER_NAME):3306/your_database
      spring.datasource.username=your_username
      spring.datasource.password=your_password
    • PS: Change MYSQL_CONTAINER_NAME with the same name of the container hosting the SQL server.
  2. Jenkins Configuration:

    • Set up a Jenkins instance and create a new pipeline for this project.
    • Follow regular installation methods for Jenkins, Java, and Maven.
    • Configure a new Jenkins Pipeline with the necessary stages, steps, and environment variables:
      stage('Checkout') {
          steps {
              script {
                  checkout([
                      $class: 'GitSCM',
                      branches: [[name: 'YOU_BRANCH_NAME']], 
                      userRemoteConfigs: [[url: 'YOUR_GITHUB_URL', credentialsId: 'github']]
                  ])
              }
          }
      }
      • PS: Change YOUR_BRANCH_NAME with the name of your current branch and YOUR_GITHUB_URL with your repository URL.
      • Clean and build the Spring Boot project:
      stage('Clean and Build') {
          steps {
              script {
                  dir('Backend') {
                      sh 'mvn clean package  -Dmaven.test.skip=true '
                      sh 'mvn package -DskipTests'
                  }
              }
          }
      }
      • Prepare metrics by adding a test stage:
      stage('Build and Test') {
          steps {
              script {
                  dir('Backend') {
                      sh 'mvn clean test'
                      sh 'mvn jacoco:report'
                  }
              }
          }
      }
  3. SonarQube Configuration:

    • SonarQube is being hosted on a container (check docker-compose file inside the monitoring-stack folder).
    • Configure the sonar-project.properties file in the root of your project with the appropriate SonarQube server information:
      sonar.host.url=http://your-sonarqube-server:9000
      sonar.login=your-sonar-token
    • Alternatively, you can add a specific token to your Jenkins credentials.
    • Add a SonarQube stage to your Jenkins pipeline script:
      stage('Static Code Analysis') {
          environment {
              SONAR_URL = "YOUR_IP:9000"
          }
          steps {
              dir('Backend') {
                  withCredentials([string(credentialsId: 'CREDENTIAL_ID', variable: 'SONAR_AUTH_TOKEN')]) {
                      sh 'mvn sonar:sonar -Dsonar.login=$SONAR_AUTH_TOKEN -Dsonar.host.url=${SONAR_URL}'
                  }
              }
          }
      }
      • Make sure to change the script based on your configuration.

      • You should have the following analysis on your sonarqube projects section

    image

    PS : if you want to increase the couverage of your code consider creating new test unit classes inside Backend/src/test.

  4. Nexus Configuration:

    • Nexus is being hosted on a separate container (check docker-compose file inside the monitoring-stack folder for more information).
    • Update the pom.xml file with the Nexus repository information for Maven dependencies based on your configuration:
      <distributionManagement>
          <repository>
              <id>nexus-releases</id>
              <url>http://your-nexus-server:8081/repository/maven-releases/</url>
          </repository>
      </distributionManagement>
    • Finally, add a Deploy artifact to Nexus stage to your pipeline script:
      stage('Deploy artifact to Nexus') {
          steps {
              dir('Backend') {
                  sh 'mvn deploy -DskipTests'               
              }
          }
      }
    • You should have your spring boot JAR uploaded to your nexus repository.

    image

  5. Deploy application :

  • Use the provided Docker Compose file in the main directory to start mysql, spring boot app and the angular front app.

    stage('deploy application') {
           steps{
              script {
         dir('.') {
                   sh "docker compose up -d"
             }}
           }
       }
    
    }
  • After this stage , you should have these containers with running status :

Capture9

  1. Prometheus and Grafana Configuration:
    • Use the provided Docker Compose file in the monitoring directory to also start Prometheus and Grafana containers , also consider adding services for cadvisor , redis etc ...
    • Access Grafana at http://YOURIP:3000 and set up Prometheus as a data source.
    • PS :
      • Configure the jobs by editing the file monitoring-stack/prometheus.yml, this file was configured for prometheus service using docker compose .

These configuration steps ensure that your Spring Boot Angular application integrates seamlessly with the specified tools and services. Adjust the configurations based on your environment and requirements.

-To make sure you have efficiently synchronized your metrics with the prometheus data sure , you should have a similar prometheus target section :

Capture4

-In final step , access your Grafana interface , add prometheus datasource , and start configuring dashboards based on your preference .

-The following examples of dashboards that i have integrated to the project :

Spring APM Capture5

Docker container & host metrics Capture6

Jenkins performance and health overview Capture7

PS: Since the sql server is hosted on particular container, we can spec the data base using this way : Capture

MIT License

Copyright (c) 2023 Badis Laffet

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

This repository houses a robust CI/CD solution leveraging Jenkins pipelines for seamless integration and deployment of a Spring Boot Angular application.With integrated tools;

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published