0% found this document useful (0 votes)
2 views

CI_CD integration_DOC

The document outlines the processes and benefits of Continuous Integration (CI) and Continuous Deployment (CD) in software development, emphasizing the importance of automated testing, code quality analysis, and deployment automation. It details the system architecture involving tools like GitHub, Jenkins, SonarQube, and Docker, providing step-by-step instructions for setting up CI/CD pipelines and integrating these tools. The implementation of CI/CD practices is presented as a means to enhance code quality, streamline development workflows, and improve overall productivity and customer satisfaction.

Uploaded by

smohanbabu08
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CI_CD integration_DOC

The document outlines the processes and benefits of Continuous Integration (CI) and Continuous Deployment (CD) in software development, emphasizing the importance of automated testing, code quality analysis, and deployment automation. It details the system architecture involving tools like GitHub, Jenkins, SonarQube, and Docker, providing step-by-step instructions for setting up CI/CD pipelines and integrating these tools. The implementation of CI/CD practices is presented as a means to enhance code quality, streamline development workflows, and improve overall productivity and customer satisfaction.

Uploaded by

smohanbabu08
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

CI/CD integration

Introduction:

Continuous Integration (CI):


Continuous Integration is a development practice that involves integrating code changes
from multiple developers into a shared repository regularly. The main goal of CI is to ensure
that each code change is tested and integrated early and frequently. It typically involves the
following steps:

1. Code Commit: Developers commit their code changes to a version control system,
such as Git.
2. Build and Test: The CI server automatically pulls the latest code changes, builds the
application, and runs automated tests to validate the code.
3. Code Quality Analysis: Additional tools or services, like SonarQube, may be used
to analyse the code for quality, security, and adherence to coding standards.
4. Feedback and Notifications: Developers receive immediate feedback on the build
and test results. Notifications can be sent via email, chat platforms, or other
communication channels.

Continuous Deployment (CD):


Continuous Deployment is an extension of CI that takes the automated process further by
automatically deploying the tested and validated code changes to production or a staging
environment. It involves the following steps:

1. Artifact Creation: Once the code changes pass all tests and analysis, the CI server
generates deployable artifacts, such as executable files or Docker images.
2. Deployment Automation: The deployment process is automated, using tools like
Jenkins, to push the artifacts to the target environment, such as AWS EC2 instances.
3. Infrastructure Configuration: If necessary, the infrastructure configuration is
automated, including setting up databases, load balancers, and other components
required for the application.
4. Release to Production: The validated changes are deployed to the production
environment, ensuring a seamless and reliable deployment process.
Benefits of CI/CD:
Implementing CI/CD in your development workflow offers several benefits:

1. Early Bug Detection: Frequent integration and automated testing help identify bugs
and issues early in the development cycle, reducing the cost and effort required for
bug fixing.
2. Faster Time to Market: CI/CD accelerates the software delivery process by
automating time-consuming tasks, enabling faster release cycles, and reducing
manual intervention.
3. Improved Code Quality: Continuous code analysis and feedback ensure that code
quality standards are maintained, enhancing the overall stability and maintainability
of the application.
4. Increased Collaboration: CI/CD encourages collaboration among developers,
enabling them to work on separate code branches and merge their changes
regularly, minimising conflicts.
5. Reliable Deployments: With automated deployment processes, the risk of human
error is reduced, leading to more reliable and consistent deployments.
6. Scalability and Flexibility: CI/CD pipelines can be easily scaled to accommodate
large-scale projects and can adapt to different development and deployment
scenarios.
7. Continuous Improvement: CI/CD encourages a culture of continuous improvement,
as feedback from tests, code analysis, and deployments helps identify areas for
enhancement and optimization.
By implementing CI/CD practices, Straive can streamline their development processes,
improve code quality, and deliver software more efficiently, leading to increased productivity
and customer satisfaction.
System Architecture:

Version Control System:


GitHub: Acts as the central repository for storing your source code and version history.
Developers push their code changes to GitHub.

Continuous Integration Server:


Jenkins: Serves as the CI server that automates the build, test, and integration process. It
monitors the GitHub repository for code changes and triggers the CI pipeline accordingly.

Build and Test:


1. Jenkins: Pulls the latest code changes from GitHub and performs the build process,
compiling the code and generating executable files or artifacts.

