Setting Up a Jenkins CI/CD Pipeline for Deploying a Node.js To-Do App with Docker Compose and GitHub Integration

Setting Up a Jenkins CI/CD Pipeline for Deploying a Node.js To-Do App with Docker Compose and GitHub Integration

Day 25 & 26: Complete Jenkins CI/CD Project

ยท

3 min read

Introduction

Welcome to this comprehensive guide on setting up a Jenkins CI/CD pipeline for deploying a Node.js To-Do app using Docker Compose, seamlessly integrated with GitHub. In this tutorial, we'll walk you through each step, providing detailed explanations and additional information to ensure a smooth setup.

Prerequisites

Before we begin, make sure you have the following prerequisites:

  • Your EC2 instance is up and running.

  • Jenkins is installed and running.

  • Docker and Docker Compose are installed on your server.

Setting Up Jenkins Job

Step 1: Create a New Freestyle Project

  1. Open Jenkins and Navigate to Dashboard: Log in to your Jenkins instance and click on "New Item" to create a new project.

  2. Enter Project Details: Provide a name for your project, such as "todo-node-app," and select the "Freestyle project" option. Click "OK" to create the project.

Step 2: Configure GitHub Project

  1. Enable GitHub Project: Check the "GitHub project" checkbox.

  2. Enter Project URL: In the "Project URL" field, input the URL of your GitHub repository.

Step 3: Set Up Source Code Management

  1. Choose Git: In the "Source Code Management" section, select "Git."

  2. Enter Repository URL: Input the URL of your GitHub repository.

Step 4: Configure Credentials

  1. Generate SSH Keys: On your EC2 instance, run ssh-keygen to generate SSH keys. Use the generated public key for GitHub

  2. Add SSH Key to GitHub: In GitHub settings, add a new SSH key with the generated public key.

  3. Jenkins Credentials: In Jenkins credentials section, select "SSH username with private key" and enter the private key directly.

Step 5: Set Up Build Triggers

Enable GitHub Hook Trigger: Check "GitHub hook trigger for GITScm polling" to trigger Jenkins upon code changes.

Step 6: Define Build Steps

Add Execute Shell Build Step: In the "Build" section, add an "Execute shell" build step. Enter the Docker Compose commands to handle Docker actions.

Step 7: Save the Jenkins Job

Click "Save" to store your Jenkins job configuration.

GitHub Webhook Configuration

Step 8: GitHub Webhook Setup

  1. Navigate to GitHub Settings: In your GitHub repository, click on "Settings" and select "Webhooks."

  2. Add Webhook: Click "Add webhook" to set up a new webhook.

Step 9: Configure Webhook

  1. Enter Payload URL: In the "Payload URL" field, enter ipaddress:8080/github-webhook/.

  2. Set Content Type: Choose "application/json" as the content type.

  3. Save Webhook: Click "Add webhook" to save your webhook configuration.

Install GitHub Integration Plugin

Step 10: Install GitHub Integration Plugin

  1. Navigate to Jenkins Plugin Manager: In Jenkins, go to "Manage Jenkins" > "Manage Plugins."

  2. Install Plugin: Search for "GitHub Integration" in the "Available" tab and install the plugin. Restart Jenkins when prompted.

Step 11: Test the Jenkins Job

  1. Build Now: Go to your Jenkins job and click "Build Now" to test if the setup is correct.

  2. Check Console Output: Monitor the build console output for any errors or issues.

Step 12: Test the Deployment

Open Browser: In your web browser, navigate to <ipaddress:8000> to verify that your app is successfully deployed.

Step 13: Verify Webhook

  1. Make Changes in GitHub: Make changes to your GitHub repository to test the webhook.

  2. Check Jenkins: Observe Jenkins for triggered builds and successful deployments.

  3. Verify Deployment: Confirm the changes by checking the deployed app in the browser at <ipaddress:8000>.

Conclusion

Congratulations! You've successfully configured a Jenkins CI/CD pipeline to automate the deployment of your Node.js To-Do app, integrated seamlessly with GitHub. Embrace the power of CI/CD for efficient and reliable software delivery.

Happy Learning! ๐ŸŽ‰

ย