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
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
Open Jenkins and Navigate to Dashboard: Log in to your Jenkins instance and click on "New Item" to create a new project.
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
Enable GitHub Project: Check the "GitHub project" checkbox.
Enter Project URL: In the "Project URL" field, input the URL of your GitHub repository.
Step 3: Set Up Source Code Management
Choose Git: In the "Source Code Management" section, select "Git."
Enter Repository URL: Input the URL of your GitHub repository.
Step 4: Configure Credentials
Generate SSH Keys: On your EC2 instance, run
ssh-keygen
to generate SSH keys. Use the generated public key for GitHubAdd SSH Key to GitHub: In GitHub settings, add a new SSH key with the generated public key.
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
Navigate to GitHub Settings: In your GitHub repository, click on "Settings" and select "Webhooks."
Add Webhook: Click "Add webhook" to set up a new webhook.
Step 9: Configure Webhook
Enter Payload URL: In the "Payload URL" field, enter ipaddress:8080/github-webhook/.
Set Content Type: Choose "application/json" as the content type.
Save Webhook: Click "Add webhook" to save your webhook configuration.
Install GitHub Integration Plugin
Step 10: Install GitHub Integration Plugin
Navigate to Jenkins Plugin Manager: In Jenkins, go to "Manage Jenkins" > "Manage Plugins."
Install Plugin: Search for "GitHub Integration" in the "Available" tab and install the plugin. Restart Jenkins when prompted.
Step 11: Test the Jenkins Job
Build Now: Go to your Jenkins job and click "Build Now" to test if the setup is correct.
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
Make Changes in GitHub: Make changes to your GitHub repository to test the webhook.
Check Jenkins: Observe Jenkins for triggered builds and successful deployments.
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! ๐