2. Automated Testing: Jenkins executes automated tests, such as unit tests, integration
tests, or end-to-end tests, to ensure the code changes are functioning as expected.

Code Quality Analysis:


SonarQube: Integrates with Jenkins to perform static code analysis and evaluate code
quality, identifying issues related to code smells, bugs, vulnerabilities, and adherence to
coding standards.
Artifact Management:
Docker: Enables containerization of the application. Jenkins can build Docker images based
on the artifacts generated during the build process, providing a consistent and portable
environment for deployment.

Deployment and Infrastructure:


1. AWS EC2: Provides the infrastructure for hosting your application. It offers virtual
servers (EC2 instances) where your application can be deployed.
2. Docker: Deploying Docker images to EC2 instances allows for scalability, easy
replication, and management of the application across multiple instances.

Continuous Deployment:
Jenkins: Manages the deployment process by orchestrating the release of artifacts to the
target environment, such as EC2 instances on AWS.

GitHub Integration:

Set up a GitHub repository:


1. Create a new repository on GitHub or use an existing one.
2. Ensure that the repository contains the source code of your project.

Install and configure Jenkins:


1. Install Jenkins on your server or use a cloud-based Jenkins service.
2. Follow the installation instructions provided by Jenkins for your specific environment.
3. Set up the necessary plugins in Jenkins, such as the GitHub plugin, to enable
integration with GitHub.

Create a Jenkins job:


1. Log in to your Jenkins server and navigate to the Jenkins dashboard.
2. Click on "New Item" to create a new Jenkins job.
3. Give the job a name and select the Freestyle job type
4. Configure the job according to your specific requirements, such as build steps, tests,
and deployment actions.

Configure the GitHub integration in Jenkins:


1. In the Jenkins job configuration, find the section related to source code management.
2. Select "Git" as the source code management system.
3. Provide the URL of your GitHub repository in the "Repository URL" field.
4. Optionally, specify the branch or branches that you want to build or trigger the CI/CD
pipeline for.
5. Configure any additional settings, such as credentials for accessing the GitHub
repository if required.

Set up webhooks or triggers:


1. In your GitHub repository settings, find the section related to webhooks or repository
triggers.
2. Add a new webhook or trigger and specify the URL of your Jenkins server's webhook
endpoint. The endpoint URL will be provided by Jenkins during the configuration
process.
3. Configure the webhook or trigger to fire events whenever there are code changes or
specific actions occur in the repository (e.g., pushes, pull requests, etc.).
4. Save the webhook or trigger settings.

Test the integration:


1. Make a code change or push a new commit to your GitHub repository.
2. Verify that Jenkins picks up the changes and triggers the configured Jenkins job.
3. Check the Jenkins job's console output and logs to ensure that the build and any
subsequent steps in the CI/CD pipeline are executed successfully.

By following these steps, you should be able to establish the connection between your
GitHub repository and your CI/CD pipeline, allowing Jenkins to automatically trigger builds
and deployments whenever code changes are pushed to the repository.

Remember to customize the configuration based on your specific project requirements, such
as choosing the appropriate Jenkins job type and configuring build steps, tests, and
deployment actions accordingly.
Installing and Configuring Jenkins:

Install Java Development Kit (JDK):


1. Jenkins requires Java to run. Install the JDK on your system if it's not already
installed. You can download it from the Oracle website or use a package manager
specific to your operating system.

Download and Install Jenkins:


1. Visit the Jenkins website (https://www.jenkins.io/) and download the latest stable
version of Jenkins.

2. Follow the installation instructions specific to your operating system. Generally, it


involves running an installer or executing a command to install Jenkins.

Start Jenkins:
1. Once installed, start the Jenkins service. It usually runs on port 8080 by default.

Access Jenkins Web Interface:

1. Open a web browser and navigate to http://localhost:8080 (replace "localhost" with


the appropriate hostname or IP address if running Jenkins on a remote server).

2. You will be prompted to unlock Jenkins by entering an initial administrator password.

3. Retrieve the initial administrator password from the Jenkins server by following the
on-screen instructions.

Complete Jenkins Setup Wizard:

1. Paste the initial administrator password into the setup wizard and click "Continue."

2. Choose the "Install suggested plugins" option, which will install commonly used
plugins for CI/CD workflows.

