Day 24 of 90 Days of DevOps Challenge: Complete Jenkins CI/CD Project for Node.js Application
Welcome to Day 24 of the 90 Days of DevOps challenge! 🎉 Today, we’ll dive into setting up a complete CI/CD pipeline using Jenkins for a Node.js application. This is an exciting step as you’ll apply everything you’ve learned so far in a real-world project.
Let’s get started! 🚀
Task-01: Set Up GitHub Integration and Webhooks
1. Fork the Repository
Begin by forking this repository for the Node.js application.
This will create a copy of the project in your GitHub account that you can modify and integrate with Jenkins.
2. Create a Jenkins Job
Create a New Job:
Open Jenkins and create a new job by selecting "New Item."
Choose "Freestyle project" and give it a name relevant to your Node.js application.
Configure Source Code Management:
In the job configuration, go to the "Source Code Management" section.
Select "Git" and enter the URL of your forked repository.
Provide credentials if required to access the repository.
3. Integrate GitHub Webhooks
Configure GitHub Webhooks:
Go to your GitHub repository settings.
Navigate to "Webhooks" and click "Add webhook."
Set the Payload URL to your Jenkins server URL followed by
/github-webhook/
(e.g.,http://your-jenkins-url/github-webhook/
).Choose the content type as
application/json
.Select the events that will trigger the webhook. Typically, you’ll select "Just the push event."
Save the webhook configuration.
Configure GitHub Plugin in Jenkins:
In Jenkins, go to the job configuration and scroll to the "Build Triggers" section.
Check the "GitHub hook trigger for GITScm polling" option.
This allows Jenkins to be notified of changes in the GitHub repository and automatically trigger builds.
Task-02: Set Up Docker Compose and Run the Project
1. Create a Docker Compose File
Define the Docker Compose File:
Create a
docker-compose.yml
file in your project’s root directory. This file defines the services required for your Node.js application.Here’s a basic example of a Docker Compose file for a Node.js app:
version: '3'
services:
web:
image: "trainwithshubham/node-app-batch-6:latest"
working_dir: /app
volumes:
- .:/app
ports:
- "5000:5000"
command: npm start
2. Update Jenkins Job to Use Docker Compose
Configure Build Steps:
In your Jenkins job configuration, go to the "Build" section.
Add a build step to execute the shell command:
docker-compose up -d
Clean Up After Build:
- Optionally, add a post-build step to clean up resources:
docker-compose down
3. Run the Project and Celebrate
Trigger a Build:
Manually trigger a build in Jenkins or push a change to your GitHub repository to automatically trigger the pipeline.
Jenkins will use Docker Compose to build and run your Node.js application.
4. Verify the build
Trigger a Build:
Go to appropriate port of your locanhost and verify that the application is running.
Conclusion
Today’s task focused on integrating Jenkins with GitHub and Docker to create a robust CI/CD pipeline for a Node.js application. This project not only solidifies your understanding of CI/CD practices but also adds a valuable experience to your resume. Keep exploring and refining your skills, and continue to push the boundaries of what you can achieve with DevOps! 🚀
Share your progress and any interesting insights on LinkedIn to inspire others in the DevOps community. 😊