Streamlining Node.js Application Deployment with Docker ??, Jenkins CI/CD , and GitHub Integration on Google Cloud Platform
Junaid Shaikh
Infrastructure Engineer at @SITA || Ex-Software Engineer @Persistent Systems || Azure Devops || 3x Google Cloud Certified || Microsoft AZ900 Certified || Jenkins || Terraform || Docker || Kubernetes || GKE || AKS || EKS
In today's fast-paced development environment, agility and efficiency are paramount. As a developer, deploying applications seamlessly while maintaining reliability is a constant challenge. However, with the right tools and strategies, this challenge can be turned into an opportunity for growth and innovation.
In this article, I'll walk you through the process of deploying a Node.js application using Docker, Jenkins CI/CD, and GitHub integration on Google Cloud Platform (GCP).
Prerequisites:
- Access to Google Cloud Platform (GCP) and a virtual machine (VM) instance.
- Installed Docker and Jenkins on the GCP VM instance.
- A GitHub repository hosting the Node.js application code.
Step 1: Pushing the Application Code to GitHub Repository from VS-code.
After executing these commands, your code changes should be pushed to your GitHub repository. You may need to authenticate with your GitHub username and password/token the first time you push.
Step 2: Creating Ubuntu VM on GCP and installing Jenkins in it
sudo apt update
sudo apt upgrade
sudo apt install openjdk-11-jre (Jenkins requires Java to run)
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' ( This command add Jenkins Repository Key)
sudo apt update
sudo apt install jenkins (Install Jenkins on it)
sudo systemctl start jenkins
sudo systemctl enable jenkins
领英推荐
Step 3: Integrating GitHub with Jenkins
Install Jenkins GitHub Plugin: In Jenkins, navigate to "Manage Jenkins" -> "Manage Plugins" -> "Available" and search for "GitHub Plugin". Install it and restart Jenkins.
Create GitHub Access Token: Go to your GitHub account settings, navigate to "Developer settings" -> "Personal access tokens", and generate a new token with "repo" scope.
Add GitHub Credentials to Jenkins: In Jenkins, go to "Manage Jenkins" -> "Manage Credentials" -> "Global credentials" -> "Add Credentials", select "Username with password" as the kind, and enter your GitHub username and the access token generated in the previous step.
Configure GitHub Webhook: In your GitHub repository settings, go to "Webhooks" -> "Add webhook", enter your Jenkins server URL followed by "/github-webhook/", and select the events you want Jenkins to trigger on.
Create a Jenkins Job: Create a new Jenkins job, select "Freestyle project", and configure it as needed (e.g., source code management, build triggers, build steps).
Add GitHub Repository URL: In the Jenkins job configuration, under "Source Code Management" select "Git" and enter the URL of your GitHub repository.
Use GitHub Credentials: Still in the Jenkins job configuration, select the GitHub credentials you added earlier from the dropdown menu under "Credentials".
Configure Build Triggers: Under "Build Triggers", select "GitHub hook trigger for GITScm polling" to enable Jenkins to trigger builds automatically when changes are pushed to the GitHub repository.
Save and Run the Job: Save the Jenkins job configuration, and then manually trigger a build to verify that everything is set up correctly.
This integration allows Jenkins to automatically build and test your GitHub projects whenever changes are made and pushed to the repository.
Step 4: Installing Docker on VM Server and Automating the Build using Jenkins
In this step, we'll install Docker on the VM server to facilitate containerization of our Node.js application. With Docker in place, we'll configure Jenkins to automate the build process by orchestrating Docker commands. Jenkins will pull the application code from GitHub, build Docker images, and push them to a registry. This seamless automation ensures consistency and reliability in the deployment pipeline, empowering developers to focus on innovation rather than manual tasks.
In summary, the fusion of Docker, Jenkins, and GitHub on Google Cloud Platform streamlines Node.js application deployment to new heights. Through seamless integration, this trifecta automates the build, test, and deployment phases, enabling teams to focus on innovation without compromising efficiency. This hands-on experience has deepened my understanding of the synergy between development, automation, and infrastructure. It's highlighted the pivotal role of standardized workflows and collaboration in streamlining deployment processes. Engaging with Docker, Jenkins, and GitHub has not only optimized efficiency but also emphasized the transformative potential of automation in modern software delivery. This journey underscores the importance of agility and innovation in driving continuous improvement within development teams.
AWS Cloud Engineer|AWS Cloud Practitioner certified|Front End Developer | React.js | HTML | CSS | JavaScript | Angular | JSON | Microsoft AZ900 Certified
10 个月??
@Senior Software Engineer || Learner.
10 个月Great ..! ???
Sr. Software Engineer at Winjit Technologies | C# | ASP.NET Core | Web APIs | MVC | EF Core | MS SQL Server | JavaScript | AJAX
10 个月Insightful!