From 7ac5ee412662fa47884a54632305f2a22db032ac Mon Sep 17 00:00:00 2001 From: pzi Date: Fri, 12 Jan 2024 20:05:29 +0100 Subject: [PATCH 01/18] Added a Jenkinsfile --- Jenkinsfile | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..daa8063f --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,30 @@ +pipeline { + agent any + + stages{ + stage("one"){ + steps{ + echo 'step 1' + sleep 3 + } + } + stage("two"){ + steps{ + echo 'step 2' + sleep 9 + } + } + stage("three"){ + steps{ + echo 'step 3' + sleep 5 + } + } + } + + post{ + always{ + echo 'This pipeline is completed.' + } + } +} From 7f0f3e2d3ec148f56cb8964b87eef94c164a555a Mon Sep 17 00:00:00 2001 From: pzi Date: Mon, 15 Jan 2024 16:28:15 +0100 Subject: [PATCH 02/18] add docker based agent --- worker/Jenkinsfile | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 worker/Jenkinsfile diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile new file mode 100644 index 00000000..3796cfe5 --- /dev/null +++ b/worker/Jenkinsfile @@ -0,0 +1,41 @@ +pipeline { +agent{ + docker{ + image 'maven:3.6.1-jdk-8-slim' + args '-v $HOME/.m2:/root/.m2' + } + } + stages{ + stage('build'){ + steps{ + echo 'building worker app' + dir('worker'){ + sh 'mvn compile' + } + } + } + stage('test'){ + steps{ + echo 'running unit tests on worker app' + dir('worker'){ + sh 'mvn clean test' + } + } + } + stage('package'){ + steps{ + echo 'packaging worker app into a jarfile' + dir('worker'){ + sh 'mvn package -DskipTests' + archiveArtifacts artifacts: '**/target/*.jar', + fingerprint: true + } + } + } + } +post{ + always{ + echo 'the job is complete' + } + } +} \ No newline at end of file From eb72054f6cb800b824add29213121e8cde780d79 Mon Sep 17 00:00:00 2001 From: pzi Date: Mon, 15 Jan 2024 16:58:50 +0100 Subject: [PATCH 03/18] add docker based agent --- worker/Jenkinsfile | 56 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 3796cfe5..f933af1a 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -1,41 +1,41 @@ pipeline { -agent{ + agent{ docker{ image 'maven:3.6.1-jdk-8-slim' args '-v $HOME/.m2:/root/.m2' } - } - stages{ - stage('build'){ + } + stages{ + stage('build'){ steps{ echo 'building worker app' dir('worker'){ sh 'mvn compile' } - } - } - stage('test'){ - steps{ - echo 'running unit tests on worker app' - dir('worker'){ - sh 'mvn clean test' - } } - } - stage('package'){ - steps{ - echo 'packaging worker app into a jarfile' - dir('worker'){ - sh 'mvn package -DskipTests' - archiveArtifacts artifacts: '**/target/*.jar', - fingerprint: true - } - } - } - } -post{ - always{ - echo 'the job is complete' + } + stage('test'){ + steps{ + echo 'running unit tests on worker app' + dir('worker'){ + sh 'mvn clean test' + } + } +} +stage('package'){ + steps{ + echo 'packaging worker app into a jarfile' + dir('worker'){ + sh 'mvn package -DskipTests' + archiveArtifacts artifacts: '**/target/*.jar', + fingerprint: true + } + } + } + } + post{ + always{ + echo 'the job is complete' + } } - } } \ No newline at end of file From dd982ccd72ef10c71e0ec83218b7f0df4eca85dc Mon Sep 17 00:00:00 2001 From: pzi Date: Mon, 15 Jan 2024 17:46:27 +0100 Subject: [PATCH 04/18] update 3 --- worker/{Jenkinsfile => Jenkinsfile.ok} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename worker/{Jenkinsfile => Jenkinsfile.ok} (100%) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile.ok similarity index 100% rename from worker/Jenkinsfile rename to worker/Jenkinsfile.ok From 36aae378ffb543e8c9a7dde920fec92b93658ae6 Mon Sep 17 00:00:00 2001 From: pzi Date: Mon, 15 Jan 2024 17:57:49 +0100 Subject: [PATCH 05/18] Update 4 --- worker/{Jenkinsfile.ok => Jenkinsfile} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename worker/{Jenkinsfile.ok => Jenkinsfile} (98%) diff --git a/worker/Jenkinsfile.ok b/worker/Jenkinsfile similarity index 98% rename from worker/Jenkinsfile.ok rename to worker/Jenkinsfile index f933af1a..12ecd911 100644 --- a/worker/Jenkinsfile.ok +++ b/worker/Jenkinsfile @@ -4,7 +4,7 @@ pipeline { image 'maven:3.6.1-jdk-8-slim' args '-v $HOME/.m2:/root/.m2' } - } + } stages{ stage('build'){ steps{ @@ -38,4 +38,4 @@ stage('package'){ echo 'the job is complete' } } -} \ No newline at end of file +} From 4f07583d46099e38d22ddb7ac0bf82d06d28b570 Mon Sep 17 00:00:00 2001 From: pzi Date: Tue, 16 Jan 2024 09:32:50 +0100 Subject: [PATCH 06/18] added = character --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8ad8a94..9174c50d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ Example Voting App -========= +========== Getting started --------------- From cb015be17700435f66f201277e068a675cd8a9ad Mon Sep 17 00:00:00 2001 From: Paride Zizzari <62766657+pzizzari@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:11:54 +0100 Subject: [PATCH 07/18] Update Jenkinsfile Signed-off-by: Paride Zizzari <62766657+pzizzari@users.noreply.github.com> --- Jenkinsfile | 63 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index daa8063f..8d5bf8ba 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,30 +1,49 @@ pipeline { - agent any - - stages{ - stage("one"){ - steps{ - echo 'step 1' - sleep 3 - } + agent any + tools{ + maven 'maven 3.6.1' + } + stages{ + stage("build"){ + when{ + changeset "**/worker/**" } - stage("two"){ - steps{ - echo 'step 2' - sleep 9 - } + steps{ + echo 'Compiling worker app..' + dir('worker'){ + sh 'mvn compile' + } } - stage("three"){ - steps{ - echo 'step 3' - sleep 5 + } + stage("test"){ + when{ + changeset "**/worker/**" + } + steps{ + echo 'Running Unit Tests on worker app..' + dir('worker'){ + sh 'mvn clean test' } } - } - + } + stage("package"){ + when{ + branch 'master' + changeset "**/worker/**" + } + steps{ + echo 'Packaging worker app' + dir('worker'){ + sh 'mvn package -DskipTests' + archiveArtifacts artifacts: '**/target/*.jar', + fingerprint:true + } + } + } + } post{ always{ - echo 'This pipeline is completed.' + echo 'Building multibranch pipeline for worker is completed..' + } } - } -} + } From d43e56ec62a7bc7cd0bdda656bccb156a3d0304c Mon Sep 17 00:00:00 2001 From: Paride Zizzari <62766657+pzizzari@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:12:58 +0100 Subject: [PATCH 08/18] Update Jenkinsfile Signed-off-by: Paride Zizzari <62766657+pzizzari@users.noreply.github.com> --- Jenkinsfile | 63 +++++++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 41 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8d5bf8ba..daa8063f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,49 +1,30 @@ pipeline { - agent any - tools{ - maven 'maven 3.6.1' - } - stages{ - stage("build"){ - when{ - changeset "**/worker/**" + agent any + + stages{ + stage("one"){ + steps{ + echo 'step 1' + sleep 3 + } } - steps{ - echo 'Compiling worker app..' - dir('worker'){ - sh 'mvn compile' - } + stage("two"){ + steps{ + echo 'step 2' + sleep 9 + } } - } - stage("test"){ - when{ - changeset "**/worker/**" - } - steps{ - echo 'Running Unit Tests on worker app..' - dir('worker'){ - sh 'mvn clean test' + stage("three"){ + steps{ + echo 'step 3' + sleep 5 } } - } - stage("package"){ - when{ - branch 'master' - changeset "**/worker/**" - } - steps{ - echo 'Packaging worker app' - dir('worker'){ - sh 'mvn package -DskipTests' - archiveArtifacts artifacts: '**/target/*.jar', - fingerprint:true - } - } - } - } + } + post{ always{ - echo 'Building multibranch pipeline for worker is completed..' - } + echo 'This pipeline is completed.' } - } + } +} From 7e51a3d9f5857c89dffed9269b9a675bcae01a83 Mon Sep 17 00:00:00 2001 From: pzi Date: Wed, 17 Jan 2024 10:28:59 +0100 Subject: [PATCH 09/18] adding Dockerfile for worker --- worker/Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 worker/Dockerfile diff --git a/worker/Dockerfile b/worker/Dockerfile new file mode 100644 index 00000000..78e16f8f --- /dev/null +++ b/worker/Dockerfile @@ -0,0 +1,6 @@ +FROM maven:3.6.1-jdk-8-slim +WORKDIR /app +COPY . . +RUN mvn package && \ + mv target/worker-jar-with-dependencies.jar /run/worker.jar && rm -rf /app/* +CMD java -jar /run/worker.jar \ No newline at end of file From 449cda80dae26c41d7b8b641c23d576b8c10180b Mon Sep 17 00:00:00 2001 From: pzi Date: Wed, 17 Jan 2024 11:16:02 +0100 Subject: [PATCH 10/18] Jenkinsfile with added docker-package stage --- worker/Jenkinsfile | 47 ++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 12ecd911..6207c4cd 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -11,9 +11,9 @@ pipeline { echo 'building worker app' dir('worker'){ sh 'mvn compile' - } - } - } + } + } + } stage('test'){ steps{ echo 'running unit tests on worker app' @@ -21,21 +21,36 @@ pipeline { sh 'mvn clean test' } } -} -stage('package'){ - steps{ - echo 'packaging worker app into a jarfile' - dir('worker'){ - sh 'mvn package -DskipTests' - archiveArtifacts artifacts: '**/target/*.jar', - fingerprint: true - } + } + stage('package'){ + steps{ + echo 'packaging worker app into a jarfile' + dir('worker'){ + sh 'mvn package -DskipTests' + archiveArtifacts artifacts: '**/target/*.jar', + fingerprint: true + } + } + } } + + stage('docker-package'){ + agent any + steps{ + echo 'Packaging worker app with docker' + script{ + docker.withRegistry('https://index.docker.io/v1/','dockerlogin') + {def workerImage = + docker.build("zkube/worker:v${env.BUILD_ID}", "./ worker") + workerImage.push() + workerImage.push("latest") + } + } + } } + post{ + always{ + echo 'the job is complete' } - post{ - always{ - echo 'the job is complete' - } } } From e6a0af585ad48f17b5dab72264c7894b82087e08 Mon Sep 17 00:00:00 2001 From: pzi Date: Wed, 17 Jan 2024 11:28:04 +0100 Subject: [PATCH 11/18] Jenkinsfile with added docker-package stage --- worker/Jenkinsfile | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 6207c4cd..624e0b45 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -32,21 +32,20 @@ pipeline { } } } - } - - stage('docker-package'){ - agent any - steps{ - echo 'Packaging worker app with docker' - script{ - docker.withRegistry('https://index.docker.io/v1/','dockerlogin') - {def workerImage = - docker.build("zkube/worker:v${env.BUILD_ID}", "./ worker") - workerImage.push() - workerImage.push("latest") + stage('docker-package'){ + agent any + steps{ + echo 'Packaging worker app with docker' + script{ + docker.withRegistry('https://index.docker.io/v1/','dockerlogin') + {def workerImage = + docker.build("zkube/worker:v${env.BUILD_ID}", "./ worker") + workerImage.push() + workerImage.push("latest") + } } - } - } + } + } } post{ always{ From 0eaf2079f7e107b79a341905d0045ff8666a8e8d Mon Sep 17 00:00:00 2001 From: pzi Date: Wed, 17 Jan 2024 11:39:32 +0100 Subject: [PATCH 12/18] per stage agents, conditional execution --- worker/Jenkinsfile | 114 +++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 40 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 624e0b45..4bf9684b 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -1,55 +1,89 @@ pipeline { - agent{ - docker{ - image 'maven:3.6.1-jdk-8-slim' - args '-v $HOME/.m2:/root/.m2' + + agent none + + stages{ + stage("build"){ + when{ + changeset "**/worker/**" + } + + agent{ + docker{ + image 'maven:3.6.1-jdk-8-slim' + args '-v $HOME/.m2:/root/.m2' + } + } + + steps{ + echo 'Compiling worker app..' + dir('worker'){ + sh 'mvn compile' + } + } } - } - stages{ - stage('build'){ - steps{ - echo 'building worker app' - dir('worker'){ - sh 'mvn compile' - } + stage("test"){ + when{ + changeset "**/worker/**" + } + agent{ + docker{ + image 'maven:3.6.1-jdk-8-slim' + args '-v $HOME/.m2:/root/.m2' } } - stage('test'){ steps{ - echo 'running unit tests on worker app' + echo 'Running Unit Tets on worker app..' dir('worker'){ - sh 'mvn clean test' - } - } - } - stage('package'){ + sh 'mvn clean test' + } + + } + } + stage("package"){ + when{ + branch 'master' + changeset "**/worker/**" + } + agent{ + docker{ + image 'maven:3.6.1-jdk-8-slim' + args '-v $HOME/.m2:/root/.m2' + } + } + steps{ + echo 'Packaging worker app' + dir('worker'){ + sh 'mvn package -DskipTests' + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true + } + + } + } + + stage('docker-package'){ + agent any + when{ + changeset "**/worker/**" + branch 'master' + } steps{ - echo 'packaging worker app into a jarfile' - dir('worker'){ - sh 'mvn package -DskipTests' - archiveArtifacts artifacts: '**/target/*.jar', - fingerprint: true + echo 'Packaging worker app with docker' + script{ + docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { + def workerImage = docker.build("xxxxx/worker:v${env.BUILD_ID}", "./worker") + workerImage.push() + workerImage.push("${env.BRANCH_NAME}") + workerImage.push("latest") } } } - stage('docker-package'){ - agent any - steps{ - echo 'Packaging worker app with docker' - script{ - docker.withRegistry('https://index.docker.io/v1/','dockerlogin') - {def workerImage = - docker.build("zkube/worker:v${env.BUILD_ID}", "./ worker") - workerImage.push() - workerImage.push("latest") - } - } - } - } } + } + post{ always{ - echo 'the job is complete' - } + echo 'Building multibranch pipeline for worker is completed..' } + } } From 682895f0ff5206de7c88ebc57393857a2315a387 Mon Sep 17 00:00:00 2001 From: pzi Date: Wed, 17 Jan 2024 11:44:43 +0100 Subject: [PATCH 13/18] per stage agents, conditional execution --- worker/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 4bf9684b..6988a12c 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -71,7 +71,7 @@ pipeline { echo 'Packaging worker app with docker' script{ docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { - def workerImage = docker.build("xxxxx/worker:v${env.BUILD_ID}", "./worker") + def workerImage = docker.build("zkube/worker:v${env.BUILD_ID}", "./worker") workerImage.push() workerImage.push("${env.BRANCH_NAME}") workerImage.push("latest") From 369e3784bfe3a1627b5abfc903c9e9b47e2eac98 Mon Sep 17 00:00:00 2001 From: pzi Date: Wed, 17 Jan 2024 11:49:11 +0100 Subject: [PATCH 14/18] per stage agents, conditional execution --- worker/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 6988a12c..7dc8cf99 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -65,7 +65,7 @@ pipeline { agent any when{ changeset "**/worker/**" - branch 'master' + branch 'feature/dockerfiles' } steps{ echo 'Packaging worker app with docker' From e31d9c34dca86ae8e6b8108fac6d0a6c2213c4dd Mon Sep 17 00:00:00 2001 From: pzi Date: Wed, 17 Jan 2024 13:01:50 +0100 Subject: [PATCH 15/18] one more push --- worker/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worker/Dockerfile b/worker/Dockerfile index 78e16f8f..e6e81eed 100644 --- a/worker/Dockerfile +++ b/worker/Dockerfile @@ -2,5 +2,5 @@ FROM maven:3.6.1-jdk-8-slim WORKDIR /app COPY . . RUN mvn package && \ - mv target/worker-jar-with-dependencies.jar /run/worker.jar && rm -rf /app/* -CMD java -jar /run/worker.jar \ No newline at end of file + mv target/worker-jar-with-dependencies.jar /run/worker.jar && rm -rf /app/* +CMD java -jar /run/worker.jar From 18f536f82bb50c40d7334582a17cc93b9e89b434 Mon Sep 17 00:00:00 2001 From: pzi Date: Wed, 17 Jan 2024 13:05:17 +0100 Subject: [PATCH 16/18] one more push --- worker/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 7dc8cf99..e41040ee 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -42,7 +42,7 @@ pipeline { } stage("package"){ when{ - branch 'master' + branch 'feature/dockerfiles' changeset "**/worker/**" } agent{ From 7a45f750331cd281b0c34d822fb00d370113cda7 Mon Sep 17 00:00:00 2001 From: pzi Date: Wed, 17 Jan 2024 13:38:21 +0100 Subject: [PATCH 17/18] one more --- docker-compose.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 docker-compose.yaml diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..f2ca8347 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,13 @@ +services: + vote: + image: zkube/vote:latest + ports: + - 5000:80 + + result: + image: zkube/result:latest + ports: + - 5001:4000 + + worker: + image: zkube/worker:latest From b3acad6f9c30b9d0e4bb5e4a5e8c550642295aa3 Mon Sep 17 00:00:00 2001 From: Paride Zizzari <62766657+pzizzari@users.noreply.github.com> Date: Wed, 17 Jan 2024 13:59:27 +0100 Subject: [PATCH 18/18] Update Jenkinsfile Signed-off-by: Paride Zizzari <62766657+pzizzari@users.noreply.github.com> --- worker/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index e41040ee..6988a12c 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -42,7 +42,7 @@ pipeline { } stage("package"){ when{ - branch 'feature/dockerfiles' + branch 'master' changeset "**/worker/**" } agent{ @@ -65,7 +65,7 @@ pipeline { agent any when{ changeset "**/worker/**" - branch 'feature/dockerfiles' + branch 'master' } steps{ echo 'Packaging worker app with docker'