From 97a012f6697af3597c9f4860bbfa17a7a58e6621 Mon Sep 17 00:00:00 2001 From: User Date: Thu, 2 Feb 2023 11:54:06 +0000 Subject: [PATCH 01/19] update ip --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 55a50c4..b6bbd1c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,7 +19,7 @@ pipeline { } stage('SSH Build Deploy'){ steps{ - sh '''ssh -i "~/.ssh/jenkins_key" jenkins@$appIP << EOF + sh '''ssh -i "~/.ssh/id_rsa" jenkins@104.197.233.99 << EOF rm -rf $repoName git clone $gitRepo cd $repoName From 9dee89e77c69d7246749bb78c6b66880db81b692 Mon Sep 17 00:00:00 2001 From: User Date: Thu, 2 Feb 2023 11:58:08 +0000 Subject: [PATCH 02/19] updating env variables --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b6bbd1c..ac5ad15 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,9 +1,9 @@ pipeline { agent any environment { - appIP=""; - gitRepo=""; - repoName=""; + appIP="104.197.233.99"; + gitRepo="https://github.com/kashbhull/SpringBoot-Jenkins-kb.git"; + repoName="main"; } stages{ stage('Test Application'){ From f930de2994aef3e584d61fec086c13cdb7aeed8c Mon Sep 17 00:00:00 2001 From: User Date: Thu, 2 Feb 2023 12:00:29 +0000 Subject: [PATCH 03/19] updating env variables --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ac5ad15..2da0a86 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,7 @@ pipeline { environment { appIP="104.197.233.99"; gitRepo="https://github.com/kashbhull/SpringBoot-Jenkins-kb.git"; - repoName="main"; + repoName=""; } stages{ stage('Test Application'){ From 1a7e077c03c32c1e71f9e076f9403dd79fd1ff16 Mon Sep 17 00:00:00 2001 From: User Date: Thu, 2 Feb 2023 12:04:50 +0000 Subject: [PATCH 04/19] updating env variables --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2da0a86..b3f667e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,7 @@ pipeline { environment { appIP="104.197.233.99"; gitRepo="https://github.com/kashbhull/SpringBoot-Jenkins-kb.git"; - repoName=""; + repoName="SpringBoot-Jenkins-kb"; } stages{ stage('Test Application'){ From f7ddcf3a6a9eb2bd71aaec0a30a261505cbe6ba1 Mon Sep 17 00:00:00 2001 From: User Date: Thu, 2 Feb 2023 14:36:03 +0000 Subject: [PATCH 05/19] updating with Piers config --- Dockerfile | 9 +++++++ Jenkinsfile | 69 ++++++++++++++++++++--------------------------------- 2 files changed, 35 insertions(+), 43 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..657927c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM openjdk:11-jre-slim + +WORKDIR /app + +COPY ./target/tdl-1.0.0.war . + +EXPOSE 8080 + +ENTRYPOINT ["java","-jar","tdl-1.0.0.war"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index b3f667e..6c4396a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,64 +17,47 @@ pipeline { sh 'mv ./target/surefire-reports/*.txt /home/jenkins/Tests/${BUILD_NUMBER}_tests/' } } - stage('SSH Build Deploy'){ + stage('Build Application'){ steps{ - sh '''ssh -i "~/.ssh/id_rsa" jenkins@104.197.233.99 << EOF - rm -rf $repoName - git clone $gitRepo - cd $repoName - rm -f ./src/main/resources/application-dev.properties - mvn clean package - ''' + sh 'mvn clean package' } } - stage('Moving War'){ + stage('Docker Build'){ steps{ - sh '''ssh -i "~/.ssh/jenkins_key" jenkins@$appIP << EOF - cd $repoName - mkdir -p /home/jenkins/Wars - mv ./target/*.war /home/jenkins/Wars/project_war.war + sh ''' + docker build -t stratcastor/$imageName:latest -t stratcastor/$imageName:build-$BUILD_NUMBER . ''' } - } - stage('Stopping Service'){ + } + stage('Push Images'){ steps{ - sh '''ssh -i "~/.ssh/jenkins_key" jenkins@$appIP << EOF - cd $repoName - bash stopservice.sh + sh ''' + docker push stratcastor/$imageName:latest + docker push stratcastor/$imageName:build-$BUILD_NUMBER ''' } - } - stage('Create new service file'){ + } + stage('Restart Container'){ steps{ - sh '''ssh -i "~/.ssh/jenkins_key" jenkins@$appIP << EOF - mkdir -p /home/jenkins/appservice - echo '#!/bin/bash -sudo java -jar /home/jenkins/Wars/project_war.war' > /home/jenkins/appservice/start.sh -sudo chmod +x /home/jenkins/appservice/start.sh -echo '[Unit] -Description=My SpringBoot App - -[Service] -User=ubuntu -Type=simple - -ExecStart=/home/jenkins/appservice/start.sh - -[Install] -WantedBy=multi-user.target' > /home/jenkins/myApp.service -sudo mv /home/jenkins/myApp.service /etc/systemd/system/myApp.service + sh ''' + ssh -i "~/.ssh/jenkins_key" jenkins@$appIP << EOF + if [ ! "$(docker ps -a -q -f name=$containerName)" ]; then + if [ "$(docker ps -aq -f status=exited -f name=$containerName)" ]; then + docker rm -f $containerName + docker rmi $imageName + fi + # run your container + docker run -d -p 8080:8080 --name $containerName $imageName + fi ''' } } - stage('Reload and restart service'){ + stage('Clean Up'){ steps{ - sh '''ssh -i "~/.ssh/jenkins_key" jenkins@$appIP << EOF - sudo systemctl daemon-reload - sudo systemctl restart myApp + sh ''' + docker system prune -f ''' } } - } -} +} \ No newline at end of file From 64929a4228df349a253d5511787ce093445f36cd Mon Sep 17 00:00:00 2001 From: User Date: Thu, 2 Feb 2023 14:39:49 +0000 Subject: [PATCH 06/19] updating with Piers config --- Jenkinsfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6c4396a..fdd7490 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,8 +2,8 @@ pipeline { agent any environment { appIP="104.197.233.99"; - gitRepo="https://github.com/kashbhull/SpringBoot-Jenkins-kb.git"; - repoName="SpringBoot-Jenkins-kb"; + containerName="java"; + imageName="java"; } stages{ stage('Test Application'){ @@ -25,15 +25,15 @@ pipeline { stage('Docker Build'){ steps{ sh ''' - docker build -t stratcastor/$imageName:latest -t stratcastor/$imageName:build-$BUILD_NUMBER . + docker build -t ksbhull/$imageName:latest -t ksbhull/$imageName:build-$BUILD_NUMBER . ''' } } stage('Push Images'){ steps{ sh ''' - docker push stratcastor/$imageName:latest - docker push stratcastor/$imageName:build-$BUILD_NUMBER + docker push ksbhull/$imageName:latest + docker push ksbhull/$imageName:build-$BUILD_NUMBER ''' } } From 98ceafb324c71441a49d3a8b4a2b00b41520cd18 Mon Sep 17 00:00:00 2001 From: User Date: Thu, 2 Feb 2023 14:42:39 +0000 Subject: [PATCH 07/19] updating with Piers config --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index fdd7490..d682466 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -40,7 +40,7 @@ pipeline { stage('Restart Container'){ steps{ sh ''' - ssh -i "~/.ssh/jenkins_key" jenkins@$appIP << EOF + ssh -i "~/.ssh/id_rsa" jenkins@$appIP << EOF if [ ! "$(docker ps -a -q -f name=$containerName)" ]; then if [ "$(docker ps -aq -f status=exited -f name=$containerName)" ]; then docker rm -f $containerName From 324dbb7ea328623b27e0ffa19fa648e5a55e5467 Mon Sep 17 00:00:00 2001 From: KashB <100960298+kashbhull@users.noreply.github.com> Date: Tue, 7 Feb 2023 09:15:40 +0000 Subject: [PATCH 08/19] Update Jenkinsfile --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d682466..ca46971 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ pipeline { agent any environment { - appIP="104.197.233.99"; + appIP="35.226.220.179"; containerName="java"; imageName="java"; } @@ -60,4 +60,4 @@ pipeline { } } } -} \ No newline at end of file +} From a1ab1f8df3d132dd848c3743256821f685f4dad5 Mon Sep 17 00:00:00 2001 From: KashB <100960298+kashbhull@users.noreply.github.com> Date: Tue, 7 Feb 2023 09:38:26 +0000 Subject: [PATCH 09/19] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ca46971..f279f7c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,7 @@ pipeline { environment { appIP="35.226.220.179"; containerName="java"; - imageName="java"; + imageName="javakb"; } stages{ stage('Test Application'){ From a4f97df622d8e9554fd945704ebaf4a405d626b9 Mon Sep 17 00:00:00 2001 From: KashB <100960298+kashbhull@users.noreply.github.com> Date: Tue, 7 Feb 2023 11:41:15 +0000 Subject: [PATCH 10/19] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f279f7c..f0fb9f9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,7 +25,7 @@ pipeline { stage('Docker Build'){ steps{ sh ''' - docker build -t ksbhull/$imageName:latest -t ksbhull/$imageName:build-$BUILD_NUMBER . + docker build -t ksbhull/$imageName:build-$BUILD_NUMBER . ''' } } From c9c6a4820bfe00beb7545afbf72d8ffb943fa7a2 Mon Sep 17 00:00:00 2001 From: KashB <100960298+kashbhull@users.noreply.github.com> Date: Tue, 7 Feb 2023 11:57:52 +0000 Subject: [PATCH 11/19] Update Jenkinsfile --- Jenkinsfile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f0fb9f9..2dc326d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -37,18 +37,18 @@ pipeline { ''' } } - stage('Restart Container'){ + + stage('Stopping Container'){ steps{ - sh ''' - ssh -i "~/.ssh/id_rsa" jenkins@$appIP << EOF - if [ ! "$(docker ps -a -q -f name=$containerName)" ]; then - if [ "$(docker ps -aq -f status=exited -f name=$containerName)" ]; then - docker rm -f $containerName - docker rmi $imageName - fi - # run your container - docker run -d -p 8080:8080 --name $containerName $imageName - fi + sh '''ssh -i "~/.ssh/id_rsa" jenkins@$appIP << EOF + docker rm -f $containerName + ''' + } + } + stage('Restart App'){ + steps{ + sh '''ssh -i "~/.ssh/id_rsa" jenkins@$appIP << EOF + docker run -d -p 8080:8080 --name $containerName $imageName ''' } } From 30f3ec6a49c489722d288b33699fb50a1652bc3c Mon Sep 17 00:00:00 2001 From: KashB <100960298+kashbhull@users.noreply.github.com> Date: Tue, 7 Feb 2023 12:02:53 +0000 Subject: [PATCH 12/19] Update Jenkinsfile --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2dc326d..699f344 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,7 +25,7 @@ pipeline { stage('Docker Build'){ steps{ sh ''' - docker build -t ksbhull/$imageName:build-$BUILD_NUMBER . + docker build -t ksbhull/$imageName:latest . ''' } } @@ -33,7 +33,6 @@ pipeline { steps{ sh ''' docker push ksbhull/$imageName:latest - docker push ksbhull/$imageName:build-$BUILD_NUMBER ''' } } From 37108eb0d1ea599ca66942a4a3cf15b6b496469f Mon Sep 17 00:00:00 2001 From: KashB <100960298+kashbhull@users.noreply.github.com> Date: Tue, 7 Feb 2023 12:12:00 +0000 Subject: [PATCH 13/19] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 699f344..34c8453 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -47,7 +47,7 @@ pipeline { stage('Restart App'){ steps{ sh '''ssh -i "~/.ssh/id_rsa" jenkins@$appIP << EOF - docker run -d -p 8080:8080 --name $containerName $imageName + docker run -d -p 8080:8080 --name $containerName ksbhull/$imageName ''' } } From fc49bd04155f9b972afdaf794c6b31d8e8f8c5b0 Mon Sep 17 00:00:00 2001 From: KashB <100960298+kashbhull@users.noreply.github.com> Date: Tue, 7 Feb 2023 12:43:25 +0000 Subject: [PATCH 14/19] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e1a7f92..808c28a 100644 --- a/README.md +++ b/README.md @@ -236,3 +236,5 @@ You can click on the boxes to see the output of the stages When it finishes the app will be on port 8080 on the app instances public IP You can make changes to the Jenkinsfile to change the pipeline + +New line for push From 4b3134dc857c909b223d4f24573757d6d90ac58e Mon Sep 17 00:00:00 2001 From: KashB <100960298+kashbhull@users.noreply.github.com> Date: Tue, 7 Feb 2023 12:44:01 +0000 Subject: [PATCH 15/19] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 808c28a..8384aed 100644 --- a/README.md +++ b/README.md @@ -237,4 +237,4 @@ When it finishes the app will be on port 8080 on the app instances public IP You can make changes to the Jenkinsfile to change the pipeline -New line for push +New line for webhook From 86bdd7d067ec8805f0e2c70347305d23069236c3 Mon Sep 17 00:00:00 2001 From: KashB <100960298+kashbhull@users.noreply.github.com> Date: Tue, 7 Feb 2023 12:47:28 +0000 Subject: [PATCH 16/19] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 34c8453..c3b214a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,7 @@ pipeline { environment { appIP="35.226.220.179"; containerName="java"; - imageName="javakb"; + imageName="javakb2"; } stages{ stage('Test Application'){ From d552aceac4d70c2f44e0963ab602830fdf906611 Mon Sep 17 00:00:00 2001 From: KashB <100960298+kashbhull@users.noreply.github.com> Date: Tue, 7 Feb 2023 12:48:26 +0000 Subject: [PATCH 17/19] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index c3b214a..abb55f1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,7 @@ pipeline { environment { appIP="35.226.220.179"; containerName="java"; - imageName="javakb2"; + imageName="javakb3"; } stages{ stage('Test Application'){ From 126ef449bcb2251d4abab08186861f01e55e2cc0 Mon Sep 17 00:00:00 2001 From: User Date: Tue, 7 Feb 2023 14:47:58 +0000 Subject: [PATCH 18/19] changed port number to 80 --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index abb55f1..71158b6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -47,7 +47,7 @@ pipeline { stage('Restart App'){ steps{ sh '''ssh -i "~/.ssh/id_rsa" jenkins@$appIP << EOF - docker run -d -p 8080:8080 --name $containerName ksbhull/$imageName + docker run -d -p 80:8080 --name $containerName ksbhull/$imageName ''' } } From 64ff2d43c73c6bfcf128a3bd3ced1471e6f32c29 Mon Sep 17 00:00:00 2001 From: User Date: Tue, 7 Feb 2023 14:54:28 +0000 Subject: [PATCH 19/19] changed port number to 8080 --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 71158b6..abb55f1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -47,7 +47,7 @@ pipeline { stage('Restart App'){ steps{ sh '''ssh -i "~/.ssh/id_rsa" jenkins@$appIP << EOF - docker run -d -p 80:8080 --name $containerName ksbhull/$imageName + docker run -d -p 8080:8080 --name $containerName ksbhull/$imageName ''' } }