3. Create an admin user and provide the necessary details.

4. Proceed with the remaining setup wizard steps until the Jenkins installation is
complete.
Create a New Jenkins Job:

1. From the Jenkins dashboard, click on "New Item" to create a new job.
2. Enter a name for the job and choose the appropriate job type (e.g., Freestyle project,
Pipeline).

Configure Source Code Management:

1. In the job configuration, locate the "Source Code Management" section.


2. For integration with GitHub, choose "Git" as the source code management system.
3. Provide the repository URL, credentials (if required), and specify the branch or
branches to build.

Configure Build Steps:

1. In the job configuration, find the "Build" section.


2. Add build steps specific to your application, such as executing shell commands,
running build scripts.

Configure Testing:

1. If your application requires tests, add test execution steps in the job configuration.
2. You can use shell commands or specify test frameworks like JUnit or Selenium for
automated testing.

Configure Deployment Actions:

1. To deploy your application, add deployment steps in the job configuration.


2. Depending on your AWS EC2
3. Install additional plugins for SSH Connectivity - SSH2 Easy.
4. Save and Run the Jenkins Job:

Save the job configuration.

1. Run the job manually to ensure that the build, test, and deployment steps are
executed as expected.
2. Monitor the console output and logs for any errors or issues.
*Please refer the below Screenshot for any clarifications.
SonarQube Integration:

SonarQube is an open-source platform that enables continuous code quality management. It


provides a range of code analysis and inspection tools to help teams detect and fix code
issues, improve code quality, ensure adherence to coding standards, and enhance overall
software reliability. SonarQube fits into the CI/CD pipeline by integrating as a code quality
analysis tool, providing feedback on the quality of code changes during the development and
build process.

Here are the steps to set up SonarQube for code quality analysis:

1. Install and Configure SonarQube Server:


