DevOps Project(Step-by-step Implementation)

DevOps Project(Step-by-step Implementation)

DevOps Project - Jenkins Ci/Cd pipeline.


  1. To start with Simple-ChatBot-Web application deployment. Go to AWS Console.



--- 2. Now we will create an EC2 instance with configurations, t2.micro.




--- 3. Allow port 3000 and 8080 in Inbound rules.




--- 4. Connect to the created server and clone the code from the repository.

Git-Repo: https://github.com/skkatore/DevProject-ChatBot.git




--- 5. Now, we will Install Docker, by running the following command:

sudo apt-get update

sudo apt install docker.io

docker ps




--- 6. Now, we will Install Docker-Compose, by running the following command:

sudo apt-get update

sudo apt install docker-compose

docker-compose --version




--- 7. Now, we will Install Jave version 17, by running the following command:

sudo apt-get update

sudo apt install openjdk-17-jre

java --version




--- 8. Now, we will Install Jenkins for Ubuntu because in this Project I have user ubuntu, by running the following command:

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \

https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key

echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \

https://pkg.jenkins.io/debian-stable binary/ | sudo tee \

/etc/apt/sources.list.d/jenkins.list > /dev/null

sudo apt-get update

sudo apt-get install jenkins




--- 9. Now we are going to give User Permissions to Docker and Jenkins and after that we are going to Reboot the Instance, by using Command:

sudo usermod -aG docker $USER

sudo usermod -aG docker jenkins

sudo reboot




--- 10. Now again we are going to connect the instance.



--- 11. Now, we can see docker has been installed, by using command:

docker ps



--- 12. Create File

DockerFile:

# Use the official Node.js image from the Docker Hub

FROM node:22-alpine3.19

# Set the working directory in the container

WORKDIR /app

# Copy package.json and package-lock.json (if available) to the container

COPY package*.json ./

# Install dependencies

RUN npm install

# Copy the rest of your application code to the container

COPY . .

# Expose the port the app runs on

EXPOSE 3000

# Command to run the app

CMD ["node", "server.js"]




--- 13. Now we are going to see our Jenkins is started or in which state it is, By using Command:

service jenkins status




--- 14. So now we are going to Copy the Public IP address of Ec2 Instance and going to past in Browers new tab with :8080.




--- 15. After that will see the jenkins interface in we are going to copy the path where the password is stored and after that on our instance we are going to paste that path with small command which will show the password of it, By using command:

sudo cat /var/lib/jenkins/secret/initialAdminPassword




--- 16. After that we are going to install jenkins plugins. Like jenkins plugins which will be suggested by jenkins.



--- 17. After that we are going to Create Admin User.




--- 18. After creating Admin user it going to show Jenkins Dashboard in that in right side will see some options like New Item, Manage Jenkins and so on.

Step1: Click on Manage Jenkins.

Step2: Go Plugins under the System Configuration.

Step3: Click on available plugins.

Step4: Click on search option and search Pipeline Stage view plugin.

Step5: Click on Pipeline Stage view plugin and install it and go back to dashboard.




--- 19. Now Open DockerHub and create repo inside it by using any name.



--- 20. Now we are going to add DockerHub credentials inside the Jenkins.

Step1: Click on Manage Jenkins.

Step2: In side Manage Jenkins Click on Credentials under Security.

Step3: Click on system.

Step4: In side system Click on Global Credentials(unrestricted).

Step5: In side they Global Credentials(unrestricted) click on Add Credentials.

Step6: Add all DockerHub credentials, like DockerHub Username, Password, In Id Type dockerHub.




--- 21. Now add This Command on Ec2 Instance Machine:

sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo systemctl restart Jenkins

sudo systemctl restart docker




--- 22. Now we are going to create our Jenkins Ci/Cd pipeline.

Step1: Click on NewItem.

Step2: Give name to your Pipeline.

Step3: Click on Pipeline option and Ok.

Step4: In Configuration in General Give in Description any Description you want.

Step5: Click on GitHub Project and paste the Url of GitHub Repository.

Step6: In Build Trigger Click on GitHub hoom trigger for GITScm polling.

Step7: Down side In Pipeline Write a Script Or you can copy the Script from Repo from Jenkinsfile.




--- Pipeline Script:

pipeline {

agent any

stages{

stage("Clone Code"){

steps {

echo "Cloning the code"

git url:"https://github.com/skkatore/ChatBot.git", branch: "master"

}

}

stage("Build"){

steps {

echo "Building the image"

sh "docker build -t chatbot1.2 ."

}

}

stage("Push to Docker Hub"){

steps {

echo "Pushing the image to docker hub"

withCredentials([usernamePassword(credentialsId:"dockerHub",passwordVariable:"dockerHubPass",usernameVariable:"dockerHubUser")]){

sh "docker tag chatbot1.2 ${env.dockerHubUser}/chatbot1.2:latest"

sh "docker login -u ${env.dockerHubUser} -p ${env.dockerHubPass}"

sh "docker push ${env.dockerHubUser}/chatbot1.2:latest"

}

}

}

stage("Deploy"){

steps {

echo "Deploying the container"

sh "docker-compose down && docker-compose up -d"

}

}

}

}


Step8: Click on Save and Apply.

Step9: Click on Buid Now option. So it will build the Pipeline.




--- 23. Now Again Copy the Public IP Address of Ec2 Instance and Past it in Browser with :3000 port which we have allocated inside the Docker Container.




--- 24. Now It will show the insterFace of Web-App which we have Deployed on Server.


ChatBot-Web application is Up!!!


(You can further play with the stuff on your level to enhance new features)


Hope you find this helpful. Do follow for more such content.

~ Soham Katore.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了