Architecture of Project
Setup GitHub repository for source code and CI
GitHub repository used -> node-todo
Note : If you need detailed overview you can also view this Blog.
Setup Job on Jenkins for application
Create EC2 instance for Jenkins server
Update repository packages
Create Job,
- Add basic script for testing,
pipeline{
agent any;
stages{
stage("Code"){
steps{
echo "Source code fetched........."
}
}
stage("Build"){
steps{
echo "Image created SUCCESS........."
}
}
stage("Push"){
steps{
echo "Pushing to dockerhub........."
}
}
stage("Deploy"){
steps{
echo "Deployement done........."
}
}
}
}
Setup security credentials in Jenkins
GitHub credentials
Go to, Dashboard -> Manage Jenkins -> Credentials -> System -> Global credentials -> Add Credentials
-> Go to Github.com and create Personal Access Token.
DockerHub Credentials
Go to, Dashboard -> Manage Jenkins -> Credentials -> System -> Global credentials -> Add Credentials
Setup GitHub WebHook
Go to repository -> Setting -> Webhook -> Add WebHook
Payload URL -: IP_of_Jenkins:8080/github-webhook
Setup CI/CD pipeline
pipeline{
agent any;
stages{
stage("Code"){
steps{
echo "Pulling source code from GitHub...."
git url: "https://github.com/ojasjawale/node-todo-cicd.git/", branch: "master"
}
}
stage("Build"){
steps{
echo "Image building started........."
sh 'docker build -t node-app:v1 .'
echo "Image Build SUCCESS............"
}
}
stage("Push"){
steps{
withCredentials([usernamePassword(credentialsId: 'dockerhub-cred', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
sh 'docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}'
sh 'docker image tag node-app:v1 ${DOCKER_USER}/node-app:v1'
sh 'docker push ${DOCKER_USER}/node-app:v1'
echo "Image pushed to DockerHub successfully......."
}
}
}
stage("Deploy"){
steps{
echo "Deployement In-progress........."
sh 'docker stop node-app && docker rm node-app'
sh 'docker run --name node-app -p 8000:8000 ojasjawale/node-app:v1'
echo "Deployement SUCCESS........."
}
}
}
}
- Build the Job,
- Access application,
Connect With Me
Follow me for more amazing content :)