DevOps(Day-81):Project-2
TABLE OF CONTENTS
Project Description
The project is about automating the deployment process of a web application using Jenkins and its declarative syntax. The pipeline includes stages like building, testing, and deploying to a staging environment. It also includes running acceptance tests and deploying to production if all tests pass.
Create an EC2 instance in the AWS management console with the required storage.
Install Jenkins and Docker in the EC2 instance.
Project Steps
- Navigate to the Jenkins dashboard and go to the new item. Then select Pipeline and create the project.
- In the general section provide the project description and also insert the GitHub project URL.
In the build trigger section select the GitHub webhook trigger option.
Ensure the webhook is configured in GitHub.
Ensure the project has a Docker file in GitHub.
Write the declarative pipeline code which is a groovy syntax code to set up the project pipeline.
agent:- Agent is the different servers that are linked to the master Jenkins server. An agent can be set up in the pipeline to run the pipelines in different agents. In this project, we are going with the default agent.
Stages:- Stages contain different steps to be executed as part of the project pipeline.
In this project we have 3 stages:-
Code:- The code stage pulls the code from Github to build and execute the pipeline in further steps.
Build and Test:- This stage builds the image of the app code from the docker file.
Run:- This stage runs the container in the server and makes the application up.
pipeline {
agent any
stages{
stage('Code'){
steps{
git url: 'https://github.com/Biswaraj/node-todo-cicd.git', branch: 'master'
}
}
stage('Build and Test'){
steps{
sh 'sudo docker build -t webapp .'
echo "build and ttest completed"
}
}
stage('Run'){
steps{
sh "sudo docker run -d -p 8000:8000 webapp"
}
}
}
}
After writing the detailed pipeline groovy scrip in the project configuration apply and save the project.
Now, navigate to the project and click on Build Now to execute the project.
We can see the successful console output and the stages that are completed in its stage executions as shown in the above and below screenshots.
Ensure to open the port 8000 in the security group associated with the EC2 instance.
Finally, navigate to the web-app URL and we can see the application is up & running.
Thanks for reading my article. Have a nice day.
WRITTEN BY Biswaraj Sahoo -- | DevOps Engineer | Docker | Linux | Jenkins | AWS | Git | Terraform | Docker | kubernetes
Empowering communities via open source and education. Connect with me over linktree: linktr.ee/biswaraj333