added jenkins docker deploymet files in new test breanch

This commit is contained in:
bhanu 2024-07-12 16:36:24 +05:30
parent d8fcd11e67
commit 2e06455b5e
4 changed files with 109 additions and 0 deletions

12
Dockerfile Normal file
View file

@ -0,0 +1,12 @@
FROM openjdk:21-jdk
LABEL project="petclinic"
LABEL author="bhanu"
EXPOSE 8080
ARG artifact=target/*.ja
COPY ${artifact} /spring-petclinic.jar
ENTRYPOINT ["java", "-jar", "/spring-petclinic.jar"]

63
Jenkinsfile vendored Normal file
View file

@ -0,0 +1,63 @@
pipeline {
agent { label 'hello' }
stages {
stage('Checkout') {
steps {
sh 'echo passed'
//git branch: 'main', url: 'https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero.git'
}
}
stage('Build and Test') {
steps {
sh 'ls -ltr'
// build the project and create a JAR file
sh 'mvn clean package'
}
}
stage('Static Code Analysis') {
environment {
SONAR_URL = "http://20.197.43.119:32768"
}
steps {
withCredentials([string(credentialsId: 'sonarqube', variable: 'SONAR_AUTH_TOKEN')]) {
sh 'mvn sonar:sonar -Dsonar.login=$SONAR_AUTH_TOKEN -Dsonar.host.url=${SONAR_URL}'
}
}
}
stage('Build and Push Docker Image') {
environment {
DOCKER_IMAGE = "bhanu3333/kube:${BUILD_NUMBER}"
// DOCKERFILE_LOCATION = "java-maven-sonar-argocd-helm-k8s/spring-boot-app/Dockerfile"
REGISTRY_CREDENTIALS = credentials('docker-cred')
}
steps {
script {
sh 'docker build -t ${DOCKER_IMAGE} .'
def dockerImage = docker.image("${DOCKER_IMAGE}")
docker.withRegistry('https://index.docker.io/v1/', "docker-cred") {
dockerImage.push()
}
}
}
}
stage('Update Deployment File') {
environment {
GIT_REPO_NAME = "Jenkins-Zero-To-Hero"
GIT_USER_NAME = "vuyyuru-bhanu"
}
steps {
withCredentials([string(credentialsId: 'github', variable: 'GITHUB_TOKEN')]) {
sh '''
git config user.email "prasad.bhanu59@gmial.com"
git config user.name "bhanu"
BUILD_NUMBER=${BUILD_NUMBER}
sed -i "s/replaceImageTag/${BUILD_NUMBER}/g" deployment.yml
git add deployment.yml
git commit -m "Update deployment image to version ${BUILD_NUMBER}"
git push https://${GITHUB_TOKEN}@github.com/${GIT_USER_NAME}/${GIT_REPO_NAME} HEAD:test
'''
}
}
}
}
}

21
deployment.yml Normal file
View file

@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-boot-app
labels:
app: spring-boot-app
spec:
replicas: 2
selector:
matchLabels:
app: spring-boot-app
template:
metadata:
labels:
app: spring-boot-app
spec:
containers:
- name: spring-boot-app
image: bhanu3333/kube:replaceImageTag
ports:
- containerPort: 8080

13
service.yml Normal file
View file

@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: spring-boot-app-service
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: 8080
protocol: TCP
selector:
app: spring-boot-app