From 08521dfe58af8de4271c1fe56c88df54312b7348 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 12:56:14 +0530 Subject: [PATCH 01/57] added Jenkinsfile for worker app to build with maven --- worker/Jenkinsfile | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 worker/Jenkinsfile diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile new file mode 100644 index 0000000000..0592cccd8b --- /dev/null +++ b/worker/Jenkinsfile @@ -0,0 +1,31 @@ +pipeline { + agent any + + tools { + maven 'Maven 3.6.1' + } + + stages { + when {changeset "**/worker/*.*" } + stage('Build') { + steps { + echo 'Building..' + sh 'mvn compile' + } + } + + stage('Test') { + steps { + echo 'Testing..' + sh 'mvn test' + } + } + stage('Package') { + steps { + echo 'Packaging....' + sh 'mvn package -DskipTests' + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true + } + } + } +} From 0fe0d08a58926297a2ec21ff04c424a04f355f66 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 13:04:07 +0530 Subject: [PATCH 02/57] add when condition for every stage --- worker/Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 0592cccd8b..3843b983ad 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -6,8 +6,8 @@ pipeline { } stages { - when {changeset "**/worker/*.*" } stage('Build') { + when {changeset "**/worker/*.*" } steps { echo 'Building..' sh 'mvn compile' @@ -15,12 +15,14 @@ pipeline { } stage('Test') { + when {changeset "**/worker/*.*" } steps { echo 'Testing..' sh 'mvn test' } } stage('Package') { + when {changeset "**/worker/*.*" } steps { echo 'Packaging....' sh 'mvn package -DskipTests' From 3108756d68d7fba9fac0df7a52c1e63775fc5032 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 13:05:57 +0530 Subject: [PATCH 03/57] updated changeset criteria from *.* to ** --- worker/Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 3843b983ad..12f991569f 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -7,7 +7,7 @@ pipeline { stages { stage('Build') { - when {changeset "**/worker/*.*" } + when {changeset "**/worker/**" } steps { echo 'Building..' sh 'mvn compile' @@ -15,14 +15,14 @@ pipeline { } stage('Test') { - when {changeset "**/worker/*.*" } + when {changeset "**/worker/**" } steps { echo 'Testing..' sh 'mvn test' } } stage('Package') { - when {changeset "**/worker/*.*" } + when {changeset "**/worker/**" } steps { echo 'Packaging....' sh 'mvn package -DskipTests' From de8fa7bad90b8a54f5ee1350951f2540d8f7e9e0 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 13:10:18 +0530 Subject: [PATCH 04/57] provide path to pom.xml --- worker/Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 12f991569f..47df3d195e 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -10,7 +10,7 @@ pipeline { when {changeset "**/worker/**" } steps { echo 'Building..' - sh 'mvn compile' + sh 'mvn -f worker/pom.xml compile' } } @@ -18,14 +18,14 @@ pipeline { when {changeset "**/worker/**" } steps { echo 'Testing..' - sh 'mvn test' + sh 'mvn -f worker/pom.xml test' } } stage('Package') { when {changeset "**/worker/**" } steps { echo 'Packaging....' - sh 'mvn package -DskipTests' + sh 'mvn -f worker/pom.xml package -DskipTests' archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true } } From 449ad9d0630047e10def06e518eacc23239ec67d Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 13:24:28 +0530 Subject: [PATCH 05/57] added jenkinsfile with docker agent --- worker/Jenkinsfile.docker | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 worker/Jenkinsfile.docker diff --git a/worker/Jenkinsfile.docker b/worker/Jenkinsfile.docker new file mode 100644 index 0000000000..0590580172 --- /dev/null +++ b/worker/Jenkinsfile.docker @@ -0,0 +1,36 @@ +pipeline { + + agent { + docker { + image 'maven:3-alpine' + args '-v $HOME/.m2:/root/.m2' + } + } + + + stages { + stage('Build') { + when {changeset "**/worker/*" } + steps { + echo 'Building..' + sh 'mvn -f worker/pom.xml compile' + } + } + + stage('Test') { + when {changeset "**/worker/*" } + steps { + echo 'Testing..' + sh 'mvn -f worker/pom.xml test' + } + } + stage('Package') { + when {changeset "**/worker/*" } + steps { + echo 'Packaging....' + sh 'mvn -f worker/pom.xml package -DskipTests' + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true + } + } + } +} From d683aba94d3130e1b8e14adc6a0bebe6cc98dc6d Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 13:25:45 +0530 Subject: [PATCH 06/57] remove changeset when condition --- worker/Jenkinsfile | 3 --- worker/Jenkinsfile.docker | 3 --- 2 files changed, 6 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 47df3d195e..031100f914 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -7,7 +7,6 @@ pipeline { stages { stage('Build') { - when {changeset "**/worker/**" } steps { echo 'Building..' sh 'mvn -f worker/pom.xml compile' @@ -15,14 +14,12 @@ pipeline { } stage('Test') { - when {changeset "**/worker/**" } steps { echo 'Testing..' sh 'mvn -f worker/pom.xml test' } } stage('Package') { - when {changeset "**/worker/**" } steps { echo 'Packaging....' sh 'mvn -f worker/pom.xml package -DskipTests' diff --git a/worker/Jenkinsfile.docker b/worker/Jenkinsfile.docker index 0590580172..cf65f44285 100644 --- a/worker/Jenkinsfile.docker +++ b/worker/Jenkinsfile.docker @@ -10,7 +10,6 @@ pipeline { stages { stage('Build') { - when {changeset "**/worker/*" } steps { echo 'Building..' sh 'mvn -f worker/pom.xml compile' @@ -18,14 +17,12 @@ pipeline { } stage('Test') { - when {changeset "**/worker/*" } steps { echo 'Testing..' sh 'mvn -f worker/pom.xml test' } } stage('Package') { - when {changeset "**/worker/*" } steps { echo 'Packaging....' sh 'mvn -f worker/pom.xml package -DskipTests' From a135216b0308b79be3480ff5902c92a70c0be069 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 13:45:19 +0530 Subject: [PATCH 07/57] - added Jenkinsfile for vote frontend app - add python-nose as a pre req to setup unit tests --- vote/Jenkinsfile | 29 +++++++++++++++++++++++++++++ vote/requirements.txt | 1 + 2 files changed, 30 insertions(+) create mode 100644 vote/Jenkinsfile diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile new file mode 100644 index 0000000000..f180471baf --- /dev/null +++ b/vote/Jenkinsfile @@ -0,0 +1,29 @@ +pipeline { + + agent { + docker { + image 'python:3.7.3-alpine3.9' + } + } + + + stages { + stage('Build') { + steps { + echo 'Building..' + dir("vote") { + sh 'pip install -r requirements.txt' + } + } + } + + stage('Test') { + steps { + echo 'Testing..' + dir("vote") { + sh 'nosetests -v' + } + } + } + } +} diff --git a/vote/requirements.txt b/vote/requirements.txt index 430bfdcd89..d3cbfb8f41 100644 --- a/vote/requirements.txt +++ b/vote/requirements.txt @@ -1,3 +1,4 @@ Flask Redis gunicorn +nose From f6cf7a85ecd468f26cca47479cc7ad78d9e19ddd Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 14:01:01 +0530 Subject: [PATCH 08/57] testing pwd with worker --- worker/Jenkinsfile.docker | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/worker/Jenkinsfile.docker b/worker/Jenkinsfile.docker index cf65f44285..9fb3fafd26 100644 --- a/worker/Jenkinsfile.docker +++ b/worker/Jenkinsfile.docker @@ -12,7 +12,9 @@ pipeline { stage('Build') { steps { echo 'Building..' - sh 'mvn -f worker/pom.xml compile' + dir('worker'){ + sh 'mvn compile' + } } } From 10899cd437f450204c77c3338efaf762e1c6a343 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 14:03:14 +0530 Subject: [PATCH 09/57] testing pwd with worker --- worker/Jenkinsfile.docker | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/worker/Jenkinsfile.docker b/worker/Jenkinsfile.docker index 9fb3fafd26..c4f1d2cbb6 100644 --- a/worker/Jenkinsfile.docker +++ b/worker/Jenkinsfile.docker @@ -21,14 +21,18 @@ pipeline { stage('Test') { steps { echo 'Testing..' - sh 'mvn -f worker/pom.xml test' + dir('worker'){ + sh 'mvn test' + } } } stage('Package') { steps { echo 'Packaging....' - sh 'mvn -f worker/pom.xml package -DskipTests' - archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true + dir('worker'){ + sh 'mvn -f worker/pom.xml package -DskipTests' + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true + } } } } From 375f2b6a8bd82e7d5de2f06522c238389d43687d Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 14:08:26 +0530 Subject: [PATCH 10/57] updated Jenkinsfile for vote --- vote/Jenkinsfile | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index f180471baf..39fd12d42f 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -2,7 +2,7 @@ pipeline { agent { docker { - image 'python:3.7.3-alpine3.9' + image 'python:2.7-alpine' } } @@ -11,8 +11,8 @@ pipeline { stage('Build') { steps { echo 'Building..' - dir("vote") { - sh 'pip install -r requirements.txt' + dir('vote'){ + sh 'pip install -r requirements.txt' } } } @@ -20,10 +20,18 @@ pipeline { stage('Test') { steps { echo 'Testing..' - dir("vote") { - sh 'nosetests -v' + dir('vote'){ + sh 'nosetests -v' } } } + stage('Package') { + steps { + echo 'Packaging....' + dir('vote'){ + sh 'python' + } + } + } } } From 93c022e580ae6c1ea22d35b81aad489ae4965286 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 14:24:54 +0530 Subject: [PATCH 11/57] run python container as root --- vote/Jenkinsfile | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 39fd12d42f..4a0a24f683 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -3,6 +3,7 @@ pipeline { agent { docker { image 'python:2.7-alpine' + args '--user root' } } @@ -25,13 +26,5 @@ pipeline { } } } - stage('Package') { - steps { - echo 'Packaging....' - dir('vote'){ - sh 'python' - } - } - } } } From 32a7e40b652fb58d9405b8e8767e0efde3ccd7a1 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 14:30:44 +0530 Subject: [PATCH 12/57] fix pom.xml path after adding dir step --- worker/Jenkinsfile.docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/Jenkinsfile.docker b/worker/Jenkinsfile.docker index c4f1d2cbb6..95713e7c69 100644 --- a/worker/Jenkinsfile.docker +++ b/worker/Jenkinsfile.docker @@ -30,7 +30,7 @@ pipeline { steps { echo 'Packaging....' dir('worker'){ - sh 'mvn -f worker/pom.xml package -DskipTests' + sh 'mvn package -DskipTests' archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true } } From 933e2958d9d605c92ebc0d0bbd7ee4443c295c25 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 14:50:50 +0530 Subject: [PATCH 13/57] adding docker build stage for vote app --- vote/Jenkinsfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 4a0a24f683..7ea625f9ab 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -26,5 +26,15 @@ pipeline { } } } + + stage('Package with Docker') { + steps { + echo 'Building and Publishing Docker Image' + + script { + def customImage = docker.build("initcron/votetest:${env.BUILD_ID}", "./vote") + } + } + } } } From 914860fc51819b8562a0ea858bbbd21cf3591d24 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 14:56:09 +0530 Subject: [PATCH 14/57] use stage specific agents, any for docker build --- vote/Jenkinsfile | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 7ea625f9ab..3903d1a91e 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -1,25 +1,30 @@ pipeline { - agent { - docker { - image 'python:2.7-alpine' - args '--user root' - } - } - + agent none stages { stage('Build') { + agent { + docker { + image 'python:2.7-alpine' + args '--user root' + } + } steps { echo 'Building..' dir('vote'){ sh 'pip install -r requirements.txt' } } - } + } stage('Test') { - steps { + agent { + docker { + image 'python:2.7-alpine' + args '--user root' + } + steps { echo 'Testing..' dir('vote'){ sh 'nosetests -v' @@ -28,6 +33,7 @@ pipeline { } stage('Package with Docker') { + agent any steps { echo 'Building and Publishing Docker Image' From f204766698f3dda503767d0fdcd6cb5638dbe248 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 14:57:59 +0530 Subject: [PATCH 15/57] fixed syntax --- vote/Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 3903d1a91e..fb04324ec6 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -23,6 +23,7 @@ pipeline { docker { image 'python:2.7-alpine' args '--user root' + } } steps { echo 'Testing..' From db2e63b1112a473290164f4bbbd6c474169f56b7 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 15:04:58 +0530 Subject: [PATCH 16/57] install python packages again while testing --- vote/Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index fb04324ec6..61baaad734 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -28,6 +28,7 @@ pipeline { steps { echo 'Testing..' dir('vote'){ + sh 'pip install -r requirements.txt' sh 'nosetests -v' } } From 6248c18bfaed73821ed0b4f2bd14a85c0c999223 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 15:09:51 +0530 Subject: [PATCH 17/57] poll scm trigger runs every 2 mins --- vote/Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 61baaad734..ace00caaaa 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -2,6 +2,8 @@ pipeline { agent none + triggers { pollSCM('H/2 * * * *') } + stages { stage('Build') { agent { From f17c22bab9a60eb931d984a8564bb20bcc757bec Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 15:13:30 +0530 Subject: [PATCH 18/57] push image --- vote/Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index ace00caaaa..584b4a2633 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -42,7 +42,9 @@ pipeline { echo 'Building and Publishing Docker Image' script { - def customImage = docker.build("initcron/votetest:${env.BUILD_ID}", "./vote") + def myImage = docker.build("initcron/votetest:${env.BUILD_ID}", "./vote") + myImage.push() + myImage.push(dev) } } } From 7f43f6375cf05354dc9ce3ee40b777240c6ac488 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 15:54:20 +0530 Subject: [PATCH 19/57] add docker build and publish step --- vote/Jenkinsfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 584b4a2633..bd990206c0 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -40,11 +40,9 @@ pipeline { agent any steps { echo 'Building and Publishing Docker Image' - - script { - def myImage = docker.build("initcron/votetest:${env.BUILD_ID}", "./vote") - myImage.push() - myImage.push(dev) + withDockerRegistry([ credentialsId: "dockerhub", "url": "https://index.docker.io/v1/" ]) { + sh "docker build -f vote/Dockerfile -t initcron/votetest:${env.BUILD_ID} vote/" + sh "docker push initcron/votetest:${env.BUILD_ID}" } } } From ad6f76e94ad4606c257b414c0c005b1bb592f213 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 16:11:04 +0530 Subject: [PATCH 20/57] scripted format of docker image build and publish --- vote/Jenkinsfile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index bd990206c0..48b7f12c52 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -40,9 +40,11 @@ pipeline { agent any steps { echo 'Building and Publishing Docker Image' - withDockerRegistry([ credentialsId: "dockerhub", "url": "https://index.docker.io/v1/" ]) { - sh "docker build -f vote/Dockerfile -t initcron/votetest:${env.BUILD_ID} vote/" - sh "docker push initcron/votetest:${env.BUILD_ID}" + script { + docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') { + def customImage = docker.build("initcron/votetest:${env.BUILD_ID}", "./vote") + customImage.push() + } } } } From 2809bca981d49139e21c22bf9f8e6dd7787c3ad5 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 16:16:52 +0530 Subject: [PATCH 21/57] build and push image with branch name --- vote/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 48b7f12c52..700ea42e51 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -42,7 +42,7 @@ pipeline { echo 'Building and Publishing Docker Image' script { docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') { - def customImage = docker.build("initcron/votetest:${env.BUILD_ID}", "./vote") + def customImage = docker.build("initcron/votetest:${env.BRANCH_NAME}-${env.BUILD_ID}", "./vote") customImage.push() } } From 18c543d8f2daa5d9b7672ea610739f47cbe10dd3 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 20:20:36 +0530 Subject: [PATCH 22/57] - added Dockerfile for worker - refactored Jenkinsfile.docker for worker with docker image build and publish steps - agent is now stage based --- worker/Dockerfile | 11 +++++++++++ worker/Jenkinsfile.docker | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 worker/Dockerfile diff --git a/worker/Dockerfile b/worker/Dockerfile new file mode 100644 index 0000000000..9ab8d5d971 --- /dev/null +++ b/worker/Dockerfile @@ -0,0 +1,11 @@ +FROM schoolofdevops/maven + +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 diff --git a/worker/Jenkinsfile.docker b/worker/Jenkinsfile.docker index 95713e7c69..7e1baef5bc 100644 --- a/worker/Jenkinsfile.docker +++ b/worker/Jenkinsfile.docker @@ -1,15 +1,16 @@ pipeline { - agent { - docker { - image 'maven:3-alpine' - args '-v $HOME/.m2:/root/.m2' - } - } + agent any stages { stage('Build') { + agent { + docker { + image 'maven:3-alpine' + args '-v $HOME/.m2:/root/.m2' + } + } steps { echo 'Building..' dir('worker'){ @@ -19,6 +20,12 @@ pipeline { } stage('Test') { + agent { + docker { + image 'maven:3-alpine' + args '-v $HOME/.m2:/root/.m2' + } + } steps { echo 'Testing..' dir('worker'){ @@ -27,6 +34,12 @@ pipeline { } } stage('Package') { + agent { + docker { + image 'maven:3-alpine' + args '-v $HOME/.m2:/root/.m2' + } + } steps { echo 'Packaging....' dir('worker'){ @@ -35,5 +48,17 @@ pipeline { } } } + stage('Package with Docker') { + agent any + steps { + echo 'Building and Publishing Docker Image' + script { + docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') { + def customImage = docker.build("initcron/worker:${env.BRANCH_NAME}-${env.BUILD_ID}", "./worker") + customImage.push() + } + } + } + } } } From 056194aa4518819fa7912c234509028ae40c641c Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 20:23:02 +0530 Subject: [PATCH 23/57] poll every 2mins --- worker/Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 031100f914..4a263f5b73 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -1,5 +1,7 @@ pipeline { agent any + + triggers { pollSCM('H/2 * * * *') } tools { maven 'Maven 3.6.1' From afdde0394332675d1cdb7c66f40eed6b06162788 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 20:49:11 +0530 Subject: [PATCH 24/57] added unit tests for results nodejs app --- result/package.json | 8 ++++++-- result/test/mock.test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 result/test/mock.test.js diff --git a/result/package.json b/result/package.json index f7863e1a1d..f0ac5fb3a6 100644 --- a/result/package.json +++ b/result/package.json @@ -1,10 +1,10 @@ { "name": "result", - "version": "1.0.0", + "version": "1.1.0", "description": "", "main": "server.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "node_modules/.bin/mocha" }, "author": "", "license": "MIT", @@ -16,5 +16,9 @@ "async": "^1.5.0", "pg": "^4.4.3", "socket.io": "^1.3.7" + }, + "devDependencies": { + "chai": "^4.0.2", + "mocha": "^3.4.2" } } diff --git a/result/test/mock.test.js b/result/test/mock.test.js new file mode 100644 index 0000000000..f99dfdae97 --- /dev/null +++ b/result/test/mock.test.js @@ -0,0 +1,29 @@ +const expect = require('chai').expect; + +describe('mock test 1', () => { + it('unit test 1', () => { + expect(true).to.be.true; + }); +}); + + +describe('mock test 2', () => { + it('unit test 2', () => { + expect(true).to.be.true; + }); +}); + +describe('mock test 3', () => { + it('unit test 3', () => { + expect(true).to.be.true; + }); +}); + + +describe('mock test 4', () => { + it('unit test 4', () => { + expect(true).to.be.true; + }); +}); + + From 12984050e1ce823c7936d2c8a16eaf1a08e37890 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 21:03:35 +0530 Subject: [PATCH 25/57] added Jenkinsfile for results app --- result/Jenkinsfile | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 result/Jenkinsfile diff --git a/result/Jenkinsfile b/result/Jenkinsfile new file mode 100644 index 0000000000..5f30963444 --- /dev/null +++ b/result/Jenkinsfile @@ -0,0 +1,50 @@ +pipeline { + + agent none + + triggers { pollSCM('H/2 * * * *') } + + stages { + stage('Build') { + agent { + docker { + image 'node:8.9-alpine' + } + } + steps { + echo 'Building..' + dir('result'){ + sh 'npm install' + } + } + } + + stage('Test') { + agent { + docker { + image 'node:8.9-alpine' + } + } + steps { + echo 'Testing..' + dir('result'){ + sh 'npm install' + sh 'npm test' + } + } + } + + stage('Package with Docker') { + agent any + steps { + echo 'Building and Publishing Docker Image' + script { + docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') { + def customImage = docker.build("initcron/result:${env.BRANCH_NAME}-${env.BUILD_ID}", "./result") + customImage.push() + } + } + } + } + } +} From 447381668115630fe24246d21d29f1fc1dfdcdfc Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 21:25:52 +0530 Subject: [PATCH 26/57] adding sonarqube analysis stage --- result/Jenkinsfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/result/Jenkinsfile b/result/Jenkinsfile index 5f30963444..15df802079 100644 --- a/result/Jenkinsfile +++ b/result/Jenkinsfile @@ -34,6 +34,16 @@ pipeline { } } + stage('Sonarqube') { + agent any + steps { + echo 'Running Sonarqube Analysis..' + dir('result'){ + sh '/opt/sonar-scanner/bin/sonar-scanner -Dproject.settings=sonar-project.properties' + } + } + } + stage('Package with Docker') { agent any steps { From 13b6a99ca936b53c873ea186fc72685b602c4ced Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 21:37:57 +0530 Subject: [PATCH 27/57] sonar fix --- result/Jenkinsfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/result/Jenkinsfile b/result/Jenkinsfile index 15df802079..2b4df00d90 100644 --- a/result/Jenkinsfile +++ b/result/Jenkinsfile @@ -36,10 +36,13 @@ pipeline { stage('Sonarqube') { agent any + environment{ + sonarpath = tool 'SonarScanner' + } steps { echo 'Running Sonarqube Analysis..' dir('result'){ - sh '/opt/sonar-scanner/bin/sonar-scanner -Dproject.settings=sonar-project.properties' + sh "${sonarpath}/bin/sonar-scanner -Dproject.settings=sonar-project.properties" } } } From eb4fde639b8d90a19c2bac20018dec28a38d8de4 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 21:41:39 +0530 Subject: [PATCH 28/57] sonar fix --- result/Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/result/Jenkinsfile b/result/Jenkinsfile index 2b4df00d90..674d7dfef7 100644 --- a/result/Jenkinsfile +++ b/result/Jenkinsfile @@ -42,7 +42,9 @@ pipeline { steps { echo 'Running Sonarqube Analysis..' dir('result'){ - sh "${sonarpath}/bin/sonar-scanner -Dproject.settings=sonar-project.properties" + withSonarQubeEnv('sonar') { + sh "${sonarpath}/bin/sonar-scanner -Dproject.settings=sonar-project.properties" + } } } } From 8fd30103c9694a8c61f1258bdb44795aa496a378 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 21:51:10 +0530 Subject: [PATCH 29/57] sonar fix --- result/Jenkinsfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/result/Jenkinsfile b/result/Jenkinsfile index 674d7dfef7..6870cedb28 100644 --- a/result/Jenkinsfile +++ b/result/Jenkinsfile @@ -41,11 +41,9 @@ pipeline { } steps { echo 'Running Sonarqube Analysis..' - dir('result'){ withSonarQubeEnv('sonar') { - sh "${sonarpath}/bin/sonar-scanner -Dproject.settings=sonar-project.properties" + sh "${sonarpath}/bin/sonar-scanner -Dproject.settings=result/sonar-project.properties" } - } } } From 72035a2baf3ec78fc028ba609d189e3e1c559e9c Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 22:09:09 +0530 Subject: [PATCH 30/57] renamed comnpose file --- e2e/{docker-compose.test.yml => docker-compose.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename e2e/{docker-compose.test.yml => docker-compose.yml} (100%) diff --git a/e2e/docker-compose.test.yml b/e2e/docker-compose.yml similarity index 100% rename from e2e/docker-compose.test.yml rename to e2e/docker-compose.yml From 985ff00380bd8ae0fb242126c04fc783c6c2d9c5 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Wed, 5 Jun 2019 23:02:37 +0530 Subject: [PATCH 31/57] renamed sut to e2e, fixed results dockerfile path --- e2e/docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/docker-compose.yml b/e2e/docker-compose.yml index 0df964e646..014f9d0a42 100644 --- a/e2e/docker-compose.yml +++ b/e2e/docker-compose.yml @@ -2,7 +2,7 @@ version: '2' services: - sut: + e2e: build: ./tests/ depends_on: - vote @@ -22,7 +22,7 @@ services: - back-tier result: - build: . + build: ../result/ ports: ["80"] depends_on: - redis From 27b40c92b2fbd8efb15450ce5640cf636abdc41a Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 6 Jun 2019 09:30:37 +0530 Subject: [PATCH 32/57] docker push images with branch name as tag --- result/Jenkinsfile | 1 + vote/Jenkinsfile | 1 + worker/Jenkinsfile.docker | 1 + 3 files changed, 3 insertions(+) diff --git a/result/Jenkinsfile b/result/Jenkinsfile index 6870cedb28..dc43bbe342 100644 --- a/result/Jenkinsfile +++ b/result/Jenkinsfile @@ -54,6 +54,7 @@ pipeline { script { docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') { def customImage = docker.build("initcron/result:${env.BRANCH_NAME}-${env.BUILD_ID}", "./result") + customImage.push("${env.BRANCH_NAME}") customImage.push() } } diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 700ea42e51..936fd80258 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -43,6 +43,7 @@ pipeline { script { docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') { def customImage = docker.build("initcron/votetest:${env.BRANCH_NAME}-${env.BUILD_ID}", "./vote") + customImage.push("${env.BRANCH_NAME}") customImage.push() } } diff --git a/worker/Jenkinsfile.docker b/worker/Jenkinsfile.docker index 7e1baef5bc..1feb2bfe20 100644 --- a/worker/Jenkinsfile.docker +++ b/worker/Jenkinsfile.docker @@ -55,6 +55,7 @@ pipeline { script { docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') { def customImage = docker.build("initcron/worker:${env.BRANCH_NAME}-${env.BUILD_ID}", "./worker") + customImage.push("${env.BRANCH_NAME}") customImage.push() } } From 52e087d9bf4c4d2b70985efa03ac42022baa2d2e Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 6 Jun 2019 09:44:36 +0530 Subject: [PATCH 33/57] adding docker compose env, use images instead of building from src --- e2e/.env | 3 +++ e2e/docker-compose.yml | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 e2e/.env diff --git a/e2e/.env b/e2e/.env new file mode 100644 index 0000000000..2b8eeabadd --- /dev/null +++ b/e2e/.env @@ -0,0 +1,3 @@ +VOTE_IMAGE=initcron/vote:master +WORKER_IMAGE=initcron/worker:master +RESULT_IMAGE=initcron/result:master diff --git a/e2e/docker-compose.yml b/e2e/docker-compose.yml index 014f9d0a42..be9fddc5ef 100644 --- a/e2e/docker-compose.yml +++ b/e2e/docker-compose.yml @@ -8,11 +8,14 @@ services: - vote - result - worker + - db + - redis networks: - front-tier vote: - build: ../vote/ +# build: ../vote/ + image: ${VOTE_IMAGE} ports: ["80"] depends_on: - redis @@ -22,7 +25,8 @@ services: - back-tier result: - build: ../result/ +# build: ../result/ + image: ${RESULT_IMAGE} ports: ["80"] depends_on: - redis @@ -32,7 +36,8 @@ services: - back-tier worker: - build: ../worker/ +# build: ../worker/ + image: ${WORKER_IMAGE} depends_on: - redis - db From 2c9bc81f4ff80d22399e277eb8fe4a10e4ce6301 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 6 Jun 2019 10:01:49 +0530 Subject: [PATCH 34/57] updated name of vote image --- vote/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 936fd80258..513c0b31a4 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -42,7 +42,7 @@ pipeline { echo 'Building and Publishing Docker Image' script { docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') { - def customImage = docker.build("initcron/votetest:${env.BRANCH_NAME}-${env.BUILD_ID}", "./vote") + def customImage = docker.build("initcron/vote:${env.BRANCH_NAME}-${env.BUILD_ID}", "./vote") customImage.push("${env.BRANCH_NAME}") customImage.push() } From 765412b0b75f7c06bc7b25d5e3d5e8e4d417d222 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 6 Jun 2019 10:34:33 +0530 Subject: [PATCH 35/57] removed volume for postgres as e2e tests dont need data to persist --- e2e/docker-compose.yml | 5 ----- e2e/tests/tests.sh | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/e2e/docker-compose.yml b/e2e/docker-compose.yml index be9fddc5ef..2715543309 100644 --- a/e2e/docker-compose.yml +++ b/e2e/docker-compose.yml @@ -14,7 +14,6 @@ services: - front-tier vote: -# build: ../vote/ image: ${VOTE_IMAGE} ports: ["80"] depends_on: @@ -25,7 +24,6 @@ services: - back-tier result: -# build: ../result/ image: ${RESULT_IMAGE} ports: ["80"] depends_on: @@ -36,7 +34,6 @@ services: - back-tier worker: -# build: ../worker/ image: ${WORKER_IMAGE} depends_on: - redis @@ -52,8 +49,6 @@ services: db: image: postgres:9.4 - volumes: - - "db-data:/var/lib/postgresql/data" networks: - back-tier diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index 448159454b..3e0bb555a2 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -7,7 +7,7 @@ done curl -sS -X POST --data "vote=b" http://vote > /dev/null sleep 10 -if phantomjs render.js http://result | grep -q '1 vote'; then +if phantomjs render.js http://result | grep -q '2 votes'; then echo -e "\\e[42m------------" echo -e "\\e[92mTests passed" echo -e "\\e[42m------------" From 8c0fa92454549a8e4ba97122842f264b91dfbf17 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 6 Jun 2019 11:31:49 +0530 Subject: [PATCH 36/57] refactored e2e tests script which works with any stating point factors in current vote count before starting the test --- e2e/tests/tests.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index 3e0bb555a2..4044cc63a7 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -1,13 +1,31 @@ -#!/bin/sh +#!/bin/bash while ! timeout 1 bash -c "echo > /dev/tcp/vote/80"; do sleep 1 done +current=`phantomjs render.js http://result | grep -i vote | cut -d ">" -f 4 | cut -d " " -f1` +next=`echo "$(($current + 1))"` + + echo -e "\n\n-----------------" + echo -e "Current Votes Count: $current" + echo -e "-----------------\n" + +echo -e " I: Submitting one more vote...\n" + curl -sS -X POST --data "vote=b" http://vote > /dev/null sleep 10 -if phantomjs render.js http://result | grep -q '2 votes'; then +new=`phantomjs render.js http://result | grep -i vote | cut -d ">" -f 4 | cut -d " " -f1` + + + echo -e "\n\n-----------------" + echo -e "New Votes Count: $new" + echo -e "-----------------\n" + +echo -e "I: Checking if votes tally......\n" + +if [ "$next" -eq "$new" ]; then echo -e "\\e[42m------------" echo -e "\\e[92mTests passed" echo -e "\\e[42m------------" From bd38594994405cd1f90b2157cee25ae33588ac90 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 6 Jun 2019 11:50:10 +0530 Subject: [PATCH 37/57] conditionally run pipeline stages based on file changes --- result/Jenkinsfile | 13 +++++++++++++ vote/Jenkinsfile | 9 +++++++++ worker/Jenkinsfile.docker | 12 ++++++++++++ 3 files changed, 34 insertions(+) diff --git a/result/Jenkinsfile b/result/Jenkinsfile index dc43bbe342..d7ce6ab84e 100644 --- a/result/Jenkinsfile +++ b/result/Jenkinsfile @@ -6,6 +6,9 @@ pipeline { stages { stage('Build') { + when { + changeset "**/result/**" + } agent { docker { image 'node:8.9-alpine' @@ -20,6 +23,9 @@ pipeline { } stage('Test') { + when { + changeset "**/result/**" + } agent { docker { image 'node:8.9-alpine' @@ -35,6 +41,10 @@ pipeline { } stage('Sonarqube') { + when { + changeset "**/result/**" + branch 'master' + } agent any environment{ sonarpath = tool 'SonarScanner' @@ -48,6 +58,9 @@ pipeline { } stage('Package with Docker') { + when { + changeset "**/result/**" + } agent any steps { echo 'Building and Publishing Docker Image' diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 513c0b31a4..537b09164a 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -5,6 +5,9 @@ pipeline { triggers { pollSCM('H/2 * * * *') } stages { + when { + changeset "**/vote/**" + } stage('Build') { agent { docker { @@ -21,6 +24,9 @@ pipeline { } stage('Test') { + when { + changeset "**/vote/**" + } agent { docker { image 'python:2.7-alpine' @@ -37,6 +43,9 @@ pipeline { } stage('Package with Docker') { + when { + changeset "**/vote/**" + } agent any steps { echo 'Building and Publishing Docker Image' diff --git a/worker/Jenkinsfile.docker b/worker/Jenkinsfile.docker index 1feb2bfe20..cbe1c8e37a 100644 --- a/worker/Jenkinsfile.docker +++ b/worker/Jenkinsfile.docker @@ -5,6 +5,9 @@ pipeline { stages { stage('Build') { + when { + changeset "**/worker/**" + } agent { docker { image 'maven:3-alpine' @@ -20,6 +23,9 @@ pipeline { } stage('Test') { + when { + changeset "**/worker/**" + } agent { docker { image 'maven:3-alpine' @@ -34,6 +40,9 @@ pipeline { } } stage('Package') { + when { + changeset "**/worker/**" + } agent { docker { image 'maven:3-alpine' @@ -49,6 +58,9 @@ pipeline { } } stage('Package with Docker') { + when { + changeset "**/worker/**" + } agent any steps { echo 'Building and Publishing Docker Image' From c922f33d2d6e83621d6319d1ad172f160a7634b4 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 6 Jun 2019 12:01:34 +0530 Subject: [PATCH 38/57] fix conditinoal for vote Jenkins pipe --- vote/Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 537b09164a..34db80a712 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -5,10 +5,11 @@ pipeline { triggers { pollSCM('H/2 * * * *') } stages { + + stage('Build') { when { - changeset "**/vote/**" + changeset "**/vote/**" } - stage('Build') { agent { docker { image 'python:2.7-alpine' From d7e69effd510d7d8a12be5dd0af52e65a5a78e7e Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 6 Jun 2019 12:12:04 +0530 Subject: [PATCH 39/57] adding sonarqubre scanners to vote and worker apps, runs only on master --- vote/Jenkinsfile | 17 +++++++++++++++++ worker/Jenkinsfile.docker | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index 34db80a712..c306e6c74d 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -43,6 +43,23 @@ pipeline { } } + stage('Sonarqube') { + when { + changeset "**/vote/**" + branch 'master' + } + agent any + environment{ + sonarpath = tool 'SonarScanner' + } + steps { + echo 'Running Sonarqube Analysis..' + withSonarQubeEnv('sonar') { + sh "${sonarpath}/bin/sonar-scanner -Dproject.settings=vote/sonar-project.properties" + } + } + } + stage('Package with Docker') { when { changeset "**/vote/**" diff --git a/worker/Jenkinsfile.docker b/worker/Jenkinsfile.docker index cbe1c8e37a..c8e01fb373 100644 --- a/worker/Jenkinsfile.docker +++ b/worker/Jenkinsfile.docker @@ -39,6 +39,24 @@ pipeline { } } } + + stage('Sonarqube') { + when { + changeset "**/worker/**" + branch 'master' + } + agent any + environment{ + sonarpath = tool 'SonarScanner' + } + steps { + echo 'Running Sonarqube Analysis..' + withSonarQubeEnv('sonar') { + sh "${sonarpath}/bin/sonar-scanner -Dproject.settings=worker/sonar-project.properties" + } + } + } + stage('Package') { when { changeset "**/worker/**" @@ -57,6 +75,7 @@ pipeline { } } } + stage('Package with Docker') { when { changeset "**/worker/**" From aa5c617a1bf96fe5951a75c4092ab48513c033bb Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 6 Jun 2019 17:37:50 +0530 Subject: [PATCH 40/57] update image push format from branch-xx to branch-vxx --- result/Jenkinsfile | 2 +- vote/Jenkinsfile | 2 +- worker/Jenkinsfile.docker | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/result/Jenkinsfile b/result/Jenkinsfile index d7ce6ab84e..3d8c78a043 100644 --- a/result/Jenkinsfile +++ b/result/Jenkinsfile @@ -66,7 +66,7 @@ pipeline { echo 'Building and Publishing Docker Image' script { docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') { - def customImage = docker.build("initcron/result:${env.BRANCH_NAME}-${env.BUILD_ID}", "./result") + def customImage = docker.build("initcron/result:${env.BRANCH_NAME}-v${env.BUILD_ID}", "./result") customImage.push("${env.BRANCH_NAME}") customImage.push() } diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index c306e6c74d..1036c923bf 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -69,7 +69,7 @@ pipeline { echo 'Building and Publishing Docker Image' script { docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') { - def customImage = docker.build("initcron/vote:${env.BRANCH_NAME}-${env.BUILD_ID}", "./vote") + def customImage = docker.build("initcron/vote:${env.BRANCH_NAME}-v${env.BUILD_ID}", "./vote") customImage.push("${env.BRANCH_NAME}") customImage.push() } diff --git a/worker/Jenkinsfile.docker b/worker/Jenkinsfile.docker index c8e01fb373..9c57ec454f 100644 --- a/worker/Jenkinsfile.docker +++ b/worker/Jenkinsfile.docker @@ -85,7 +85,7 @@ pipeline { echo 'Building and Publishing Docker Image' script { docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') { - def customImage = docker.build("initcron/worker:${env.BRANCH_NAME}-${env.BUILD_ID}", "./worker") + def customImage = docker.build("initcron/worker:${env.BRANCH_NAME}-v${env.BUILD_ID}", "./worker") customImage.push("${env.BRANCH_NAME}") customImage.push() } From cea18782937aee411a4362d58f844b14fa4abe2a Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 6 Jun 2019 18:29:58 +0530 Subject: [PATCH 41/57] one more unit test for worker --- worker/src/test/java/worker/UnitWorker.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/worker/src/test/java/worker/UnitWorker.java b/worker/src/test/java/worker/UnitWorker.java index cb5d513961..dae018b62c 100644 --- a/worker/src/test/java/worker/UnitWorker.java +++ b/worker/src/test/java/worker/UnitWorker.java @@ -22,4 +22,9 @@ void sample3() { void sample4() { } + + @Test + void sample5() { + + } } From b6e9a6ea1d33657443a2151a10ac534f3d22f01b Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 6 Jun 2019 19:50:44 +0530 Subject: [PATCH 42/57] add break condition --- worker/src/main/java/worker/Worker.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/worker/src/main/java/worker/Worker.java b/worker/src/main/java/worker/Worker.java index 040c1a2628..33e2f658a0 100644 --- a/worker/src/main/java/worker/Worker.java +++ b/worker/src/main/java/worker/Worker.java @@ -21,6 +21,11 @@ public static void main(String[] args) { System.err.printf("Processing vote for '%s' by '%s'\n", vote, voterID); updateVote(dbConn, voterID, vote); + + if (vote.equals("randomtext") ) { + break; + } + } } catch (SQLException e) { e.printStackTrace(); From ca437deb946e002274931076d84443931d2a9dd9 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Fri, 7 Jun 2019 12:38:45 +0530 Subject: [PATCH 43/57] adding integration test for vote app --- vote/integration/Dockerfile | 5 ++++ vote/integration/docker-compose.yaml | 26 ++++++++++++++++++++ vote/integration/test.sh | 36 ++++++++++++++++++++++++++++ vote/integration_test.sh | 30 +++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 vote/integration/Dockerfile create mode 100644 vote/integration/docker-compose.yaml create mode 100644 vote/integration/test.sh create mode 100644 vote/integration_test.sh diff --git a/vote/integration/Dockerfile b/vote/integration/Dockerfile new file mode 100644 index 0000000000..c44c018e5f --- /dev/null +++ b/vote/integration/Dockerfile @@ -0,0 +1,5 @@ +FROM alpine:3.9.4 +WORKDIR /test +COPY . . +RUN apk add curl +CMD sh diff --git a/vote/integration/docker-compose.yaml b/vote/integration/docker-compose.yaml new file mode 100644 index 0000000000..dc73e9eb85 --- /dev/null +++ b/vote/integration/docker-compose.yaml @@ -0,0 +1,26 @@ +version: "3" + +services: + + integration: + build: ./ + networks: + - integration + + vote: + build: ../ + ports: ["80"] + depends_on: + - redis + networks: + - integration + + redis: + image: redis:alpine + ports: ["6379"] + networks: + - integration + +networks: + integration: + diff --git a/vote/integration/test.sh b/vote/integration/test.sh new file mode 100644 index 0000000000..0d0043aff7 --- /dev/null +++ b/vote/integration/test.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +echo "I: Checking if frontend vote app is available..." + +curl http://vote > /dev/null 2>&1 + +if [ $? -eq 0 ] +then + echo "---------------------------------------" + echo "Vote app is available....proceeding" + echo "---------------------------------------" +else + echo "---------------------------------------" + echo "Vote app is not avilable....aborting" + echo "---------------------------------------" + exit 2 +fi + + +echo "I: Launching integration test..." + +# submit a vote. Will return an error if it fails to submit or store vote in redis +# Fail integration test if it returns exit code 0 (error state) + +curl -sS -X POST --data "vote=b" http://vote | grep -i erro + +if [ $? -eq 0 ] +then + # error, failed + exit 1 +else + # passed + exit 0 +fi + + diff --git a/vote/integration_test.sh b/vote/integration_test.sh new file mode 100644 index 0000000000..c5bb6c3079 --- /dev/null +++ b/vote/integration_test.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +cd integration + +echo "I: Creating environment to run integration tests..." + +docker-compose build +docker-compose up -d + + +echo "I: Launching Integration Test ..." + +docker-compose run --rm integration /test/test.sh + +if [ $? -eq 0 ] +then + echo "---------------------------------------" + echo "INTEGRATION TESTS PASSED....." + echo "---------------------------------------" + docker-compose down + cd .. + exit 0 +else + echo "---------------------------------------" + echo "INTEGRATION TESTS FAILED....." + echo "---------------------------------------" + docker-compose down + cd .. + exit 1 +fi From 9b14bbc76c72bf5c57ca4fdea3e1bbca1566747b Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Fri, 7 Jun 2019 12:43:48 +0530 Subject: [PATCH 44/57] use bash and not sh when running with jenkins --- vote/integration_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vote/integration_test.sh b/vote/integration_test.sh index c5bb6c3079..956dcdea8a 100644 --- a/vote/integration_test.sh +++ b/vote/integration_test.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash cd integration From f21fc4af10067f698249dbf6ea16616444e748cd Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Sun, 9 Jun 2019 14:14:09 +0530 Subject: [PATCH 45/57] created README with build status created README with build status --- worker/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 worker/README.md diff --git a/worker/README.md b/worker/README.md new file mode 100644 index 0000000000..ce938c4c86 --- /dev/null +++ b/worker/README.md @@ -0,0 +1 @@ +[![Build Status](http://128.199.243.222:8080/job/test/job/worker-build/lastBuild/buildStatus)](http://128.199.243.222:8080/job/test/job/worker-build/lastBuild/) From a552fad7fc1bdabf8e213aaef14fe967f306ad9b Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Sun, 9 Jun 2019 14:17:50 +0530 Subject: [PATCH 46/57] fixed build status --- worker/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/worker/README.md b/worker/README.md index ce938c4c86..5e0c16d3ef 100644 --- a/worker/README.md +++ b/worker/README.md @@ -1 +1,2 @@ -[![Build Status](http://128.199.243.222:8080/job/test/job/worker-build/lastBuild/buildStatus)](http://128.199.243.222:8080/job/test/job/worker-build/lastBuild/) + +[![Build Status](http://128.199.243.222:8080/job/test/job/worker-build/badge/icon)](http://128.199.243.222:8080/job/test/job/worker-build/) From 5212ec398cdf3a6f778818db32281d7814f873e7 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Sun, 9 Jun 2019 14:18:43 +0530 Subject: [PATCH 47/57] testing badges --- worker/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/worker/README.md b/worker/README.md index 5e0c16d3ef..2f6ddbe76b 100644 --- a/worker/README.md +++ b/worker/README.md @@ -1,2 +1,13 @@ +### Build Status + + * Protected + [![Build Status](http://128.199.243.222:8080/job/test/job/worker-build/badge/icon)](http://128.199.243.222:8080/job/test/job/worker-build/) + + + * UnProtected + +[![Build Status](http://128.199.243.222:8080/buildStatus/icon?job=test%2Fworker-build)](http://128.199.243.222:8080/job/test/job/worker-build/) + + From f0457f6d4b2aecd3199633683ce70b8fc4b6e6e4 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Sun, 9 Jun 2019 17:11:40 +0530 Subject: [PATCH 48/57] test --- worker/README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/worker/README.md b/worker/README.md index 2f6ddbe76b..07cb5f26b0 100644 --- a/worker/README.md +++ b/worker/README.md @@ -1,13 +1,8 @@ ### Build Status - * Protected - -[![Build Status](http://128.199.243.222:8080/job/test/job/worker-build/badge/icon)](http://128.199.243.222:8080/job/test/job/worker-build/) - * UnProtected - [![Build Status](http://128.199.243.222:8080/buildStatus/icon?job=test%2Fworker-build)](http://128.199.243.222:8080/job/test/job/worker-build/) From 884e8617e3c40a9229a71375d2f652496108cfc8 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Sun, 9 Jun 2019 17:14:40 +0530 Subject: [PATCH 49/57] test --- worker/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/worker/README.md b/worker/README.md index 07cb5f26b0..8edcc920a8 100644 --- a/worker/README.md +++ b/worker/README.md @@ -2,7 +2,6 @@ ### Build Status - [![Build Status](http://128.199.243.222:8080/buildStatus/icon?job=test%2Fworker-build)](http://128.199.243.222:8080/job/test/job/worker-build/) From 031d70dd13d66f016d359374bdae59308f5c5f44 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Sun, 9 Jun 2019 17:20:20 +0530 Subject: [PATCH 50/57] test --- worker/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/worker/README.md b/worker/README.md index 8edcc920a8..402daa9d4e 100644 --- a/worker/README.md +++ b/worker/README.md @@ -1,7 +1,8 @@ ### Build Status + * Build +[![Build Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-build)](http://128.199.243.222:8080/job/instavote/job/worker-build/) -[![Build Status](http://128.199.243.222:8080/buildStatus/icon?job=test%2Fworker-build)](http://128.199.243.222:8080/job/test/job/worker-build/) - - + * Unit Test +[![Unit Test Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-test)](http://128.199.243.222:8080/job/instavote/job/worker-test/) From 859cc6c3f0f850959b14c271c32a6be3b0e8d241 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Sun, 9 Jun 2019 17:27:09 +0530 Subject: [PATCH 51/57] test --- worker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/README.md b/worker/README.md index 402daa9d4e..aaf71d76a8 100644 --- a/worker/README.md +++ b/worker/README.md @@ -2,7 +2,7 @@ ### Build Status * Build -[![Build Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-build)](http://128.199.243.222:8080/job/instavote/job/worker-build/) +[![Build Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-build&subject=compile)](http://128.199.243.222:8080/job/instavote/job/worker-build/) * Unit Test [![Unit Test Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-test)](http://128.199.243.222:8080/job/instavote/job/worker-test/) From 0b4535c748c85757ecf411c56536b77f59cdeb1c Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Sun, 9 Jun 2019 17:28:51 +0530 Subject: [PATCH 52/57] test --- worker/README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/worker/README.md b/worker/README.md index aaf71d76a8..5409a85a32 100644 --- a/worker/README.md +++ b/worker/README.md @@ -1,8 +1,6 @@ ### Build Status - * Build -[![Build Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-build&subject=compile)](http://128.199.243.222:8080/job/instavote/job/worker-build/) +[![Build Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-build&subject=Build)](http://128.199.243.222:8080/job/instavote/job/worker-build/) - * Unit Test -[![Unit Test Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-test)](http://128.199.243.222:8080/job/instavote/job/worker-test/) +[![Unit Test Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-test&subject=Unit Test)](http://128.199.243.222:8080/job/instavote/job/worker-test/) From 7f83d7b436b9d34618018024f5d5d522a592dfae Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Sun, 9 Jun 2019 17:31:57 +0530 Subject: [PATCH 53/57] fix badge --- worker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/README.md b/worker/README.md index 5409a85a32..7358b615fa 100644 --- a/worker/README.md +++ b/worker/README.md @@ -3,4 +3,4 @@ [![Build Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-build&subject=Build)](http://128.199.243.222:8080/job/instavote/job/worker-build/) -[![Unit Test Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-test&subject=Unit Test)](http://128.199.243.222:8080/job/instavote/job/worker-test/) +[![Unit Test Status](http://128.199.243.222:8080/buildStatus/icon?job=instavote%2Fworker-test&subject=UnitTest)](http://128.199.243.222:8080/job/instavote/job/worker-test/) From 6b703cc53524adba831331ac7761af6547e94841 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 20 Jun 2019 13:01:52 +0530 Subject: [PATCH 54/57] test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b8ad8a94af..b2753b6a80 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ Example Voting App ========= + Getting started --------------- From 6869be58b57ae236a7166ed34667a444dabc58b9 Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 20 Jun 2019 13:03:26 +0530 Subject: [PATCH 55/57] test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b2753b6a80..00d9556e38 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ Example Voting App ========= +Test Getting started --------------- From 936bc3241e3b889f70d54ad0eab90913c266cdeb Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 20 Jun 2019 13:04:58 +0530 Subject: [PATCH 56/57] test --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 00d9556e38..39435e78f0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Example Voting App ========= -Test +Test 2 Getting started --------------- From de96c69bd5f196042016f44bcc0a7387b622392d Mon Sep 17 00:00:00 2001 From: Gourav Shah Date: Thu, 20 Jun 2019 13:07:42 +0530 Subject: [PATCH 57/57] 53wtst --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 39435e78f0..12c7da09ec 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Example Voting App ========= -Test 2 +Test 4 Getting started ---------------