0% found this document useful (0 votes)
29 views6 pages

Task For DevOps Engineer

eee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views6 pages

Task For DevOps Engineer

eee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

install docker

apt-get install docker.io

set2

pull image in to docker hub

docker pull tutum/hello-world

bild

docker build –t name .

docker run image name

docker login

give the crdinteles in user name and password

create repo

public or private

docker push repo name

manual process

scriptway devops apporoch

stage("Docker Build & Push"){

steps{

script{

withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){

sh "docker build -t name of image ."

sh "docker tag tetrisv2 name:latest "

sh "docker push name:latest "

}
Write deployment for kubernites

apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 4
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: give the continer name
image: name of continer :latest
ports:
- containerPort: 8080

Hear I creating 4 repli

Wre need to used one of servies in we have 3 servies


Cluster id
Node pot
Loadblancer ,ingress
---
Hear I am using load balancer
apiVersion: v1
kind: Service
metadata:
name: my-app-lb
labels:
app: my-app-lb
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: my-app-lb

wre can write in single file


Define the CI/CD pipeline as code using a Jenkinsfile.
The pipeline should include the following stages:
Build: Compile the Java application using Maven.

Now complete script

pipeline{
agent any
tools{
jdk 'jdk17'
nodejs 'node16'
}
environment {
SCANNER_HOME=tool 'sonar-scanner'
GIT_REPO_NAME = ""
GIT_USER_NAME = "" # change your Github Username here
}

stage('Checkout from Git'){


steps{
git branch: 'main', url: '”””””
}
}

stage('Build and Test') {

steps {
// Use Maven to build and run JUnit tests
script {
def mavenHome = tool 'Maven' dir change
sh "${mavenHome}/bin/mvn clean test"
}
}

post {
always {
// Publish JUnit test results
junit 'target/surefire-reports/*.xml'
}
}
}
}
} Add junit test install plugin in we
stages {
stage('clean workspace'){
steps{
cleanWs()
}
}
}
}
Code qulaty puroues
stage("Sonarqube Analysis "){
steps{
withSonarQubeEnv('sonar-server') {
sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=TetrisVersion2.0 \
-Dsonar.projectKey=TetrisVersion2.0 '''
}
}
}
stage("quality gate"){
steps {
script {
waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-token'
}
}
}
stage('Install Dependencies') { piojects dependences
steps {
sh "npm install"
}
}

stage("Docker Build & Push"){

steps{

script{

withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){

sh "docker build -t name of image ."

sh "docker tag tetrisv2 name:latest "

sh "docker push name:latest "

}
Image scan

stage("TRIVY"){

steps{

sh "trivy image :latest > trivyimage.txt" hear we scan the image in 2 time once build and push
Irepo again we scan it

stage('Checkout Code') {

steps {

git branch: 'main', url: '' /deployment file is we keep another repo we call hear

stage('Update Deployment File') {

steps {
script {
withCredentials([string(credentialsId: 'github', variable: 'GITHUB_TOKEN')]) {
NEW_IMAGE_NAME = "sevenajay/tetrisv2:latest" #update your image here
sh "sed -i 's|image: .*|image: $NEW_IMAGE_NAME|' deployment.yml"
sh 'git add deployment.yml'
sh "git commit -m 'Update deployment image to $NEW_IMAGE_NAME'"
sh "git push
https://${GITHUB_TOKEN}@github.com/${GIT_USER_NAME}/${GIT_REPO_NAME} HEAD:main" image is
automaticallt update in the git repo
it gtopsway
}
}
}
}
}
}
Integrating git wth Jenkins

Sep 1: interate Jenkins


Settings webhook- give url jinkenas - see green tick mark  install gitpilgin in Jenkins

Step2 :

Crate Jenkins pliple job write script in Jenkins file -or writtin Jenkins script inside the jinks

You might also like