From 4ed887726ac2103aa9940675dc1345ea3954756c Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 20 Jul 2025 14:41:32 +0300 Subject: [PATCH 01/36] added application info --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a8ee7312..584e3917 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +2 TRY + Example Voting App ========= From 990ffa762f6e46f97f88174eaec40d7c67fba3d8 Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 20 Jul 2025 15:02:36 +0300 Subject: [PATCH 02/36] added Jenkinsfile for worker with build job --- worker/Jenkinsfile.groovy | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 worker/Jenkinsfile.groovy diff --git a/worker/Jenkinsfile.groovy b/worker/Jenkinsfile.groovy new file mode 100644 index 00000000..e94d7c5a --- /dev/null +++ b/worker/Jenkinsfile.groovy @@ -0,0 +1,31 @@ +pipeline { + agent any + tools { + maven 'maven 3.9.8' + } + stages { + stage("build") { + steps { + echo 'Compiling worker app' + dir('worker') { + sh 'mvn compile' + } + } + } + stage("test") { + steps { + echo 'Running Unit Tests on worker app' + } + } + stage("package") { + steps { + echo 'Packaging worker app' + } + } + } + post { + always { + echo 'Building multibranch pipeline for worker is completed..' + } + } +} From 5da7700627e5eeefa71cfe713a242de47b7d723a Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 20 Jul 2025 15:16:31 +0300 Subject: [PATCH 03/36] added Test and package job for worker pipeline --- worker/Jenkinsfile.groovy | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/worker/Jenkinsfile.groovy b/worker/Jenkinsfile.groovy index e94d7c5a..5773c20c 100644 --- a/worker/Jenkinsfile.groovy +++ b/worker/Jenkinsfile.groovy @@ -6,7 +6,7 @@ pipeline { stages { stage("build") { steps { - echo 'Compiling worker app' + echo 'Compiling worker app..' dir('worker') { sh 'mvn compile' } @@ -14,12 +14,18 @@ pipeline { } stage("test") { steps { - echo 'Running Unit Tests on worker app' + echo 'Running Unit Tests on worker app..' + dir('worker') { + sh 'mvn clean test' + } } } stage("package") { steps { echo 'Packaging worker app' + dir('worker') { + sh 'mvn package' + } } } } From a1fe8db689edfb492ab1cc34a601e95b1813cdbe Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 20 Jul 2025 15:20:08 +0300 Subject: [PATCH 04/36] added Test and package job for worker pipeline --- worker/Jenkinsfile.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/worker/Jenkinsfile.groovy b/worker/Jenkinsfile.groovy index 5773c20c..d1a28890 100644 --- a/worker/Jenkinsfile.groovy +++ b/worker/Jenkinsfile.groovy @@ -24,13 +24,14 @@ pipeline { steps { echo 'Packaging worker app' dir('worker') { - sh 'mvn package' + sh 'mvn package -DskipTests' } } } } post { always { + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true echo 'Building multibranch pipeline for worker is completed..' } } From 93702d886f3baec4a31880784e386558d2956eb5 Mon Sep 17 00:00:00 2001 From: norahalr Date: Mon, 21 Jul 2025 09:09:47 +0300 Subject: [PATCH 05/36] adding Jenkinsfile for result app --- result/Jenkinsfile.groovy | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 result/Jenkinsfile.groovy diff --git a/result/Jenkinsfile.groovy b/result/Jenkinsfile.groovy new file mode 100644 index 00000000..d1a28890 --- /dev/null +++ b/result/Jenkinsfile.groovy @@ -0,0 +1,38 @@ +pipeline { + agent any + tools { + maven 'maven 3.9.8' + } + stages { + stage("build") { + steps { + echo 'Compiling 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' + dir('worker') { + sh 'mvn package -DskipTests' + } + } + } + } + post { + always { + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true + echo 'Building multibranch pipeline for worker is completed..' + } + } +} From 344171a3f7532ce13a588cb7edc8412b9764c603 Mon Sep 17 00:00:00 2001 From: norahalr Date: Mon, 21 Jul 2025 09:14:17 +0300 Subject: [PATCH 06/36] adding mock test --- result/test/mock.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/result/test/mock.test.js b/result/test/mock.test.js index aac87156..716f6f5a 100644 --- a/result/test/mock.test.js +++ b/result/test/mock.test.js @@ -32,6 +32,7 @@ describe('mock test 5', () => { }); }); + describe('mock test 6', () => { it('unit test 6', () => { expect(true).to.be.true; From 7eb39e8a3164a311a5c71e72a2b1cfef8338bff1 Mon Sep 17 00:00:00 2001 From: norahalr Date: Mon, 21 Jul 2025 10:06:49 +0300 Subject: [PATCH 07/36] add docker based agent --- worker/Jenkinsfile.groovy | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/worker/Jenkinsfile.groovy b/worker/Jenkinsfile.groovy index d1a28890..05c16990 100644 --- a/worker/Jenkinsfile.groovy +++ b/worker/Jenkinsfile.groovy @@ -1,38 +1,40 @@ pipeline { - agent any - tools { - maven 'maven 3.9.8' + agent { + docker { + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } } stages { - stage("build") { + stage('build') { steps { - echo 'Compiling worker app..' + echo 'building worker app' dir('worker') { sh 'mvn compile' } } } - stage("test") { + stage('test') { steps { - echo 'Running Unit Tests on worker app..' + echo 'running unit tests on worker app' dir('worker') { sh 'mvn clean test' } } } - stage("package") { + stage('package') { steps { - echo 'Packaging worker app' + echo 'packaging worker app into a jarfile' dir('worker') { sh 'mvn package -DskipTests' + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true } } } } post { always { - archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true - echo 'Building multibranch pipeline for worker is completed..' + echo 'the job is complete' } } } From a5e811d4f8973c18dfbb1176ec555b96a9524e0c Mon Sep 17 00:00:00 2001 From: norahalr Date: Mon, 21 Jul 2025 14:56:43 +0300 Subject: [PATCH 08/36] 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..fb0b0cbc --- /dev/null +++ b/worker/Dockerfile @@ -0,0 +1,6 @@ +FROM maven:3.9.8-sapmachine-21 +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"] From bed2ac7972232c38d65cf7afd1c089d7183a4e9b Mon Sep 17 00:00:00 2001 From: norahalr Date: Mon, 21 Jul 2025 15:41:01 +0300 Subject: [PATCH 09/36] Added Docker build stage to Jenkinsfile --- worker/Jenkinsfile.groovy | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/worker/Jenkinsfile.groovy b/worker/Jenkinsfile.groovy index 05c16990..f7c2b5cd 100644 --- a/worker/Jenkinsfile.groovy +++ b/worker/Jenkinsfile.groovy @@ -24,13 +24,26 @@ pipeline { } stage('package') { steps { - echo 'packaging worker app into a jarfile' + echo 'packaging worker app into a jar file' 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("norahns/worker:${env.BUILD_ID}", "./worker") + workerImage.push() + workerImage.push("latest") + } + } + } + } } post { always { From 7f5babcb192b8a28830dbb666c6ae4965a7a4970 Mon Sep 17 00:00:00 2001 From: norahalr Date: Mon, 21 Jul 2025 16:03:15 +0300 Subject: [PATCH 10/36] per stage agents, conditional execution --- worker/Jenkinsfile.groovy | 122 ++++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 43 deletions(-) diff --git a/worker/Jenkinsfile.groovy b/worker/Jenkinsfile.groovy index f7c2b5cd..47a7e1a3 100644 --- a/worker/Jenkinsfile.groovy +++ b/worker/Jenkinsfile.groovy @@ -1,53 +1,89 @@ pipeline { - agent { - docker { + + agent none + + stages{ + stage("build"){ + when{ + changeset "**/worker/**" + } + + agent{ + docker{ image 'maven:3.9.8-sapmachine-21' args '-v $HOME/.m2:/root/.m2' + } } - } - stages { - stage('build') { - steps { - echo 'building worker app' - dir('worker') { - sh 'mvn compile' - } - } + + steps{ + echo 'Compiling worker app..' + dir('worker'){ + sh 'mvn compile' + } } - stage('test') { - steps { - echo 'running unit tests on worker app' - dir('worker') { - sh 'mvn clean test' - } - } + } + stage("test"){ + when{ + changeset "**/worker/**" } - stage('package') { - steps { - echo 'packaging worker app into a jar file' - dir('worker') { - sh 'mvn package -DskipTests' - archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true - } - } + agent{ + docker{ + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } } - 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("norahns/worker:${env.BUILD_ID}", "./worker") - workerImage.push() - workerImage.push("latest") - } - } - } + steps{ + echo 'Running Unit Tets on worker app..' + dir('worker'){ + sh 'mvn clean test' + } + + } + } + stage("package"){ + when{ + branch 'master' + changeset "**/worker/**" } - } - post { - always { - echo 'the job is complete' + agent{ + docker{ + image 'maven:3.9.8-sapmachine-21' + 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 with docker' + script{ + docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { + def workerImage = docker.build("norahns/worker:v${env.BUILD_ID}", "./worker") + workerImage.push() + workerImage.push("${env.BRANCH_NAME}") + workerImage.push("latest") + } + } + } + } + } + + post{ + always{ + echo 'Building multibranch pipeline for worker is completed..' } -} + } +} \ No newline at end of file From ff57944d1d34037626a57d301ca5ba9de75b9e46 Mon Sep 17 00:00:00 2001 From: norahalr Date: Mon, 21 Jul 2025 16:36:11 +0300 Subject: [PATCH 11/36] Added Dockerfiles and Jenkinsfiles for vote/result --- result/Dockerfile | 23 +++++++++++++ result/Jenkinsfile | 84 ++++++++++++++++++++++++++++++++++++++++++++++ vote/Dockerfile | 22 ++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 result/Dockerfile create mode 100644 result/Jenkinsfile create mode 100644 vote/Dockerfile diff --git a/result/Dockerfile b/result/Dockerfile new file mode 100644 index 00000000..a3dc9802 --- /dev/null +++ b/result/Dockerfile @@ -0,0 +1,23 @@ +FROM node:22.4.0-slim + +# Install curl for health checks and tini for process management +RUN apt-get update && \ + apt-get install -y --no-install-recommends curl tini && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /usr/local/app + +# Install nodemon for development (optional) +RUN npm install -g nodemon + +COPY package*.json ./ +RUN npm ci && \ + npm cache clean --force && \ + mv /usr/local/app/node_modules /node_modules + +COPY . . +ENV PORT 80 +EXPOSE 80 + +ENTRYPOINT ["/usr/bin/tini", "--"] +CMD ["node", "server.js"] \ No newline at end of file diff --git a/result/Jenkinsfile b/result/Jenkinsfile new file mode 100644 index 00000000..1af2dd2a --- /dev/null +++ b/result/Jenkinsfile @@ -0,0 +1,84 @@ +pipeline { + agent none + + stages { + stage("build") { + when { + changeset "**/worker/**" + } + agent { + docker { + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } + } + steps { + echo 'Compiling worker app..' + dir('worker') { + sh 'mvn compile' + } + } + } + + stage("test") { + when { + changeset "**/worker/**" + } + agent { + docker { + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } + } + steps { + echo 'Running Unit Tests on worker app..' + dir('worker') { + sh 'mvn clean test' + } + } + } + + stage("package") { + when { + branch 'master' + changeset "**/worker/**" + } + agent { + docker { + image 'maven:3.9.8-sapmachine-21' + 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 { + branch 'master' + changeset "**/result/**" + } + steps { + script { + docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { + def resultImage = docker.build("norahns/result:v${env.BUILD_ID}", "./result") + resultImage.push() + resultImage.push("latest") + } + } + } + } + } + + post { + always { + echo 'Building multibranch pipeline for worker is completed..' + } + } +} diff --git a/vote/Dockerfile b/vote/Dockerfile new file mode 100644 index 00000000..7df264c4 --- /dev/null +++ b/vote/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.11-slim AS base + +# Install curl for health checks +RUN apt-get update && \ + apt-get install -y --no-install-recommends curl && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /usr/local/app +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +# Development stage (optional) +FROM base AS dev +RUN pip install watchdog +ENV FLASK_ENV=development +CMD ["python", "app.py"] + +# Production stage +FROM base AS final +COPY . . +EXPOSE 80 +CMD ["gunicorn", "app:app", "-b", "0.0.0.0:80", "--log-file", "-", "--access-logfile", "-", "--workers", "4", "--keep-alive", "0"] \ No newline at end of file From 78794d2b0e066188f3dec1d93ca45c9b49850f30 Mon Sep 17 00:00:00 2001 From: norahalr Date: Tue, 22 Jul 2025 15:06:18 +0300 Subject: [PATCH 12/36] adding docker compose spec --- docker-compose.yaml | 52 +++++++++++++++++++++++++++++++++++++++ result/Dockerfile | 9 ++++--- result/Jenkinsfile.groovy | 38 ---------------------------- vote/Dockerfile | 18 +++++++++++--- vote/Jenkinsfile | 30 +++++++++++----------- 5 files changed, 87 insertions(+), 60 deletions(-) create mode 100644 docker-compose.yaml delete mode 100644 result/Jenkinsfile.groovy diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..a3c314cc --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,52 @@ +volumes: + db-data: + +networks: + instavote: + driver: bridge + +services: + vote: + image: norahns/vote:latest + ports: + - "5000:80" + depends_on: + - redis + networks: + - instavote + + redis: + image: redis:alpine + networks: + - instavote + + db: + image: postgres:15-alpine + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + volumes: + - db-data:/var/lib/postgresql/data + - ./healthchecks:/healthchecks + healthcheck: + test: /healthchecks/postgres.sh + interval: 5s + networks: + - instavote + + result: + image: norahns/result:latest + ports: + - "5001:80" + depends_on: + - db + networks: + - instavote + + worker: + image: norahns/worker:latest + depends_on: + - redis + - db + networks: + - instavote diff --git a/result/Dockerfile b/result/Dockerfile index a3dc9802..10eeb5b1 100644 --- a/result/Dockerfile +++ b/result/Dockerfile @@ -1,23 +1,26 @@ FROM node:22.4.0-slim -# Install curl for health checks and tini for process management +# Add curl for healthcheck and tini for signal handling RUN apt-get update && \ apt-get install -y --no-install-recommends curl tini && \ rm -rf /var/lib/apt/lists/* WORKDIR /usr/local/app -# Install nodemon for development (optional) +# Have nodemon available for local dev use (file watching) RUN npm install -g nodemon COPY package*.json ./ + RUN npm ci && \ npm cache clean --force && \ mv /usr/local/app/node_modules /node_modules COPY . . -ENV PORT 80 + +ENV PORT=80 EXPOSE 80 ENTRYPOINT ["/usr/bin/tini", "--"] + CMD ["node", "server.js"] \ No newline at end of file diff --git a/result/Jenkinsfile.groovy b/result/Jenkinsfile.groovy deleted file mode 100644 index d1a28890..00000000 --- a/result/Jenkinsfile.groovy +++ /dev/null @@ -1,38 +0,0 @@ -pipeline { - agent any - tools { - maven 'maven 3.9.8' - } - stages { - stage("build") { - steps { - echo 'Compiling 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' - dir('worker') { - sh 'mvn package -DskipTests' - } - } - } - } - post { - always { - archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true - echo 'Building multibranch pipeline for worker is completed..' - } - } -} diff --git a/vote/Dockerfile b/vote/Dockerfile index 7df264c4..77877b05 100644 --- a/vote/Dockerfile +++ b/vote/Dockerfile @@ -1,22 +1,32 @@ +# Define a base stage that uses the official python runtime base image FROM python:3.11-slim AS base -# Install curl for health checks +# Add curl for healthcheck RUN apt-get update && \ apt-get install -y --no-install-recommends curl && \ rm -rf /var/lib/apt/lists/* +# Set the application directory WORKDIR /usr/local/app -COPY requirements.txt ./ + +# Install our requirements.txt +COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt -# Development stage (optional) +# Define a stage specifically for development, where it'll watch for filesystem changes FROM base AS dev RUN pip install watchdog ENV FLASK_ENV=development CMD ["python", "app.py"] -# Production stage +# Define the final stage that will bundle the application for production FROM base AS final + +# Copy our code from the current folder to the working directory inside the container COPY . . + +# Make port 80 available for links and/or publish EXPOSE 80 + +# Define our command to be run when launching the container CMD ["gunicorn", "app:app", "-b", "0.0.0.0:80", "--log-file", "-", "--access-logfile", "-", "--workers", "4", "--keep-alive", "0"] \ No newline at end of file diff --git a/vote/Jenkinsfile b/vote/Jenkinsfile index b2fd93e1..bcbc4e6d 100644 --- a/vote/Jenkinsfile +++ b/vote/Jenkinsfile @@ -38,22 +38,22 @@ pipeline { } } - stage('docker-package'){ - agent any - - steps{ - echo 'Packaging wvoteorker app with docker' - script{ - docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { - // ./vote is the path to the Dockerfile that Jenkins will find from the Github repo - def voteImage = docker.build("xxxx/vote:v${env.BUILD_ID}", "./vote") - voteImage.push() - voteImage.push("${env.BRANCH_NAME}") - voteImage.push("latest") - } + stage('docker-package') { + agent any + when { + branch 'master' + changeset "**/vote/**" } - } - } + steps { + script { + docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { + def voteImage = docker.build("norahns/vote:v${env.BUILD_ID}", "./vote") + voteImage.push() + voteImage.push("latest") + } + } + } + } } post { From 423d68ebd9e29c565ebd51dc37b6a48c3f84eee4 Mon Sep 17 00:00:00 2001 From: norahalr Date: Tue, 22 Jul 2025 15:50:26 +0300 Subject: [PATCH 13/36] all --- Jenkinsfile | 239 ++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 13 ++- worker/Jenkinsfile | 89 +++++++++++++++++ 3 files changed, 336 insertions(+), 5 deletions(-) create mode 100644 Jenkinsfile create mode 100644 worker/Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..7723fb06 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,239 @@ +pipeline { + + agent none + + stages { + + stage('worker-build') { + agent { + docker { + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } + + } + when { + changeset '**/worker/**' + } + steps { + echo 'Compiling worker app..' + dir(path: 'worker') { + sh 'mvn compile' + } + + } + } + + stage('worker test') { + agent { + docker { + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } + + } + when { + changeset '**/worker/**' + } + steps { + echo 'Running Unit Tets on worker app.' + dir(path: 'worker') { + sh 'mvn clean test' + } + + } + } + + stage('worker-package') { + agent { + docker { + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } + + } + when { + branch 'master' + changeset '**/worker/**' + } + steps { + echo 'Packaging worker app' + dir(path: 'worker') { + sh 'mvn package -DskipTests' + archiveArtifacts(artifacts: '**/target/*.jar', fingerprint: true) + } + + } + } + + stage('worker-docker-package') { + agent any + when { + changeset '**/worker/**' + branch 'master' + } + steps { + 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('result-build') { + agent { + docker { + image 'node:22.4.0-alpine' + } + + } + when { + changeset '**/result/**' + } + steps { + echo 'Compiling result app..' + dir(path: 'result') { + sh 'npm install' + } + + } + } + + stage('result-test') { + agent { + docker { + image 'node:22.4.0-alpine' + } + + } + when { + changeset '**/result/**' + } + steps { + echo 'Running Unit Tests on result app..' + dir(path: 'result') { + sh 'npm install' + sh 'npm test' + } + + } + } + + stage('result-docker-package') { + agent any + when { + changeset '**/result/**' + branch 'master' + } + steps { + echo 'Packaging result app with docker' + script { + docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { + def resultImage = docker.build("xxxxx/result:v${env.BUILD_ID}", './result') + resultImage.push() + resultImage.push("${env.BRANCH_NAME}") + resultImage.push('latest') + } + } + } + } + + stage('vote-build') { + agent { + docker { + image 'python:3.11-slim' + args '--user root' + } + + } + when { + changeset '**/vote/**' + } + steps { + echo 'Compiling vote app.' + dir(path: 'vote') { + sh 'pip install -r requirements.txt' + } + + } + } + + stage('vote-test') { + agent { + docker { + image 'python:3.11-slim' + args '--user root' + } + + } + when { + changeset '**/vote/**' + } + steps { + echo 'Running Unit Tests on vote app.' + dir(path: 'vote') { + sh 'pip install -r requirements.txt' + sh 'nosetests -v' + } + + } + } + + stage('vote integration'){ + agent any + when{ + changeset "**/vote/**" + branch 'master' + } + steps{ + echo 'Running Integration Tests on vote app' + dir('vote'){ + sh 'sh integration_test.sh' + } + } +} + + + stage('vote-docker-package') { + agent any + steps { + echo 'Packaging vote app with docker' + script { + docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { + // ./vote is the path to the Dockerfile that Jenkins will find from the Github repo + def voteImage = docker.build("xxxxx/vote:${env.GIT_COMMIT}", "./vote") + voteImage.push() + voteImage.push("${env.BRANCH_NAME}") + voteImage.push("latest") + } + } + + } + } + + + stage('deploy to dev') { + agent any + when { + branch 'master' + } + steps { + echo 'Deploy instavote app with docker compose' + sh 'docker-compose up -d' + } + } + + } + + post { + always { + echo 'Building mono pipeline for voting app is completed.' + } + } +} \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index a3c314cc..f96f63e6 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,8 +8,9 @@ networks: services: vote: image: norahns/vote:latest + build: ./vote ports: - - "5000:80" + - 5000:80 depends_on: - redis networks: @@ -26,18 +27,19 @@ services: POSTGRES_USER: "postgres" POSTGRES_PASSWORD: "postgres" volumes: - - db-data:/var/lib/postgresql/data - - ./healthchecks:/healthchecks + - "db-data:/var/lib/postgresql/data" + - "./healthchecks:/healthchecks" healthcheck: test: /healthchecks/postgres.sh - interval: 5s + interval: "5s" networks: - instavote result: image: norahns/result:latest + build: ./result ports: - - "5001:80" + - 5001:80 depends_on: - db networks: @@ -45,6 +47,7 @@ services: worker: image: norahns/worker:latest + build: ./worker depends_on: - redis - db diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile new file mode 100644 index 00000000..47a7e1a3 --- /dev/null +++ b/worker/Jenkinsfile @@ -0,0 +1,89 @@ +pipeline { + + agent none + + stages{ + stage("build"){ + when{ + changeset "**/worker/**" + } + + agent{ + docker{ + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } + } + + steps{ + echo 'Compiling worker app..' + dir('worker'){ + sh 'mvn compile' + } + } + } + stage("test"){ + when{ + changeset "**/worker/**" + } + agent{ + docker{ + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } + } + steps{ + echo 'Running Unit Tets on worker app..' + dir('worker'){ + sh 'mvn clean test' + } + + } + } + stage("package"){ + when{ + branch 'master' + changeset "**/worker/**" + } + agent{ + docker{ + image 'maven:3.9.8-sapmachine-21' + 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 with docker' + script{ + docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { + def workerImage = docker.build("norahns/worker:v${env.BUILD_ID}", "./worker") + workerImage.push() + workerImage.push("${env.BRANCH_NAME}") + workerImage.push("latest") + } + } + } + } + } + + post{ + always{ + echo 'Building multibranch pipeline for worker is completed..' + } + } +} \ No newline at end of file From 4cacfba75fcd32fd816fa07484592cb6b457781c Mon Sep 17 00:00:00 2001 From: norahalr Date: Tue, 22 Jul 2025 16:45:50 +0300 Subject: [PATCH 14/36] jenkins file --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7723fb06..0b8c96b0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -76,7 +76,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("norahns/worker:v${env.BUILD_ID}", './worker') workerImage.push() workerImage.push("${env.BRANCH_NAME}") workerImage.push('latest') @@ -135,7 +135,7 @@ pipeline { echo 'Packaging result app with docker' script { docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { - def resultImage = docker.build("xxxxx/result:v${env.BUILD_ID}", './result') + def resultImage = docker.build("norahns/result:v${env.BUILD_ID}", './result') resultImage.push() resultImage.push("${env.BRANCH_NAME}") resultImage.push('latest') @@ -207,7 +207,7 @@ pipeline { script { docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { // ./vote is the path to the Dockerfile that Jenkins will find from the Github repo - def voteImage = docker.build("xxxxx/vote:${env.GIT_COMMIT}", "./vote") + def voteImage = docker.build("norahns/vote:${env.GIT_COMMIT}", "./vote") voteImage.push() voteImage.push("${env.BRANCH_NAME}") voteImage.push("latest") From d5e90a71775aca60810e82a85239d4bd1d4f1ca5 Mon Sep 17 00:00:00 2001 From: norahalr Date: Tue, 22 Jul 2025 16:55:32 +0300 Subject: [PATCH 15/36] jenkins file --- Jenkinsfile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0b8c96b0..0d3e216c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -202,15 +202,18 @@ pipeline { stage('vote-docker-package') { agent any + when { + changeset '**/vote/**' + branch 'master' + } steps { echo 'Packaging vote app with docker' script { + def sanitizedBranch = env.BRANCH_NAME.replace('/', '-') docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { - // ./vote is the path to the Dockerfile that Jenkins will find from the Github repo - def voteImage = docker.build("norahns/vote:${env.GIT_COMMIT}", "./vote") + def voteImage = docker.build("norahns/vote:${env.BUILD_ID}", "./vote") voteImage.push() - voteImage.push("${env.BRANCH_NAME}") - voteImage.push("latest") + voteImage.push(sanitizedBranch) // Now uses "feature-monopipe" instead } } @@ -225,7 +228,7 @@ pipeline { } steps { echo 'Deploy instavote app with docker compose' - sh 'docker-compose up -d' + sh 'docker compose up -d' } } From ff499bff3c1c271f4b874a71209e6b3a4f404700 Mon Sep 17 00:00:00 2001 From: norahalr Date: Wed, 23 Jul 2025 16:19:10 +0300 Subject: [PATCH 16/36] update --- Jenkinsfile | 30 +++++++++++++++++++++++++ sonar-project.properties | 4 ++-- worker/src/main/java/worker/Worker.java | 21 +++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0d3e216c..733290bb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -220,7 +220,37 @@ pipeline { } } + stage('Sonarqube') { + agent any + when{ + branch 'master' + } + // tools { + // jdk "JDK11" // the name you have given the JDK installation in Global Tool Configuration + // } + + environment{ + sonarpath = tool 'SonarScanner' + } + + steps { + echo 'Running Sonarqube Analysis..' + withSonarQubeEnv('sonar-instavote') { + sh "${sonarpath}/bin/sonar-scanner -Dproject.settings=sonar-project.properties -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=86400" + } + } + } + + stage("Quality Gate") { + steps { + timeout(time: 1, unit: 'HOURS') { + // Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails + // true = set pipeline to UNSTABLE, false = don't + waitForQualityGate abortPipeline: true + } + } + } stage('deploy to dev') { agent any when { diff --git a/sonar-project.properties b/sonar-project.properties index dcd32fdc..f461c6fb 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,6 +1,6 @@ # Uncomment and update Org matching your configurations on Sonarcloud -sonar.organization=your-org -sonar.projectKey=your-org_example-voting-app +sonar.organization=norahalr +sonar.projectKey=norahalr_LFS261-example-voting-app sonar.projectName=Instavote AIO sonar.projectVersion=1.0 # Comma-separated paths to directories with sources (required) diff --git a/worker/src/main/java/worker/Worker.java b/worker/src/main/java/worker/Worker.java index 26e5a8bb..00cbd828 100644 --- a/worker/src/main/java/worker/Worker.java +++ b/worker/src/main/java/worker/Worker.java @@ -123,4 +123,25 @@ static void sleep(long duration) { System.exit(1); } } +static class FizzBuzz { + public static void generate(int limit) { + for (int i = 1; i <= limit; i++) { + if (i % 3 == 0 && i % 5 == 0) { + System.out.println("FizzBuzz"); + } else if (i % 3 == 0) { + System.out.println("Fizz"); + } else if (i % 5 == 0) { + System.out.println("Buzz"); + } else { + System.out.println(i); + } + } + } + + // Example of how it could be called, not part of the main application flow + public static void main(String[] args) { + System.out.println("FizzBuzz demonstration:"); + generate(20); // Generate FizzBuzz up to 20 + } + } } From ae51f84ae1af688004fd06c94ffa4cb85b8906e1 Mon Sep 17 00:00:00 2001 From: norahalr Date: Thu, 24 Jul 2025 08:59:18 +0300 Subject: [PATCH 17/36] jenkin lab 8 --- Jenkinsfile | 47 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 733290bb..7723fb06 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -76,7 +76,7 @@ pipeline { echo 'Packaging worker app with docker' script { docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { - def workerImage = docker.build("norahns/worker:v${env.BUILD_ID}", './worker') + def workerImage = docker.build("xxxxx/worker:v${env.BUILD_ID}", './worker') workerImage.push() workerImage.push("${env.BRANCH_NAME}") workerImage.push('latest') @@ -135,7 +135,7 @@ pipeline { echo 'Packaging result app with docker' script { docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { - def resultImage = docker.build("norahns/result:v${env.BUILD_ID}", './result') + def resultImage = docker.build("xxxxx/result:v${env.BUILD_ID}", './result') resultImage.push() resultImage.push("${env.BRANCH_NAME}") resultImage.push('latest') @@ -202,55 +202,22 @@ pipeline { stage('vote-docker-package') { agent any - when { - changeset '**/vote/**' - branch 'master' - } steps { echo 'Packaging vote app with docker' script { - def sanitizedBranch = env.BRANCH_NAME.replace('/', '-') docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { - def voteImage = docker.build("norahns/vote:${env.BUILD_ID}", "./vote") + // ./vote is the path to the Dockerfile that Jenkins will find from the Github repo + def voteImage = docker.build("xxxxx/vote:${env.GIT_COMMIT}", "./vote") voteImage.push() - voteImage.push(sanitizedBranch) // Now uses "feature-monopipe" instead + voteImage.push("${env.BRANCH_NAME}") + voteImage.push("latest") } } } } - stage('Sonarqube') { - agent any - when{ - branch 'master' - } - // tools { - // jdk "JDK11" // the name you have given the JDK installation in Global Tool Configuration - // } - - environment{ - sonarpath = tool 'SonarScanner' - } - - steps { - echo 'Running Sonarqube Analysis..' - withSonarQubeEnv('sonar-instavote') { - sh "${sonarpath}/bin/sonar-scanner -Dproject.settings=sonar-project.properties -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=86400" - } - } - } - - stage("Quality Gate") { - steps { - timeout(time: 1, unit: 'HOURS') { - // Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails - // true = set pipeline to UNSTABLE, false = don't - waitForQualityGate abortPipeline: true - } - } - } stage('deploy to dev') { agent any when { @@ -258,7 +225,7 @@ pipeline { } steps { echo 'Deploy instavote app with docker compose' - sh 'docker compose up -d' + sh 'docker-compose up -d' } } From 1bb3bb0ccec6ea1e630d4392d99b9d57130512f4 Mon Sep 17 00:00:00 2001 From: norahalr Date: Thu, 24 Jul 2025 09:22:24 +0300 Subject: [PATCH 18/36] fkkd --- Jenkinsfile | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7723fb06..1715dc5e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -185,20 +185,19 @@ pipeline { } } - stage('vote integration'){ - agent any - when{ - changeset "**/vote/**" - branch 'master' - } - steps{ - echo 'Running Integration Tests on vote app' - dir('vote'){ - sh 'sh integration_test.sh' - } - } -} - + stage('vote-integration') { + agent any + when { + changeset '**/vote/**' + branch 'master' + } + steps { + echo 'Running Integration Tests on vote app' + dir('vote') { + sh 'sh integration_test.sh' + } + } + } stage('vote-docker-package') { agent any From c674282e016e1ef98a038fff7e61328aca0cd373 Mon Sep 17 00:00:00 2001 From: norahalr Date: Thu, 24 Jul 2025 09:38:16 +0300 Subject: [PATCH 19/36] jinkens --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1715dc5e..5f4024ac 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -206,7 +206,7 @@ pipeline { script { docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { // ./vote is the path to the Dockerfile that Jenkins will find from the Github repo - def voteImage = docker.build("xxxxx/vote:${env.GIT_COMMIT}", "./vote") + def voteImage = docker.build("norahalr/vote:${env.GIT_COMMIT}", "./vote") voteImage.push() voteImage.push("${env.BRANCH_NAME}") voteImage.push("latest") From a890964cf76e6184a252e00270961804258522aa Mon Sep 17 00:00:00 2001 From: norahalr Date: Thu, 24 Jul 2025 09:45:11 +0300 Subject: [PATCH 20/36] Added Quality Gate and fixed Docker packaging stages --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5f4024ac..4c0d0c65 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -76,7 +76,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("norahalr/worker:v${env.BUILD_ID}", './worker') workerImage.push() workerImage.push("${env.BRANCH_NAME}") workerImage.push('latest') @@ -135,7 +135,7 @@ pipeline { echo 'Packaging result app with docker' script { docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { - def resultImage = docker.build("xxxxx/result:v${env.BUILD_ID}", './result') + def resultImage = docker.build("norahalr/result:v${env.BUILD_ID}", './result') resultImage.push() resultImage.push("${env.BRANCH_NAME}") resultImage.push('latest') From f1d44e123f3491b209c01a814f5b91c8f6ca2253 Mon Sep 17 00:00:00 2001 From: norahalr Date: Thu, 24 Jul 2025 14:30:03 +0300 Subject: [PATCH 21/36] fix: update docker image names to match Docker Hub account --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4c0d0c65..e12a94bc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -76,7 +76,7 @@ pipeline { echo 'Packaging worker app with docker' script { docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { - def workerImage = docker.build("norahalr/worker:v${env.BUILD_ID}", './worker') + def workerImage = docker.build("norahns/worker:v${env.BUILD_ID}", './worker') workerImage.push() workerImage.push("${env.BRANCH_NAME}") workerImage.push('latest') @@ -135,7 +135,7 @@ pipeline { echo 'Packaging result app with docker' script { docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { - def resultImage = docker.build("norahalr/result:v${env.BUILD_ID}", './result') + def resultImage = docker.build("norahns/result:v${env.BUILD_ID}", './result') resultImage.push() resultImage.push("${env.BRANCH_NAME}") resultImage.push('latest') @@ -206,7 +206,7 @@ pipeline { script { docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') { // ./vote is the path to the Dockerfile that Jenkins will find from the Github repo - def voteImage = docker.build("norahalr/vote:${env.GIT_COMMIT}", "./vote") + def voteImage = docker.build("norahns/vote:${env.GIT_COMMIT}", "./vote") voteImage.push() voteImage.push("${env.BRANCH_NAME}") voteImage.push("latest") From f5b75e561c606597c9bd3c44cb97fbf482d54396 Mon Sep 17 00:00:00 2001 From: norahalr Date: Thu, 24 Jul 2025 15:48:02 +0300 Subject: [PATCH 22/36] changes --- e2e/.env | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/.env b/e2e/.env index 100455d5..24b21980 100644 --- a/e2e/.env +++ b/e2e/.env @@ -1,3 +1,3 @@ -VOTE_IMAGE=xxxx/vote:latest -WORKER_IMAGE=xxxx/worker:latest -RESULT_IMAGE=xxxx/result:latest +VOTE_IMAGE=norahns/vote:latest +WORKER_IMAGE=norahns/worker:latest +RESULT_IMAGE=norahns/result:latest From 1c966efc069003ca0579dcf39c54f5dd59c4bb2f Mon Sep 17 00:00:00 2001 From: norahalr Date: Thu, 24 Jul 2025 15:52:57 +0300 Subject: [PATCH 23/36] docker --- e2e/tests/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/tests/Dockerfile b/e2e/tests/Dockerfile index d5a2f8b2..0010793f 100644 --- a/e2e/tests/Dockerfile +++ b/e2e/tests/Dockerfile @@ -9,4 +9,4 @@ RUN apt-get update -qq && apt-get install -qy \ RUN yarn global add phantomjs-prebuilt ADD . /app WORKDIR /app -CMD ./tests.sh +CMD ./e2e.sh From 758981b9010edac51bf7dfebd86d7b9d9ef32a4a Mon Sep 17 00:00:00 2001 From: norahalr Date: Thu, 24 Jul 2025 15:58:13 +0300 Subject: [PATCH 24/36] fix: make tests.sh executable --- e2e/tests/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/tests/Dockerfile b/e2e/tests/Dockerfile index 0010793f..d5a2f8b2 100644 --- a/e2e/tests/Dockerfile +++ b/e2e/tests/Dockerfile @@ -9,4 +9,4 @@ RUN apt-get update -qq && apt-get install -qy \ RUN yarn global add phantomjs-prebuilt ADD . /app WORKDIR /app -CMD ./e2e.sh +CMD ./tests.sh From 8a151fc5b730aca7a812d5205f9caef0e3e74dfb Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 10:58:03 +0300 Subject: [PATCH 25/36] mess --- e2e/tests/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/tests/Dockerfile b/e2e/tests/Dockerfile index d5a2f8b2..61191c5d 100644 --- a/e2e/tests/Dockerfile +++ b/e2e/tests/Dockerfile @@ -9,4 +9,4 @@ RUN apt-get update -qq && apt-get install -qy \ RUN yarn global add phantomjs-prebuilt ADD . /app WORKDIR /app -CMD ./tests.sh +CMD ["sh", "-c", "cd /app && ./tests.sh"] From 77809583282e027e75c9d3be542298b98695cb8a Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 11:38:44 +0300 Subject: [PATCH 26/36] yay --- e2e/tests/Dockerfile | 2 +- e2e/tests/tests.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/tests/Dockerfile b/e2e/tests/Dockerfile index 61191c5d..85e00756 100644 --- a/e2e/tests/Dockerfile +++ b/e2e/tests/Dockerfile @@ -9,4 +9,4 @@ RUN apt-get update -qq && apt-get install -qy \ RUN yarn global add phantomjs-prebuilt ADD . /app WORKDIR /app -CMD ["sh", "-c", "cd /app && ./tests.sh"] +CMD ./tests.sh \ No newline at end of file diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index c2811eaa..6a2550ad 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Function to get current vote count get_vote_count() { From 9470d6f8d17d17c7131e9ea5244663a36b9f6cc8 Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 11:46:31 +0300 Subject: [PATCH 27/36] the bash --- e2e/tests/tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index 6a2550ad..c2811eaa 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Function to get current vote count get_vote_count() { From 67d0e84d6c3d279c42b313fd0c775691f2ad90b5 Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 11:49:55 +0300 Subject: [PATCH 28/36] bash --- e2e/tests/tests.sh | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index c2811eaa..9ad0f0bc 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -2,7 +2,7 @@ # Function to get current vote count get_vote_count() { - phantomjs render.js "http://result:80/" | grep -i vote | cut -d ">" -f 4 | cut -d " " -f1 + phantomjs render.js "http://result:80/" | grep -oE '[0-9]+' | head -n 1 } # Wait for services to be ready @@ -19,31 +19,20 @@ echo "Result service is ready." # Get initial vote count initial_count=$(get_vote_count) - echo "Initial vote count: $initial_count" - - # Submit first vote echo "Submitting vote (a)..." curl -sS -X POST --data "vote=a" http://vote sleep 2 -current=$(get_vote_count) -echo "Vote count after first submission: $current" - -# Calculate expected next count -# final=$((initial_count + 1)) -# echo "Expected final count: $final" -# Check vote count multiple times -# for i in {1..5}; do - # sleep 2 +# Get new vote count new=$(get_vote_count) -# done +echo "Vote count after first submission: $new" # Final check echo "Performing final check..." -if [ $initial_count -lt $new ]; then +if ! [ -z "$initial_count" ] && ! [ -z "$new" ] && [ "$initial_count" -lt "$new" ]; then echo -e "\e[42m------------" echo -e "\e[92mTests passed" echo -e "\e[42m------------" @@ -52,6 +41,6 @@ else echo -e "\e[41m------------" echo -e "\e[91mTests failed" echo -e "\e[41m------------" - echo "Expected: $next, Actual: $new" + echo "Expected: greater than $initial_count, Actual: $new" exit 1 fi From dc9a263ec580e2891bd27e7662ac1a0e31c53335 Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 11:52:17 +0300 Subject: [PATCH 29/36] norah --- e2e/tests/tests.sh | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index 9ad0f0bc..8d057e97 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -1,10 +1,26 @@ -#!/bin/bash +#!/bin/sh # Function to get current vote count get_vote_count() { phantomjs render.js "http://result:80/" | grep -oE '[0-9]+' | head -n 1 } +# ... Later in script ... + +if ! [ -z "$initial_count" ] && ! [ -z "$new" ] && [ "$initial_count" -lt "$new" ]; then + echo -e "\e[42m------------" + echo -e "\e[92mTests passed" + echo -e "\e[42m------------" + exit 0 +else + echo -e "\e[41m------------" + echo -e "\e[91mTests failed" + echo -e "\e[41m------------" + echo "Expected: greater than $initial_count, Actual: $new" + exit 1 +fi + + # Wait for services to be ready echo "Waiting for services to be ready..." while ! timeout 1 bash -c "echo > /dev/tcp/vote/80"; do @@ -19,20 +35,31 @@ echo "Result service is ready." # Get initial vote count initial_count=$(get_vote_count) + echo "Initial vote count: $initial_count" + + # Submit first vote echo "Submitting vote (a)..." curl -sS -X POST --data "vote=a" http://vote sleep 2 +current=$(get_vote_count) +echo "Vote count after first submission: $current" + +# Calculate expected next count +# final=$((initial_count + 1)) +# echo "Expected final count: $final" -# Get new vote count +# Check vote count multiple times +# for i in {1..5}; do + # sleep 2 new=$(get_vote_count) -echo "Vote count after first submission: $new" +# done # Final check echo "Performing final check..." -if ! [ -z "$initial_count" ] && ! [ -z "$new" ] && [ "$initial_count" -lt "$new" ]; then +if [ $initial_count -lt $new ]; then echo -e "\e[42m------------" echo -e "\e[92mTests passed" echo -e "\e[42m------------" @@ -41,6 +68,6 @@ else echo -e "\e[41m------------" echo -e "\e[91mTests failed" echo -e "\e[41m------------" - echo "Expected: greater than $initial_count, Actual: $new" + echo "Expected: $next, Actual: $new" exit 1 fi From e752fc9fef3359ccca98ced0e898ac640b448bfd Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 12:07:12 +0300 Subject: [PATCH 30/36] bash --- e2e/tests/tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index 8d057e97..10783d85 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -2,9 +2,10 @@ # Function to get current vote count get_vote_count() { - phantomjs render.js "http://result:80/" | grep -oE '[0-9]+' | head -n 1 + phantomjs render.js "http://result:80/" | grep -oE '[0-9]+ votes' | grep -oE '[0-9]+' } + # ... Later in script ... if ! [ -z "$initial_count" ] && ! [ -z "$new" ] && [ "$initial_count" -lt "$new" ]; then From 3715217a426ba2f6aaada108879199c457d28d34 Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 12:09:32 +0300 Subject: [PATCH 31/36] norah --- e2e/tests/tests.sh | 42 ++++-------------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index 10783d85..d3c9f48e 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -1,28 +1,9 @@ -#!/bin/sh +#!/bin/bash -# Function to get current vote count get_vote_count() { phantomjs render.js "http://result:80/" | grep -oE '[0-9]+ votes' | grep -oE '[0-9]+' } - -# ... Later in script ... - -if ! [ -z "$initial_count" ] && ! [ -z "$new" ] && [ "$initial_count" -lt "$new" ]; then - echo -e "\e[42m------------" - echo -e "\e[92mTests passed" - echo -e "\e[42m------------" - exit 0 -else - echo -e "\e[41m------------" - echo -e "\e[91mTests failed" - echo -e "\e[41m------------" - echo "Expected: greater than $initial_count, Actual: $new" - exit 1 -fi - - -# Wait for services to be ready echo "Waiting for services to be ready..." while ! timeout 1 bash -c "echo > /dev/tcp/vote/80"; do sleep 1 @@ -34,33 +15,18 @@ while ! timeout 1 bash -c "echo > /dev/tcp/result/80"; do done echo "Result service is ready." -# Get initial vote count initial_count=$(get_vote_count) - echo "Initial vote count: $initial_count" - - -# Submit first vote echo "Submitting vote (a)..." curl -sS -X POST --data "vote=a" http://vote sleep 2 -current=$(get_vote_count) -echo "Vote count after first submission: $current" - -# Calculate expected next count -# final=$((initial_count + 1)) -# echo "Expected final count: $final" -# Check vote count multiple times -# for i in {1..5}; do - # sleep 2 new=$(get_vote_count) -# done +echo "Vote count after first submission: $new" -# Final check echo "Performing final check..." -if [ $initial_count -lt $new ]; then +if ! [ -z "$initial_count" ] && ! [ -z "$new" ] && [ "$initial_count" -lt "$new" ]; then echo -e "\e[42m------------" echo -e "\e[92mTests passed" echo -e "\e[42m------------" @@ -69,6 +35,6 @@ else echo -e "\e[41m------------" echo -e "\e[91mTests failed" echo -e "\e[41m------------" - echo "Expected: $next, Actual: $new" + echo "Expected: greater than $initial_count, Actual: $new" exit 1 fi From b664da2c411414506a0acee57352b597b783412d Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 12:10:19 +0300 Subject: [PATCH 32/36] norah --- e2e/tests/tests.sh | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index d3c9f48e..10783d85 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -1,9 +1,28 @@ -#!/bin/bash +#!/bin/sh +# Function to get current vote count get_vote_count() { phantomjs render.js "http://result:80/" | grep -oE '[0-9]+ votes' | grep -oE '[0-9]+' } + +# ... Later in script ... + +if ! [ -z "$initial_count" ] && ! [ -z "$new" ] && [ "$initial_count" -lt "$new" ]; then + echo -e "\e[42m------------" + echo -e "\e[92mTests passed" + echo -e "\e[42m------------" + exit 0 +else + echo -e "\e[41m------------" + echo -e "\e[91mTests failed" + echo -e "\e[41m------------" + echo "Expected: greater than $initial_count, Actual: $new" + exit 1 +fi + + +# Wait for services to be ready echo "Waiting for services to be ready..." while ! timeout 1 bash -c "echo > /dev/tcp/vote/80"; do sleep 1 @@ -15,18 +34,33 @@ while ! timeout 1 bash -c "echo > /dev/tcp/result/80"; do done echo "Result service is ready." +# Get initial vote count initial_count=$(get_vote_count) + echo "Initial vote count: $initial_count" + + +# Submit first vote echo "Submitting vote (a)..." curl -sS -X POST --data "vote=a" http://vote sleep 2 +current=$(get_vote_count) +echo "Vote count after first submission: $current" + +# Calculate expected next count +# final=$((initial_count + 1)) +# echo "Expected final count: $final" +# Check vote count multiple times +# for i in {1..5}; do + # sleep 2 new=$(get_vote_count) -echo "Vote count after first submission: $new" +# done +# Final check echo "Performing final check..." -if ! [ -z "$initial_count" ] && ! [ -z "$new" ] && [ "$initial_count" -lt "$new" ]; then +if [ $initial_count -lt $new ]; then echo -e "\e[42m------------" echo -e "\e[92mTests passed" echo -e "\e[42m------------" @@ -35,6 +69,6 @@ else echo -e "\e[41m------------" echo -e "\e[91mTests failed" echo -e "\e[41m------------" - echo "Expected: greater than $initial_count, Actual: $new" + echo "Expected: $next, Actual: $new" exit 1 fi From e0d46e8d6dce1e4a9cf34d1573895fc3f5e3aa48 Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 12:10:33 +0300 Subject: [PATCH 33/36] norah --- e2e/tests/tests.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index 10783d85..8d057e97 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -2,10 +2,9 @@ # Function to get current vote count get_vote_count() { - phantomjs render.js "http://result:80/" | grep -oE '[0-9]+ votes' | grep -oE '[0-9]+' + phantomjs render.js "http://result:80/" | grep -oE '[0-9]+' | head -n 1 } - # ... Later in script ... if ! [ -z "$initial_count" ] && ! [ -z "$new" ] && [ "$initial_count" -lt "$new" ]; then From 88dbbe2083bd29cf50fc1261e3b3f73070c2fee4 Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 12:12:49 +0300 Subject: [PATCH 34/36] norah --- e2e/tests/tests.sh | 44 +++++++++++--------------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index 8d057e97..1db0713e 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -1,65 +1,43 @@ -#!/bin/sh +#!/bin/bash # Function to get current vote count get_vote_count() { - phantomjs render.js "http://result:80/" | grep -oE '[0-9]+' | head -n 1 + # Extracts the number of votes like "7 votes" => "7" + phantomjs render.js "http://result:80/" | grep -oE '[0-9]+ votes' | grep -oE '[0-9]+' } -# ... Later in script ... - -if ! [ -z "$initial_count" ] && ! [ -z "$new" ] && [ "$initial_count" -lt "$new" ]; then - echo -e "\e[42m------------" - echo -e "\e[92mTests passed" - echo -e "\e[42m------------" - exit 0 -else - echo -e "\e[41m------------" - echo -e "\e[91mTests failed" - echo -e "\e[41m------------" - echo "Expected: greater than $initial_count, Actual: $new" - exit 1 -fi - - # Wait for services to be ready echo "Waiting for services to be ready..." -while ! timeout 1 bash -c "echo > /dev/tcp/vote/80"; do +while ! timeout 1 bash -c "echo > /dev/tcp/vote/80" 2>/dev/null; do sleep 1 done echo "Vote service is ready." -while ! timeout 1 bash -c "echo > /dev/tcp/result/80"; do +while ! timeout 1 bash -c "echo > /dev/tcp/result/80" 2>/dev/null; do sleep 1 done echo "Result service is ready." # Get initial vote count initial_count=$(get_vote_count) - echo "Initial vote count: $initial_count" - - # Submit first vote echo "Submitting vote (a)..." curl -sS -X POST --data "vote=a" http://vote sleep 2 + +# Get vote count after submission current=$(get_vote_count) echo "Vote count after first submission: $current" -# Calculate expected next count -# final=$((initial_count + 1)) -# echo "Expected final count: $final" - -# Check vote count multiple times -# for i in {1..5}; do - # sleep 2 +# Try again if result is unstable or delayed +sleep 2 new=$(get_vote_count) -# done # Final check echo "Performing final check..." -if [ $initial_count -lt $new ]; then +if ! [ -z "$initial_count" ] && ! [ -z "$new" ] && [ "$initial_count" -lt "$new" ]; then echo -e "\e[42m------------" echo -e "\e[92mTests passed" echo -e "\e[42m------------" @@ -68,6 +46,6 @@ else echo -e "\e[41m------------" echo -e "\e[91mTests failed" echo -e "\e[41m------------" - echo "Expected: $next, Actual: $new" + echo "Expected: greater than $initial_count, Actual: $new" exit 1 fi From eff683fbe92908cd02fde7c0e4aedcc53a6c71f8 Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 12:14:25 +0300 Subject: [PATCH 35/36] final inshalla --- e2e/tests/tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/tests/tests.sh b/e2e/tests/tests.sh index 1db0713e..afc9171e 100755 --- a/e2e/tests/tests.sh +++ b/e2e/tests/tests.sh @@ -24,7 +24,7 @@ echo "Initial vote count: $initial_count" # Submit first vote echo "Submitting vote (a)..." -curl -sS -X POST --data "vote=a" http://vote +curl -sS -X POST --data "vote=a" http://vote > /dev/null sleep 2 # Get vote count after submission From 4325410eac73893278061a1dd1660b7bdaf5fdbd Mon Sep 17 00:00:00 2001 From: norahalr Date: Sun, 27 Jul 2025 12:36:47 +0300 Subject: [PATCH 36/36] ig --- e2e/tests/= | 0 e2e/tests/CACHED | 0 e2e/tests/[e2e] | 0 e2e/tests/exporting | 0 e2e/tests/transferring | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 e2e/tests/= create mode 100644 e2e/tests/CACHED create mode 100644 e2e/tests/[e2e] create mode 100644 e2e/tests/exporting create mode 100644 e2e/tests/transferring diff --git a/e2e/tests/= b/e2e/tests/= new file mode 100644 index 00000000..e69de29b diff --git a/e2e/tests/CACHED b/e2e/tests/CACHED new file mode 100644 index 00000000..e69de29b diff --git a/e2e/tests/[e2e] b/e2e/tests/[e2e] new file mode 100644 index 00000000..e69de29b diff --git a/e2e/tests/exporting b/e2e/tests/exporting new file mode 100644 index 00000000..e69de29b diff --git a/e2e/tests/transferring b/e2e/tests/transferring new file mode 100644 index 00000000..e69de29b