Day 24 Jenkins CI/CD Project Completion: A To-Do List

ยท

5 min read

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:

  1. Jenkins installed and running (you should be familiar with Jenkins basics from Day 23).

  2. Docker and Docker Compose installed.

  3. GitHub Account & Repository โ€“ A GitHub account and your Node.js app repository should be ready for integration.

  4. GitHub WebHooks: Understanding how GitHub Webhooks work to trigger Jenkins builds.

  5. 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 ๐Ÿ“‚๐Ÿ”—

  1. Fork this repository.

  2. Set up a connection between your Jenkins job and your GitHub repository through GitHub Integration.

  3. Learn about GitHub WebHooks and ensure you have the CI/CD setup configured.

Step 1: Fork the Repository ๐Ÿ“

  1. Visit the node-todo-cicd GitHub repository.

  2. 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.

  1. 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.

  2. 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).

  3. 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.

  1. Go to your GitHub repo: Settings โ†’ Webhooks โ†’ Add webhook.

  2. Add the following details:

    • Payload URL: http://<your-jenkins-server>/github-webhook/.

    • Content type: application/json.

    • Event: Select Just the push event.

  3. Click Add Webhook.

    • Now, Jenkins will trigger builds automatically on code pushes!

Task 2: Run the Application Using Docker Compose ๐Ÿณ

  1. In the "Execute Shell" section of your Jenkins job, run the application using Docker Compose.

  2. Create a Docker Compose file for this project (a valuable open-source contribution).

  3. 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 ๐Ÿณ

  1. In your Jenkins job, go to Build โ†’ Add Build Step โ†’ Execute Shell.

  2. 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! ๐Ÿฅ‚

ย