Table of contents
❄️Project:
Containerise and deploy a node.js application using Jenkins Job.
🔹Step 1
Fork the repo - https://github.com/Aishwarya-Portfolio/node-todo-cicd
🔹Step 2
Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration.
We can use SSH keys or PAT tokens to integrate the GitHub repo into Jenkins.
Here I am using SSH keys.
- Generate SSH key pair in your Jenkins instance.
ssh-keygen
I already have the key pair.
2. Create a new SSH key in GitHub and save the public key of Jenkins Instance.
3. Save the Private key in Jenkins credential.
4. Create a new Freestyle Jenkins Job -
5. Add source code GitHub Repo with added credential -
6. Now run the pipeline to check if the source code is checked out through Jenkins -
The repo files are present in Jenkins Workspace -
7. Now we need to set up a webhook for an automatic trigger from GitHub.
-- Install the GitHub integration plugin in Jenkins.
-- Create a Webhook.
The payload URL should be in the below format
http://jenkins_URL/github-webhook/
8. Do not forget to open port 8080 to Anywhere so that the GitHub webhook can reach Jenkins on port 8080.
The green tick shows that the connection is established.
9. In your Jenkins Job, enable GitHub Hook to trigger in the build trigger section.
10. To test the webhook, make some changes to the code and commit it.
Check if the Job was triggered by a push event.
🔹Step 3
In the Execute shell run the application using Docker compose.
- Create a Dockerfile to install all the dependencies and containerize the application.
2. Add a build step - Execute shell to build the docker image.
3. Docker image is created successfully.
4. Create a docker-compose file to run the container using this image.
5. Add the docker-compose up command to run the container.
6. The build is successful.
7. The container is up and running.
8. Since I want to run the application on Port 8100, I made changes in the app.js file.
9. Now my application is running.
Thank You for Reading! 📘