-
Notifications
You must be signed in to change notification settings - Fork 2
CI CD pipeline.
The goal was to implement continuous integration and continuous deployment (CI-CD) for the application.
We created CI-CD for our project using Jenkins. The steps involved are as follows:
- Jenkins will poll any changes pushed in the git repository of the specific branches.
- If it finds a push, it builds the image locally.
- It then logins to the docker hub and pushes the newly built image.
- It then login's to Kubernetes master and restarts the service which was recently updated.
- It logs out of the Kubernetes master.
- It logs out of the docker hub.
The JenkinsFile is functional and is monitored for each branch in the application. All the JenkinsFile can be found in branch: ci-cd-setup
Note: the sh
are the shell script commands.
stage('Initialize') {
steps {
script {
properties([pipelineTriggers([pollSCM('* * * * *')])])
}
git branch: 'ci-cd-setup' , url: 'https://github.com/airavata-courses/terra.git'
}
}
This stage is the initializing stage. The Git repository will be monitored on the branch, ci-cs-setup
. The JenkinsFile will scan for the recent pushes. Remember you can use this technique to trigger build after pushing in the repository instead of configuring WebHooks in the Git.
stage('Image Build') {
steps {
sh 'docker build -t gauti091/user-management:linux user.session.management/'
}
}
If in the previous stage, a push is detected, then, in this stage the image is built based on the recent code changes. The image will be built locally and stored.
stage('Docker Login') {
steps {
sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin'
}
}
In this stage, Jenkins will try to log in to the docker hub account. The DockerHub credentials should be stored in the 'Manage Credentials'.
stage('Docker Push') {
steps {
sh 'docker push gauti091/user-management:linux'
}
}
In this stage, the image built-in stage 2, which was stored locally will be pushed in the docker hub account which was logged in the previous step.
stage('Deploy image'){
steps{
sshagent(credentials:['kuber-root-some1']){
sh """ssh -tt [email protected] -o "StrictHostKeyChecking no" << EOF
whoami
kubectl get pods
kubectl rollout restart deployment/service-sql
pwd
ls
exit
EOF"""
}
This is an important stage. In this Jenkins will login to the Kubernetes master system and restart the pod. The Kubernetes will pull the recent code changes and deploy the pod. Remember here to generate the ssh-keys. The 'public key' should be copied into the remote server(Here, Kubernetes), and the private key must be stored in authorized_keys
of the Jenkins System/Client machine.
post {
always {
sh 'docker logout'
}
With this, Jenkins will log out of the docker hub.
Note: the sh
are the shell script commands.
Public Key(Denied)
It is because either the public key is not properly added to the remote server authorized_keys
or the private key local server authorized_keys
If you want the code to be built after a push event trigger in multiple branches then, Multi-branch pipeline would be beneficial. You can store the JenkinsFile in one branch which will monitor another branch then the build will be triggered by two branches. In a multi-branch pipeline, you need to store JenkinsFile in a branch and provide the path while configuring.
Install JDK first then Jenkins.
Milestone - 1:
Milestone - 2:
- Weather service and Forecasting service with 1 pod
- Weather Service and Forecasting Service with 3 and 5 pods
- User service - 1 pod
- User service -3 and 5 pods
- Auto Scaling
Milestone -3:
Milestone - 4: