Skip to main content

Experiment No. 7 Title: Applying CI/CD Principles to Web Development Using Jenkins, Git, using Docker Containers

 Experiment No. 7

Title: Applying CI/CD Principles to Web Development Using Jenkins, Git, using Docker Containers


Objective:

The objective of this experiment is to set up a CI/CD pipeline for a web application using Jenkins, Git, Docker containers, and GitHub webhooks. The pipeline will automatically build, test, and deploy the web application whenever changes are pushed to the Git repository, without the need for a pipeline script.


Introduction:

Continuous Integration and Continuous Deployment (CI/CD) principles are integral to modern web development practices, allowing for the automation of code integration, testing, and deployment. This experiment demonstrates how to implement CI/CD for web development using Jenkins, Git, Docker containers, and GitHub webhooks without a pipeline script. Instead, we'll utilize Jenkins' "GitHub hook trigger for GITScm polling" feature.


In the fast-paced world of modern web development, the ability to deliver high-quality software efficiently and reliably is paramount. Continuous Integration and Continuous Deployment (CI/CD) are integral principles and practices that have revolutionized the way software is developed, tested, and deployed. These practices bring automation, consistency, and speed to the software development lifecycle, enabling development teams to deliver code changes to production with confidence.


Continuous Integration (CI):

CI is the practice of frequently and automatically integrating code changes from multiple contributors into a shared repository. The core idea is that developers regularly merge their code into a central repository, triggering automated builds and tests. Key aspects of CI include:

  • Automation: CI tools, like Jenkins, Travis CI, or CircleCI, automate the building and testing of code whenever changes are pushed to the repository.

  • Frequent Integration: Developers commit and integrate their code changes multiple times a day, reducing integration conflicts and catching bugs early.

  • Testing: Automated tests, including unit tests and integration tests, are run to ensure that new code changes do not introduce regressions.

  • Quick Feedback: CI provides rapid feedback to developers about the quality and correctness of their code changes.


Continuous Deployment (CD):


CD is the natural extension of CI. It is the practice of automatically and continuously deploying code changes to production or staging environments after successful integration and testing. Key aspects of CD include:


  • Automation: CD pipelines automate the deployment process, reducing the risk of human error and ensuring consistent deployments.

  • Deployment to Staging: Code changes are deployed first to a staging environment where further testing and validation occur.

  • Deployment to Production: After passing all tests in the staging environment, code changes are automatically deployed to the production environment, often with zero downtime.

  • Rollbacks: In case of issues, CD pipelines provide the ability to rollback to a previous version quickly.


Benefits of CI/CD in Web Development:

  • Rapid Development: CI/CD accelerates development cycles by automating time-consuming tasks, allowing developers to focus on coding.

  • Quality Assurance: Automated testing ensures code quality, reducing the number of bugs and regressions.

  • Consistency: CI/CD ensures that code is built, tested, and deployed consistently, regardless of the development environment.

  • Continuous Feedback: Developers receive immediate feedback on the impact of their changes, improving collaboration and productivity.

  • Reduced Risk: Automated deployments reduce the likelihood of deployment errors and downtime, enhancing reliability.

  • Scalability: CI/CD can scale to accommodate projects of all sizes, from small startups to large enterprises.


