Day 10: Jenkins Declarative CI/CD 
                          Pipeline Project

Day 10: Jenkins Declarative CI/CD Pipeline Project

ยท

3 min read

Project 1: Notes App

Prerequisites โœ…

  1. EC2 instance ๐Ÿ–ฅ๏ธ

  2. GitHub ๐Ÿ™

  3. Docker ๐Ÿณ

  4. Docker Hub ๐Ÿ 

  5. Jenkins ๐Ÿš€

Steps Included:

๐Ÿ› ๏ธ Configuration Steps:

  1. Create EC2 Instance:

    • Set up a new EC2 instance on AWS.๐Ÿ–ฅ๏ธ
  2. SSH Connection:

    • Connect to your EC2 instance using SSH.๐Ÿ”—
  3. Update Instance:

    • Ensure your instance is up to date with the latest updates.๐Ÿ”„
  4. Docker Installation:

    • Install Docker on your EC2 instance.๐Ÿณ
  5. User Addition to Docker Group:

    • Add your user to the Docker group for seamless Docker access.๐Ÿ‘ฅ
  6. Java Installation:

    • Install Java on your EC2 instance.โ˜•
  7. Jenkins Installation:

    • Install Jenkins on your EC2 instance.๐Ÿš€
  8. Jenkins User to Docker Group:

    • Grant Jenkins user access to the Docker group.๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿณ
  9. Reboot Instance:

    • Reboot your EC2 instance for changes to take effect.โ™ป๏ธ
  10. Inbound Rules Configuration:

    • Edit inbound rules to allow access to Jenkins on port 8080.๐Ÿšช
  11. Jenkins Setup:

    • Finally, configure and set up Jenkins for your continuous integration needs.๐Ÿ› ๏ธ

๐Ÿš€Pipeline Creation Steps:

  1. New Pipeline Setup:

    • Initiate the creation of a new pipeline.
  2. GitHub Project Selection:

    • Opt for the 'GitHub Project' option and input the GitHub URL for your project.๐Ÿ™
  3. Pipeline Script Configuration:

    • Choose 'Pipeline Script' as the script option.๐Ÿ“œ
  4. Groovy Scripting:

    • Use Groovy script to:

      • Clone the code from the specified GitHub repository.

      • Build a Docker image from the cloned code.

  5. Docker Hub Account Creation:

    • Create an account on Docker Hub.๐Ÿ 
  6. Credentials Setup:

    • In Jenkins, navigate to 'Manage Jenkins' -> 'Credentials' -> 'System' -> 'Global Credentials' -> 'Add'.

    • Add Docker Hub credentials using environment variables.๐Ÿ”

  7. Dockerhub Credentials in Code:

    • Use the 'withCredentials' Groovy syntax to provide Docker Hub login credentials within the pipeline code.๐Ÿ”‘
  8. Image Retagging:

    • Retag the previously built image using the 'docker tag' command.๐Ÿท๏ธ
  9. Dockerhub Login:

    • Incorporate the script to log in to Docker Hub using the specified credentials.๐Ÿ”’
  10. Image Push to Dockerhub:

    • Push the latest image to Docker Hub using the 'docker push' command.๐Ÿšข

These steps collectively configure a comprehensive pipeline, from code cloning to Docker image pushing, including Docker Hub integration. ๐ŸŒ๐Ÿณ

๐Ÿšข Docker-Compose Deployment and Automated Build Configuration:

  1. Docker-Compose Integration:

    • Enhance pipeline robustness by deploying through Docker-Compose. Install Docker-Compose on the instance.๐Ÿณ
  2. Security Configuration:

    • Edit inbound rules in security, adding port 8000 for improved access. Verify the application in the browser.๐Ÿšช
  3. GitHub Repository Integration:

    • Optimize code retrieval by adding a Jenkinsfile to the GitHub repository, containing pipeline code.๐Ÿ“
  4. Pipeline Configuration:

    • Choose the 'Pipeline from SCM' option in Jenkins.

    • Provide the GitHub repository URL, specify the branch, and mention the Jenkinsfile path. Save the configuration.๐Ÿ”—

  5. Automated Declarative Checkout:

    • Trigger builds with Declarative Checkout SCM by simply clicking 'Build.' The Jenkinsfile in the repository automates the process of code retrieval.๐Ÿค–
  6. Webhook Setup in GitHub:

    • In GitHub repository settings, add a webhook for automation.

    • In Jenkins, go to 'Configure' -> 'Build Triggers' -> select 'GitHub hook trigger for GitSCM polling' -> Save.๐Ÿ› ๏ธ

  7. Automated Build Trigger:

    • Any changes committed to the GitHub code trigger automatic builds in Jenkins, creating an efficient and automated build pipeline.๐Ÿ”„

These steps optimize the deployment process through Docker-Compose, enhance security, and automate the build process with GitHub integration, ensuring a seamless and efficient pipeline. ๐Ÿš€๐Ÿ”—

"๐Ÿ™Œ Thank you for taking the time to explore this blog!๐Ÿ“š I hope you found the information both helpful and insightful.โœจ

๐Ÿš€ Enjoy your learning journey, and don't hesitate to reach out if you have any feedback. ๐Ÿค“ Happy exploring!"

ย