From e4be41170bd2dd2bc892c718760b7214f9e2681b Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 12:20:06 -0400 Subject: [PATCH 01/15] Jenkins File added --- Dockerfile | 0 Jenkinsfile | 13 +++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 Dockerfile create mode 100644 Jenkinsfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e69de29b diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..478db317 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,13 @@ +pipeline{ + agent { + label 'Slave1-BuildServer' + } + + stages{ + stage ('git-clone'){ + steps{ + git branch: 'feature1', url: 'https://github.com/MithunEdappulath/projCert.git' + } + } + } +} \ No newline at end of file From fa3cf4fc82a70fa8425c322679bf3cea4991fdab Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 12:26:24 -0400 Subject: [PATCH 02/15] Docker file added --- Dockerfile | 10 ++++++++++ Jenkinsfile | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/Dockerfile b/Dockerfile index e69de29b..0ca1b381 100644 --- a/Dockerfile +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM php:7.4-apache + +WORKDIR /var/www/html + +COPY ./website /var/www/html + +EXPOSE 80 + +CMD ["apache2-foreground"] + diff --git a/Jenkinsfile b/Jenkinsfile index 478db317..ff8c0343 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,5 +9,11 @@ pipeline{ git branch: 'feature1', url: 'https://github.com/MithunEdappulath/projCert.git' } } + + stage ('Docker-Build'){ + steps{ + sh 'docker build -t mithun-app .' + } + } } } \ No newline at end of file From f6ac78f2ae7bfd24d43b5846c1ce0df47139689a Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 12:36:06 -0400 Subject: [PATCH 03/15] test --- test | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test diff --git a/test b/test new file mode 100644 index 00000000..e69de29b From 20fd5d03076ab06202d08abb9b71328605b6b99a Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 12:43:24 -0400 Subject: [PATCH 04/15] Corrected Jenkins File --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ff8c0343..b6bc252b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,7 @@ pipeline{ stages{ stage ('git-clone'){ steps{ - git branch: 'feature1', url: 'https://github.com/MithunEdappulath/projCert.git' + git branch: 'feature2', url: 'https://github.com/MithunEdappulath/projCert.git' } } From 61ee83b8b7d64de4a3f0c8a4e2de02a191829ba0 Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 13:11:10 -0400 Subject: [PATCH 05/15] testing docker credentials --- Jenkinsfile | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b6bc252b..4617dc49 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,7 +12,22 @@ pipeline{ stage ('Docker-Build'){ steps{ - sh 'docker build -t mithun-app .' + sh 'docker build -t $JOB_NAME:1.$BUILD_NUMBER .' + } + } + + stage ('Docker-Tag'){ + steps{ + sh 'docker tag $JOB_NAME:1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:1.$BUILD_NUMBER' + sh 'docker tag $JOB_NAME:1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:latest' + } + + stage('Docker-Image-Push'){ + steps{ + withCredentials([usernamePassword(credentialsId: 'docker-login-edurekaproject', passwordVariable: 'docker-password', usernameVariable: 'docker-username')]) { + echo "username: ${env.docker-username}, password: ${env.docker-password}" + } + } } } } From e9ef49fa0345c6a14d26759282e8c927d1ae9d27 Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 13:14:15 -0400 Subject: [PATCH 06/15] corrected --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4617dc49..76bd721a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -22,8 +22,8 @@ pipeline{ sh 'docker tag $JOB_NAME:1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:latest' } - stage('Docker-Image-Push'){ - steps{ + stage ('Docker-Image-Push'){ + steps{ withCredentials([usernamePassword(credentialsId: 'docker-login-edurekaproject', passwordVariable: 'docker-password', usernameVariable: 'docker-username')]) { echo "username: ${env.docker-username}, password: ${env.docker-password}" } From 1b378f18a8cdf9cfd2b62be326e73e3c9ac21b2f Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 13:17:22 -0400 Subject: [PATCH 07/15] corrected --- Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 76bd721a..dcc5276b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,12 +16,13 @@ pipeline{ } } - stage ('Docker-Tag'){ + stage ('Docker Image Tag'){ steps{ sh 'docker tag $JOB_NAME:1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:1.$BUILD_NUMBER' sh 'docker tag $JOB_NAME:1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:latest' } - + } + stage ('Docker-Image-Push'){ steps{ withCredentials([usernamePassword(credentialsId: 'docker-login-edurekaproject', passwordVariable: 'docker-password', usernameVariable: 'docker-username')]) { From adc2115ee1b3fb98bd5e12f164f8b6fc746b283d Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 13:19:43 -0400 Subject: [PATCH 08/15] corrected --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index dcc5276b..0d72c7e4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -22,14 +22,14 @@ pipeline{ sh 'docker tag $JOB_NAME:1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:latest' } } - + stage ('Docker-Image-Push'){ steps{ withCredentials([usernamePassword(credentialsId: 'docker-login-edurekaproject', passwordVariable: 'docker-password', usernameVariable: 'docker-username')]) { echo "username: ${env.docker-username}, password: ${env.docker-password}" } } - } } + } } \ No newline at end of file From 11c26c1bfa11daa686fa010bc688cf734ddee50c Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 13:23:14 -0400 Subject: [PATCH 09/15] error-debug --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0d72c7e4..8e568db8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,7 +26,7 @@ pipeline{ stage ('Docker-Image-Push'){ steps{ withCredentials([usernamePassword(credentialsId: 'docker-login-edurekaproject', passwordVariable: 'docker-password', usernameVariable: 'docker-username')]) { - echo "username: ${env.docker-username}, password: ${env.docker-password}" + echo "username: ${docker-username}, password: ${docker-password}" } } } From 44ae8f500bdc125b204c88a90b9e103e14b3bd67 Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 13:34:19 -0400 Subject: [PATCH 10/15] error-debug --- Jenkinsfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8e568db8..a8465e5e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,10 +25,11 @@ pipeline{ stage ('Docker-Image-Push'){ steps{ - withCredentials([usernamePassword(credentialsId: 'docker-login-edurekaproject', passwordVariable: 'docker-password', usernameVariable: 'docker-username')]) { - echo "username: ${docker-username}, password: ${docker-password}" - } + withCredentials([usernamePassword(credentialsId: 'edureka-project-docker-login', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) { + echo "Username: ${env.USERNAME}" + echo "Password: ${env.PASSWORD}" } + } } } From 71a48cc11a46a83a5d66235e8599395826793887 Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 13:40:40 -0400 Subject: [PATCH 11/15] Docker Image Push --- Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a8465e5e..796cd989 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,8 +26,9 @@ pipeline{ stage ('Docker-Image-Push'){ steps{ withCredentials([usernamePassword(credentialsId: 'edureka-project-docker-login', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) { - echo "Username: ${env.USERNAME}" - echo "Password: ${env.PASSWORD}" + sh "docker login -u ${env.USERNAME} -p ${env.PASSWORD}" + sh 'docker push mithunedappulath/$JOB_NAME:1.$BUILD_NUMBER' + sh 'docker push mithunedappulath/$JOB_NAME:latest' } } } From c5281f058225a11a534a17341981dea5191314a9 Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 13:56:39 -0400 Subject: [PATCH 12/15] Checking deploy stage --- Jenkinsfile | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 796cd989..0c992556 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,26 +12,42 @@ pipeline{ stage ('Docker-Build'){ steps{ - sh 'docker build -t $JOB_NAME:1.$BUILD_NUMBER .' + sh 'docker build -t $JOB_NAME:V1.$BUILD_NUMBER .' } } stage ('Docker Image Tag'){ steps{ - sh 'docker tag $JOB_NAME:1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:1.$BUILD_NUMBER' + sh 'docker tag $JOB_NAME:1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:V1.$BUILD_NUMBER' sh 'docker tag $JOB_NAME:1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:latest' + sh 'docker images' } } - stage ('Docker-Image-Push'){ + stage ('Image-Push to Docker-Hub'){ steps{ withCredentials([usernamePassword(credentialsId: 'edureka-project-docker-login', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) { sh "docker login -u ${env.USERNAME} -p ${env.PASSWORD}" - sh 'docker push mithunedappulath/$JOB_NAME:1.$BUILD_NUMBER' + sh 'docker push mithunedappulath/$JOB_NAME:V1.$BUILD_NUMBER' sh 'docker push mithunedappulath/$JOB_NAME:latest' } } } + + stage ('Docker Image Clean-up'){ + steps{ + sh 'docker rmi $JOB_NAME:V1.$BUILD_NUMBER' + sh 'docker rmi mithunedappulath/$JOB_NAME:V1.$BUILD_NUMBER' + sh 'docker rmi mithunedappulath/$JOB_NAME:latest' + } + } + + stage ('Deploy to Test-Server'){ + steps{ + echo 'Will be deployed soon - Working on' + } + } + } } \ No newline at end of file From 038506230a3b47b2413c2efe14daa94454ab0acf Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 13:59:15 -0400 Subject: [PATCH 13/15] Error-Debug --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0c992556..085cd341 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,8 +18,8 @@ pipeline{ stage ('Docker Image Tag'){ steps{ - sh 'docker tag $JOB_NAME:1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:V1.$BUILD_NUMBER' - sh 'docker tag $JOB_NAME:1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:latest' + sh 'docker tag $JOB_NAME:V1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:V1.$BUILD_NUMBER' + sh 'docker tag $JOB_NAME:V1.$BUILD_NUMBER mithunedappulath/$JOB_NAME:latest' sh 'docker images' } } From fa491ddda664513c03d00a7ef1467767fd08345f Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 15:19:22 -0400 Subject: [PATCH 14/15] deploy to test server --- Jenkinsfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 085cd341..9452f0b6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -44,7 +44,10 @@ pipeline{ stage ('Deploy to Test-Server'){ steps{ - echo 'Will be deployed soon - Working on' + sshagent(['QA-Test-Server']) { + sh 'ssh -o StrictHostKeyChecking=no -l devopsadmin 172.31.86.57 sudo docker images' + sh 'ssh -o StrictHostKeyChecking=no -l devopsadmin 172.31.86.57 sudo docker run -it -d --name edureka-project -p 80:80 mithunedappulath/edureka-project1' + } } } From 42e4b53baf00f293f159bb1559a86623938e482d Mon Sep 17 00:00:00 2001 From: mithunedappulath Date: Thu, 13 Apr 2023 15:25:15 -0400 Subject: [PATCH 15/15] Final Check --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 9452f0b6..e04deb25 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -46,6 +46,8 @@ pipeline{ steps{ sshagent(['QA-Test-Server']) { sh 'ssh -o StrictHostKeyChecking=no -l devopsadmin 172.31.86.57 sudo docker images' + sh 'ssh -o StrictHostKeyChecking=no -l devopsadmin 172.31.86.57 sudo docker rm -f edureka-project' + sh 'ssh -o StrictHostKeyChecking=no -l devopsadmin 172.31.86.57 sudo docker rmi -f mithunedappulath/edureka-project1' sh 'ssh -o StrictHostKeyChecking=no -l devopsadmin 172.31.86.57 sudo docker run -it -d --name edureka-project -p 80:80 mithunedappulath/edureka-project1' } }