Materials:

  • A computer with Docker installed (https://docs.docker.com/get-docker/)

  • Jenkins installed and configured (https://www.jenkins.io/download/)

  • A web application code repository hosted on GitHub


Experiment Steps:

Step 1: Set Up the Web Application and Git Repository

  • Create a simple web application or use an existing one. Ensure it can be hosted in a Docker container.

  • Initialise a Git repository for your web application and push it to GitHub.


Step 2: Install and Configure Jenkins

  • Install Jenkins on your computer or server following the instructions for your operating system (https://www.jenkins.io/download/).

  • Open Jenkins in your web browser (usually at http://localhost:8080) and complete the initial setup, including setting up an admin user and installing necessary plugins.

  • Configure Jenkins to work with Git by setting up Git credentials in the Jenkins Credential Manager.


Step 3: Create a Jenkins Job

  • Create a new Jenkins job using the "Freestyle project" type.

  • In the job configuration, specify a name for your job and choose "This project is parameterized."

  • Add a "String Parameter" named GIT_REPO_URL and set its default value to your Git repository URL.

  • Set Branches to build  -> Branch Specifier to the working Git branch (ex */master)

  • In the job configuration, go to the "Build Triggers" section and select the "GitHub hook trigger for GITScm polling" option. This enables Jenkins to listen for GitHub webhook triggers.


Step 4: Configure Build Steps

  • In the job configuration, go to the "Build" section.

  • Add build steps to execute Docker commands for building and deploying the containerized web application. Use the following commands:



# Remove the existing container if it exists

docker rm --force container1


# Build a new Docker image

docker build -t nginx-image1 .


# Run the Docker container

docker run -d -p 8081:80 --name=container1 nginx-image1


  • These commands remove the existing container (if any), build a Docker image named "nginx-image1," and run a Docker container named "container1" on port 8081.


Step 5: Set Up a GitHub Webhook

  • In your GitHub repository, navigate to "Settings" and then "Webhooks."

  • Create a new webhook, and configure it to send a payload to the Jenkins webhook URL (usually http://jenkins-server/github-webhook/). Set the content type to "application/json."


Step 6: Trigger the CI/CD Pipeline

  • Push changes to your GitHub repository. The webhook will trigger the Jenkins job automatically, executing the build and deployment steps defined in the job configuration.

  • Monitor the Jenkins job's progress in the Jenkins web interface.


Step 7: Verify the Deployment

Access your web application by opening a web browser and navigating to http://localhost:8081 (or the appropriate URL if hosted elsewhere).


Conclusion:

This experiment demonstrates how to apply CI/CD principles to web development using Jenkins, Git, Docker containers, and GitHub webhooks. By configuring Jenkins to listen for GitHub webhook triggers and executing Docker commands in response to code changes, you can automate the build and deployment of your web application, ensuring a more efficient and reliable development workflow.


Exercise / Questions : 

  1. Explain the core principles of Continuous Integration (CI) and Continuous Deployment (CD) in the context of web development. How do these practices enhance the software development lifecycle?

  2. Discuss the key differences between Continuous Integration and Continuous Deployment. When might you choose to implement one over the other in a web development project?

  3. Describe the role of automation in CI/CD. How do CI/CD pipelines automate code integration, testing, and deployment processes?

  4. Explain the concept of a CI/CD pipeline in web development. What are the typical stages or steps in a CI/CD pipeline, and why are they important?

  5. Discuss the benefits of CI/CD for web development teams. How does CI/CD impact the speed, quality, and reliability of software delivery?

  6. What role do version control systems like Git play in CI/CD workflows for web development? How does version control contribute to collaboration and automation?

  7. Examine the challenges and potential risks associated with implementing CI/CD in web development. How can these challenges be mitigated?

  8. Provide examples of popular CI/CD tools and platforms used in web development. How do these tools facilitate the implementation of CI/CD principles?

  9. Explain the concept of "Infrastructure as Code" (IaC) and its relevance to CI/CD. How can IaC be used to automate infrastructure provisioning in web development projects?

  10. Discuss the cultural and organisational changes that may be necessary when adopting CI/CD practices in a web development team. How does CI/CD align with DevOps principles and culture?


Comments

Popular posts from this blog

Experiment No. 5 Title: Applying CI/CD Principles to Web Development Using Jenkins, Git, and Local HTTP Server

  Experiment No. 5 Title: Applying CI/CD Principles to Web Development Using Jenkins, Git, and Local HTTP Server  Objective: The objective of this experiment is to set up a CI/CD pipeline for a web development project using Jenkins, Git, and webhooks, without the need for a Jenkinsfile. You will learn how to automatically build and deploy a web application to a local HTTP server whenever changes are pushed to the Git repository, using Jenkins' "Execute Shell" build step. Introduction: Continuous Integration and Continuous Deployment (CI/CD) is a critical practice in modern software development, allowing teams to automate the building, testing, and deployment of applications. This process ensures that software updates are consistently and reliably delivered to end-users, leading to improved development efficiency and product quality. In this context, this introduction sets the stage for an exploration of how to apply CI/CD principles specifically to web development using J

Experiment No. 6 Title: Exploring Containerization and Application Deployment with Docker

  Experiment No. 6 Title: Exploring Containerization and Application Deployment with Docker  Objective: The objective of this experiment is to provide hands-on experience with Docker containerization and application deployment by deploying an Apache web server in a Docker container. By the end of this experiment, you will understand the basics of Docker, how to create Docker containers, and how to deploy a simple web server application. Introduction Containerization is a technology that has revolutionised the way applications are developed, deployed, and managed in the modern IT landscape. It provides a standardised and efficient way to package, distribute, and run software applications and their dependencies in isolated environments called containers. Containerization technology has gained immense popularity, with Docker being one of the most well-known containerization platforms. This introduction explores the fundamental concepts of containerization, its benefits, and how it differs

Experiment No. 10 Title: Create the GitHub Account to demonstrate CI/CD pipeline using Cloud Platform.

  Experiment No. 10 Title: Create the GitHub Account to demonstrate CI/CD pipeline using Cloud Platform. Objective: The objective of this experiment is to help you create a GitHub account and set up a basic CI/CD pipeline on GCP. You will learn how to connect your GitHub repository to GCP, configure CI/CD using Cloud Build, and automatically deploy web pages to an Apache web server when code is pushed to your repository. Introduction: Continuous Integration and Continuous Deployment (CI/CD) pipelines are essential for automating the deployment of web applications. In this experiment, we will guide you through creating a GitHub account and setting up a basic CI/CD pipeline using Google Cloud Platform (GCP) to copy web pages for an Apache HTTP web application. Continuous Integration and Continuous Deployment (CI/CD) is a crucial practice in modern software development. It involves automating the processes of code integration, testing, and deployment to ensure that software changes are co