a. Download the SonarQube server from the official website
(https://www.sonarqube.org/downloads/).
b. Install the server according to the provided installation instructions specific to
your operating system.
c. Configure SonarQube properties, such as database connection settings and
server port, in the sonar.properties file.

2. Start SonarQube Server:


a. Start the SonarQube server by executing the appropriate command or script
for your operating system. (FolderName/bin/OSTypeFolderName/.sonar.sh)

3. Access SonarQube Web Interface:


a. Open a web browser and navigate to the SonarQube server URL (
http://localhost:9000).
b. Log in using the default credentials (admin/admin), and change the password
when prompted.

4. Create a SonarQube Project:


a. In the SonarQube web interface, create a new project and provide the
necessary details (e.g., project key, display name).

5. Generate SonarQube Access Token:


a. Generate an access token in SonarQube to authenticate Jenkins or other
tools during the integration process.
b. Go to "My Account" → "Security" → "Generate Tokens" in the SonarQube
web interface.
c. Provide a name for the token and click "Generate."

Configuring SonarQube Plugins in Jenkins or Integrating Directly into the Build Process:
There are two main approaches to integrating SonarQube into your CI/CD pipeline: using
SonarQube plugins in Jenkins or integrating it directly into the build process. Here's how to
configure with SonarQube Plugin options:

1. Install the SonarQube Scanner for Jenkins plugin in Jenkins.


2. In the Jenkins job configuration, find the "Build Environment" section.
3. Enable the "Prepare SonarQube Scanner environment" option.
4. Configure the SonarQube server details, including the server URL and access token.
5. Specify the project key matching the SonarQube project created earlier.
6. Save the configuration and run the Jenkins job. SonarQube analysis will be triggered
as part of the build process, and the results will be available in the SonarQube
dashboard.
DOCKER INTEGRATION

Docker plays a crucial role in the CI/CD pipeline by providing containerization, which offers
several benefits. Containerization allows applications and their dependencies to be
packaged as self-contained units called Docker containers. Here's an overview of Docker's
role and the benefits it brings to the CI/CD pipeline:

Role of Docker in the CI/CD Pipeline:

1. Consistent Environment: Docker ensures consistency across different


environments by packaging applications with their dependencies into containers. This
eliminates the "works on my machine" problem and helps guarantee that the
application will behave consistently across development, testing, and production
environments.

2. Reproducible Builds: Docker images are built from a set of instructions defined in a
Dockerfile. This enables reproducibility, allowing the exact same image to be created
consistently at any point in the CI/CD pipeline.

3. Isolation: Docker containers provide process-level isolation, allowing multiple


applications or services to run on the same host without interfering with each other.
This isolation ensures that one application's dependencies for configuration changes
don't impact other applications.

4. Scalability: Docker enables horizontal scalability by allowing multiple instances of


containers to be deployed easily. This makes it simpler to scale applications up or
down based on demand.

5. Simplified Deployment: Docker simplifies the deployment process by packaging the


application and its dependencies into a single portable unit. This eliminates the need
to install dependencies manually on the target environment, reducing the chances of
configuration errors.

Process of Creating Docker Images on EC2 with Jenkins for Your Application:

To create Docker images on EC2 with Jenkins for your application, follow these steps:
1. Set up Jenkins on EC2: Install and configure Jenkins on your EC2 instance by
following the installation instructions provided by Jenkins.

2. Install Docker on EC2: Install Docker on your EC2 instance by following the Docker
installation instructions for your operating system. This will allow Jenkins to interact
with Docker and build Docker images.

3. Configure Jenkins:

a. Install the necessary plugins in Jenkins, such as the "Docker" plugin and any
other plugins required for integration with your CI/CD pipeline.

b. Set up the necessary Jenkins job for building Docker images. Configure the
job to fetch your application's source code from the repository, execute
Docker commands, and perform any other build steps required.

4. Configure Docker Registry:

a. Set up a Docker registry to store your Docker images. You can use a public
registry like Docker Hub or set up a private registry using tools like AWS ECR.
b. Obtain the necessary credentials (e.g., username, password, access key) to
authenticate and push Docker images to the registry.

Instructions for Building, Tagging, and Pushing Docker Images within the Remote Shell of
Jenkins to a Registry:

To build, tag, and push Docker images within the remote shell of Jenkins to a registry as part
of your CI/CD process, add the below code:

cd /home/ubuntu/podets/printondemand_a6/

nvm install 14.17

npm install

npm install node-sass

ng build

docker system prune -f

cd /home/ubuntu/podets/printOnDemand

echo 'FROM nginx:1.22.0-alpine AS prod-stage

# Remove the default NGINX website

RUN rm -rf /usr/share/nginx/html/*

COPY printOnDemand_app/ /usr/share/nginx/html/


EXPOSE 80

CMD ["nginx","-g","daemon off;"]' > Dockerfile

docker stop printondemand_app || true

docker rm printondemand_app || true

docker build -t printondemand_app .

docker run -d -p 8085:80 --name=printondemand_app printondemand_app

AWS INTEGRATION

1. Sign in to the AWS Management Console:

a. Navigate to the EC2 service.


b. Launch a new EC2 instance based on your desired configuration (e.g.,
Amazon Linux, Ubuntu, Windows Server).
c. Select the appropriate instance type, configure the storage, and choose other
settings as needed.
d. Create or select a key pair for SSH access to the instance.
e. Launch the instance.

2. Connect to the EC2 Instance:


a. Obtain the public IP address or public DNS name of the EC2 instance from
the EC2 console.
b. Connect to the instance using SSH. For example, using the following
command in the terminal:
ssh -i <path-to-key-pair>.pem ec2-user@<public-ip-or-dns>

c. Replace <path-to-key-pair> with the path to the downloaded key pair file and
<public-ip-or-dns> with the IP address or DNS name of the EC2 instance.

3. Install Required Dependencies:

a. Update the package repositories: sudo yum update (for Amazon Linux) or
sudo apt update (for Ubuntu).
b. Install necessary dependencies, such as Git, Docker, Jenkins, SonarQube or
specific programming language runtimes.

4. Deploy Your Application:

a. Clone or copy your application code to the EC2 instance using Git.

5. Configuring Security Groups:

a. In the EC2 console, navigate to "Security Groups."


b. Create a new security group or modify an existing one.
c. Configure inbound and outbound rules to allow necessary traffic to your
application (e.g., HTTP, HTTPS, SSH).
d. Associate the security group with your EC2 instance.

*Please refer the below Screenshot for any clarifications.

After completing all the above steps, start a build using jenkins manually or commit any new
changes to Git to trigger the jenkins job automatically.
END

You might also like