Streamlining Software Delivery: Building CI/CD Pipelines with Docker, Jenkins, and AWS

Streamlining Software Delivery: Building CI/CD Pipelines with Docker, Jenkins, and AWS

"When you are eager to learn something, You will find the way." — Chandresh Patle

Introduction: In today's fast-paced software development landscape, the ability to deliver applications quickly and reliably is paramount. Continuous Integration and Continuous Delivery (CI/CD) pipelines have become indispensable tools for achieving seamless and automated software delivery. In this blog, we will explore how to create a CI/CD pipeline for a web application using Docker, Jenkins, and AWS. This powerful combination allows for efficient containerization, continuous integration, testing, and deployment, enabling teams to streamline their development process and deliver high-quality software.

  1. Understanding the CI/CD Pipeline: A CI/CD pipeline is a set of automated processes that enable developers to build, test, and deploy code changes seamlessly. The pipeline ensures that any changes made to the codebase are automatically validated, tested, and deployed in a controlled manner. This minimizes manual errors, reduces deployment time, and increases the overall efficiency of the software development lifecycle.

  2. Leveraging Docker for Containerization: Containerization with Docker allows for consistent and portable software packaging. Docker simplifies the process of creating lightweight, isolated environments called containers, which encapsulate the application and its dependencies. By utilizing Docker, we can ensure that our application runs consistently across different environments, making it easier to manage and deploy.

  3. Setting up Jenkins for Continuous Integration: Jenkins, a popular open-source automation server, plays a crucial role in orchestrating the CI/CD pipeline. It automates the building, testing, and deployment of the application, triggered by code changes. With Jenkins, you can define pipelines using a Jenkinsfile, which describes the steps and stages of the CI/CD process. Jenkins offers extensive plugins and integrations that make it highly customizable and flexible.

  4. AWS Services for Deployment: Amazon Web Services (AWS) provides a comprehensive suite of services that can enhance your CI/CD pipeline. AWS Elastic Compute Cloud (EC2) allows you to host your web application, while Amazon Elastic Container Registry (ECR) enables easy storage and management of Docker images. Additionally, AWS provides tools like AWS CLI and SDKs, which integrate seamlessly with Jenkins for deploying and managing the infrastructure.

  5. Building the CI/CD Pipeline: To create a CI/CD pipeline, we follow several steps:

    Create AWS EC2 Instance and connect the instance

  • Update sudo and install java

  •   sudo apt-get update
      sudo apt install openjdk-11-jre
    
  • To check the Java version

  •   java -version
    
  • To install Jenkins

  •   curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
        /usr/share/keyrings/jenkins-keyring.asc > /dev/null
      echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
        https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
        /etc/apt/sources.list.d/jenkins.list > /dev/null
    
      sudo apt-get update
      sudo apt-get install jenkins
    
  • To start Jenkins

  •   sudo systemctl enable jenkins
      sudo systemctl start jenkins
      sudo systemctl status jenkins
    

    Add port range 8080 for Jenkins

  • Open Jenkins and create a password

  • Create a username and password

  • Jenkins Dashboard

  • Now create a new item and configure it, copy the GitHub repo and paste it to the project URL.

  • Now create a private n public key for GitHub

  •   ssh-keygen
      cd .ssh
      cat id_rsa
      cat id_rsa.pub
    
  • Now Create a Dockerfile

  •   FROM node:12.2.0-alpine
      WORKDIR app
      COPY . .
      RUN npm install
      RUN npm run test
      EXPOSE 8000
      CMD ["node","app.js"]
    
  • To build the Dockerfile and execute the command, add it to the build's execution shell.

  • Now setup webhook on GitHub
    -> Payload URL: paste IP with 8080/gitHub-webhook
    -> Content type: application/json

  • In Jenkins -> Configure -> Build Trigger -> check GitHub hook trigger for GITScm polling and save

  • After some changes in the GitHub code Implemented a CI/CD pipeline and build Finished: SUCCESS

  • Running IP with 8000

Conclusion: Implementing a CI/CD pipeline using Docker, Jenkins, and AWS empowers development teams to automate and streamline their software delivery process. Containerization with Docker ensures consistent and portable deployments, while Jenkins provides the flexibility and automation needed for continuous integration and delivery. Leveraging the services offered by AWS further enhances the scalability, reliability, and monitoring capabilities of the application. By embracing this powerful combination of technologies, organizations can accelerate their software development lifecycle, improve collaboration, and deliver high-quality applications to their users efficiently.

Thank you for joining us on this journey of CI/CD pipelines. Happy building and deploying!

If you have any further questions, suggestions, or topics you would like me to cover, please feel free to reach out. I am here to listen and learn from you.

Linkedin

GitHub

Did you find this article valuable?

Support Chandresh Patle's Blog by becoming a sponsor. Any amount is appreciated!