From 7d7a91b258e8d316de7b8566257664b307bf1d48 Mon Sep 17 00:00:00 2001 From: sridhar Date: Wed, 6 Sep 2023 16:47:51 +0530 Subject: [PATCH] added spc --- Jenkinsfile | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ deployement.yaml | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 Jenkinsfile create mode 100644 deployement.yaml diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..34ff90831 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,50 @@ +pipeline{ + agent{label 'dotnet-7'} + stages{ + stage('VCS'){ + steps{ + git credentialsId: 'GIT_HUB_CREDENTIALS', + url: 'https://github.com/Cloud-and-devops-notes/spring-petclinic-jenkins.git', + branch: 'tera' + + + } + } + stage('artifact build'){ + steps{ + sh 'sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys B53DC80D13EDEF05' + sh 'sudo apt upgrade dotnet-sdk-7.0 -y' + sh 'dotnet restore src/NopCommerce.sln' + sh 'dotnet build -c Release src/NopCommerce.sln' + sh 'dotnet publish -c Release src/Presentation/Nop.Web/Nop.Web.csproj -o publish' + sh 'sudo apt install zip -y' + sh 'zip -r nopCommerce.zip publish' + archive '**/nopCommerce.zip' + sh 'docker image list' + } + } + + stage('docker login'){ + steps{ + withCredentials([string(credentialsId: 'DOCKER_HUB_PASSWORD',variable: 'PASSWORD')]) { + sh 'docker login -u sridhar006 -p $PASSWORD' + } + } + } + stage('docker push image '){ + steps{ + sh 'docker image build -t nop123 .' + sh 'docker image tag nop123 sridhar006/nopaugest:${BUILD_ID}' + sh 'docker push sridhar006/nopaugest:${BUILD_ID}' + + } + } + stage("kubernetes deployment"){ + steps{ + sh 'kubectl apply -f deployment.yaml' + } + + } + + } + } diff --git a/deployement.yaml b/deployement.yaml new file mode 100644 index 000000000..9650d86c8 --- /dev/null +++ b/deployement.yaml @@ -0,0 +1,46 @@ + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nop + labels: + app: nop +spec: + minReadySeconds: 5 + replicas: 4 + selector: + matchLabels: + app: nop + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + template: + metadata: + labels: + app: nop + name: nop + spec: + containers: + - name: nop + image: sridhar006/nopaugest:26 + ports: + - containerPort: 5000 + +--- +apiVersion: v1 +kind: Service +metadata: + name: nop +spec: + selector: + app: nop + type: ClusterIP + ports: + - protocol: TCP + name: nop + port: 80 + targetPort: 5000 + type: LoadBalancer \ No newline at end of file