Day 24 Jenkins CI/CD Project Completion: A To-Do List
Ready to level up your DevOps game? Let's create a rock-solid CI/CD pipeline for your Node.js application! ๐
By now, youโve already dived into Jenkins and Docker, so itโs time to put your skills to the test. If youโve just completed Day 23 of the #90DaysOfDevOps challenge, youโve got a good grip on Jenkins CI/CD basics. Today, we're taking everything to the next level! You'll be completing a real-world project from start to finish, something you can proudly showcase on your resume. ๐
Get ready to integrate Docker and Docker Compose into a live Node.js project and bring everything together using Jenkins. It's like putting together the ultimate puzzle, and once you're done, you'll have a fully functional CI/CD pipeline. Plus, you'll have a chance to contribute to open-source with a Docker Compose fileโhow cool is that? ๐
Prerequisites:
Before we dive in, make sure you have the following tools set up and ready to go:
Jenkins installed and running (you should be familiar with Jenkins basics from Day 23).
Docker and Docker Compose installed.
GitHub Account & Repository โ A GitHub account and your Node.js app repository should be ready for integration.
GitHub WebHooks: Understanding how GitHub Webhooks work to trigger Jenkins builds.
Basic knowledge of Node.js applications and how to run them.
Once you have these, youโre all set to go! Let's make some magic happen! โจ
TASKS
Task 1: Set Up Your Repository and Connect Jenkins with GitHub ๐๐
Fork this repository.
Set up a connection between your Jenkins job and your GitHub repository through GitHub Integration.
Learn about GitHub WebHooks and ensure you have the CI/CD setup configured.
Step 1: Fork the Repository ๐
Visit the node-todo-cicd GitHub repository.
Click the Fork button to create your own copy of the repository.
- Your forked repo will be available under your GitHub account.๐
Step 2: Connect Jenkins with GitHub ๐
Now that you have the repository, letโs establish a connection between Jenkins and GitHub. This will allow Jenkins to automatically trigger builds whenever you push changes to your GitHub repo.
Install GitHub Integration Plugin in Jenkins if you havenโt already.
Navigate to
Jenkins โ Manage Jenkins โ Manage Plugins โ Available
.Search for GitHub Plugin and install it.
Create a New Jenkins Job:
Go to
Jenkins โ New Item
.Enter a name like Node-Todo-CI-CD and select Freestyle Project.
Under Source Code Management, choose Git and:
Add your forked repo URL.
Add your GitHub credentials (username and personal access token).
Enable GitHub Webhooks for Builds:
- Under Build Triggers, select GitHub hook trigger for GITScm polling.
Step 3: Set Up GitHub Webhook ๐
Now that Jenkins is connected to GitHub, we need to set up a webhook to notify Jenkins of any new code changes.
Go to your GitHub repo:
Settings โ Webhooks โ Add webhook
.Add the following details:
Payload URL:
http://<your-jenkins-server>/github-webhook/
.Content type:
application/json
.Event: Select Just the push event.
Click Add Webhook.
- Now, Jenkins will trigger builds automatically on code pushes!
Task 2: Run the Application Using Docker Compose ๐ณ
In the "Execute Shell" section of your Jenkins job, run the application using Docker Compose.
Create a Docker Compose file for this project (a valuable open-source contribution).
Run the project and celebrate your accomplishment! ๐
Now that Jenkins is integrated with GitHub, itโs time to dockerize the Node.js application and run it with Docker Compose. This step ensures that your application runs consistently across different environments.
Step 1: Create a Docker Compose File ๐
In the root directory of your repository, create a file named docker-compose.yml
with the following content:
version: '3.8'
services:
app:
image: node:16
container_name: node-todo-app
working_dir: /app
volumes:
- .:/app
command: npm install && npm start
ports:
- "3000:3000"
networks:
- app-network
networks:
app-network:
driver: bridge
This file will do the following:
Uses Node.js 16 as the base image.
Mounts your project folder to the container (
/app
).Runs
npm install && npm start
to install dependencies and start the app.Maps port 3000 for browser access.
Defines a custom bridge network for container communication.
Step 2: Configure Jenkins to Use Docker Compose ๐ณ
In your Jenkins job, go to Build โ Add Build Step โ Execute Shell.
Add the following commands:
docker-compose -f /path/to/your/docker-compose.yml up --build -d
- This builds the Docker image and runs the Node.js app in detached mode.
Step 3: Test Your Pipeline ๐
Now, trigger the Jenkins job manually or push a change to your GitHub repository. Jenkins will pull the latest code from GitHub, build the Docker image, and start the Node.js application using Docker Compose. ๐
Go to your Jenkins dashboard to check the status of the build.
Once successful, open your browser and go to
http://localhost:3000
to see the app in action! ๐
๐ Wrapping It Up in Style! ๐
๐ Congratulations, DevOps champion! You've successfully tackled setting up a CI/CD pipeline for your Node.js application using Jenkins, GitHub, and Docker Compose. ๐
By forking the repository, connecting Jenkins to GitHub, and diving deep into WebHooks, you've built the foundation for continuous integration and delivery. Then, with the magic of Docker Compose, you containerized your app and brought it to life. ๐
Remember, DevOps isn't just about following stepsโit's about creating an automated, smooth pipeline that can deploy your code in the blink of an eye. So go ahead, hit the "Run" button, and let your hard work take off! ๐
Follow my DevOps journey:
๐LinkedIn
๐Hashnode
๐GitHub
Until next time, keep building cool things, and donโt forget to enjoy the process. ๐โจ
Cheers to your DevOps journey! ๐ฅ