From 12e70380184d3cd9cc68f315de2d3e130c60b62f Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Fri, 13 Dec 2024 13:24:47 +0100 Subject: [PATCH 01/12] added Jenkinsfile for worker with build job --- worker/Jenkinsfile | 69 +++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index b66016b2..2a785855 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -1,41 +1,34 @@ -pipeline { - 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' - } - } - } - stage('test'){ - steps{ - echo 'running unit tests on worker app' - dir('worker'){ - sh 'mvn clean test' - } - } - } - stage('package'){ - steps{ - echo 'packaging worker app into a jarfile' - dir('worker'){ - sh 'mvn package -DskipTests' - archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true - } - } - } - } - post{ - always{ - echo 'the job is complete' +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 55805a509fd3a49c6cdd5f8beaf7dffc58e3ac46 Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Fri, 13 Dec 2024 15:04:25 +0100 Subject: [PATCH 02/12] added Test and package job for worker pipeline --- worker/Jenkinsfile | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 2a785855..b4a295af 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -1,33 +1,39 @@ pipeline { agent any - tools{ + tools { maven 'maven 3.9.8' } - - stages{ - stage("build"){ - steps{ - echo 'Compiling worker app' - dir('worker'){ + + stages { + stage("build") { + steps { + echo 'Compiling worker app..' + dir('worker') { sh 'mvn compile' } } } - stage("test"){ - steps{ - echo 'Running Unit Tests on worker app' + stage("test") { + steps { + echo 'Running Unit Tests on worker app..' + dir('worker') { + sh 'mvn clean test' + } } } - stage("package"){ - steps{ + stage("package") { + steps { echo 'Packaging worker app' + dir('worker') { + sh 'mvn package' + } } } } - - post{ - always{ + + post { + always { echo 'Building multibranch pipeline for worker is completed..' } } From 53effcabb64d8d3ea8064ebc465126a8f83b5b66 Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Fri, 13 Dec 2024 15:24:35 +0100 Subject: [PATCH 03/12] archive artifacts, skip test and package --- worker/Jenkinsfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index b4a295af..3f5c7452 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -14,6 +14,7 @@ pipeline { } } } + stage("test") { steps { echo 'Running Unit Tests on worker app..' @@ -22,11 +23,12 @@ pipeline { } } } + stage("package") { steps { echo 'Packaging worker app' dir('worker') { - sh 'mvn package' + sh 'mvn package -DskipTests' } } } @@ -34,7 +36,9 @@ pipeline { post { always { + archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true echo 'Building multibranch pipeline for worker is completed..' } } } + From ae12c1bc40fa3ecc99cb9a0466131d314a17acfd Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Mon, 16 Dec 2024 10:29:22 +0100 Subject: [PATCH 04/12] adding Jenkinsfile for result app --- result/Jenkinsfile | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 result/Jenkinsfile diff --git a/result/Jenkinsfile b/result/Jenkinsfile new file mode 100644 index 00000000..46e2c803 --- /dev/null +++ b/result/Jenkinsfile @@ -0,0 +1,35 @@ +pipeline { + agent any + + tools { + nodejs 'NodeJS 22.4.0' + } + + stages { + stage("build") { + when { + changeset "**/result/**" + } + steps { + echo 'Compiling result app..' + dir('worker') { + sh 'npm install' + } + } + } + + stage("test") { + when { + changeset "**/result/**" + } + steps { + echo 'Running Unit Tests on result app..' + dir('result') { + sh 'npm install' + sh 'npm test' + } + } + } + } +} + From b7e598731dff833e11d1b64afff483ecc2942377 Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Mon, 16 Dec 2024 11:23:08 +0100 Subject: [PATCH 05/12] adding mock test --- result/test/mock.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/result/test/mock.test.js b/result/test/mock.test.js index aac87156..3983f9f0 100644 --- a/result/test/mock.test.js +++ b/result/test/mock.test.js @@ -1,4 +1,4 @@ -const expect = require('chai').expect; +oconst expect = require('chai').expect; describe('mock test 1', () => { it('unit test 1', () => { @@ -38,3 +38,8 @@ describe('mock test 6', () => { }); }); +describe('mock test 7', () => { + it('unit test 7', () => { + expect(true).to.be.true; + }); +}); From 704e9fccb05d9935497bd17c561890183d89cf9a Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Mon, 16 Dec 2024 11:39:23 +0100 Subject: [PATCH 06/12] attemped fix --- result/Jenkinsfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/result/Jenkinsfile b/result/Jenkinsfile index 46e2c803..a067a084 100644 --- a/result/Jenkinsfile +++ b/result/Jenkinsfile @@ -12,8 +12,9 @@ pipeline { } steps { echo 'Compiling result app..' - dir('worker') { - sh 'npm install' + // Remove 'dir('worker')' if you are not using the worker package anymore. + dir('result') { + sh 'npm install' // Now this will run inside the 'result' directory } } } @@ -25,8 +26,8 @@ pipeline { steps { echo 'Running Unit Tests on result app..' dir('result') { - sh 'npm install' - sh 'npm test' + sh 'npm install' // Install dependencies in the 'result' directory + sh 'npm test' // Run tests in the 'result' directory } } } From 1495dc3d35a934166b9c31d97ccc06376860488c Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Mon, 16 Dec 2024 11:44:22 +0100 Subject: [PATCH 07/12] attemped fix - typo --- result/test/mock.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/result/test/mock.test.js b/result/test/mock.test.js index 3983f9f0..8b11b370 100644 --- a/result/test/mock.test.js +++ b/result/test/mock.test.js @@ -1,4 +1,4 @@ -oconst expect = require('chai').expect; +const expect = require('chai').expect; describe('mock test 1', () => { it('unit test 1', () => { From 7458a4637f2fb827865fc34c28d0caa7c439972d Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Mon, 16 Dec 2024 14:05:36 +0100 Subject: [PATCH 08/12] add docker based agent --- worker/Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index b66016b2..c35e5aa4 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -28,6 +28,8 @@ pipeline { dir('worker'){ sh 'mvn package -DskipTests' archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true + + } } } From c94c27b122206e8f5ddd535270a1c1cdb7d28e7b Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Tue, 17 Dec 2024 09:30:00 +0100 Subject: [PATCH 09/12] adding Dockerfile for worker --- worker/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/worker/Dockerfile b/worker/Dockerfile index 2b152eab..4657b3c3 100644 --- a/worker/Dockerfile +++ b/worker/Dockerfile @@ -1,4 +1,5 @@ FROM maven:3.9.8-sapmachine-21 + WORKDIR /app COPY . . RUN mvn package && \ From 99b14cb7924086a4e88436b7bfefbcb741a74257 Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Tue, 17 Dec 2024 09:47:59 +0100 Subject: [PATCH 10/12] Jenkinsfile update --- worker/Jenkinsfile | 88 ++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index b66016b2..0a3d8803 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -1,41 +1,53 @@ -pipeline { - 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' - } - } - } - stage('test'){ - steps{ - echo 'running unit tests on worker app' - dir('worker'){ - sh 'mvn clean test' - } - } - } - stage('package'){ - steps{ - echo 'packaging worker app into a jarfile' - dir('worker'){ - sh 'mvn package -DskipTests' - archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true - } - } - } +pipeline { + agent { + docker { + image 'maven:3.9.8-sapmachine-21' + args '-v $HOME/.m2:/root/.m2' + } } - post{ - always{ - echo 'the job is complete' - + stages { + stage('build') { + steps { + echo 'Building worker app' + dir('worker') { + sh 'mvn compile' + } + } + } + stage('test') { + steps { + echo 'Running unit tests on worker app' + dir('worker') { + sh 'mvn clean test' + } + } + } + stage('package') { + steps { + echo 'Packaging worker app into a 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("xmarkus/worker:v${env.BUILD_ID}", "./worker") + workerImage.push() + workerImage.push("latest") + } + } + } + } + } + post { + always { + echo 'The job is complete' + } } - } } From 425ced41a8ef3d61067a1de308f7640f3ca06a4a Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Tue, 17 Dec 2024 09:58:39 +0100 Subject: [PATCH 11/12] Jenkinsfile update 2nd --- worker/Jenkinsfile | 120 +++++++++++++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 42 deletions(-) diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index 0a3d8803..5f01e3a5 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -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("xmarkus/worker:v${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("xmarkus/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..' } + } } From 059a73c636b7791513752e2c69db069de546a5d8 Mon Sep 17 00:00:00 2001 From: kusnir18 Date: Tue, 17 Dec 2024 10:23:05 +0100 Subject: [PATCH 12/12] more changes --- result/Dockerfile | 20 ++++++++++++++++---- vote/Dockerfile | 23 ++++++++++++----------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/result/Dockerfile b/result/Dockerfile index 4fb74e8c..0dc31b94 100644 --- a/result/Dockerfile +++ b/result/Dockerfile @@ -1,25 +1,37 @@ +# Base image FROM node:18-slim -# add curl for healthcheck +# Add curl and tini for health check and process management RUN apt-get update && \ apt-get install -y --no-install-recommends curl tini && \ rm -rf /var/lib/apt/lists/* +# Set the working directory WORKDIR /usr/local/app -# have nodemon available for local dev use (file watching) +# Install nodemon globally for development use (file watching) RUN npm install -g nodemon +# Copy package.json and package-lock.json COPY package*.json ./ +# Install dependencies and clean up cache RUN npm ci && \ - npm cache clean --force && \ - mv /usr/local/app/node_modules /node_modules + npm cache clean --force && \ + mv /usr/local/app/node_modules /node_modules +# Copy application source code COPY . . +# Set environment variables ENV PORT 80 + +# Expose port 80 EXPOSE 80 +# Use tini as the init system ENTRYPOINT ["/usr/bin/tini", "--"] + +# Command to run the application CMD ["node", "server.js"] + diff --git a/vote/Dockerfile b/vote/Dockerfile index 9e812ca9..8a4dea98 100644 --- a/vote/Dockerfile +++ b/vote/Dockerfile @@ -1,33 +1,34 @@ -# Define a base stage that uses the official python runtime base image +# Base stage using the official Python runtime base image FROM python:3.11-slim AS base -# Add curl for healthcheck +# Add curl for health checks RUN apt-get update && \ apt-get install -y --no-install-recommends curl && \ rm -rf /var/lib/apt/lists/* -# Set the application directory +# Set the working directory WORKDIR /usr/local/app -# Install our requirements.txt +# Install dependencies from requirements.txt COPY requirements.txt ./requirements.txt RUN pip install --no-cache-dir -r requirements.txt -# Define a stage specifically for development, where it'll watch for -# filesystem changes +# Development stage with tools for live file watching FROM base AS dev RUN pip install watchdog ENV FLASK_ENV=development CMD ["python", "app.py"] -# Define the final stage that will bundle the application for production +# Production stage optimized for deployment FROM base AS final -# Copy our code from the current folder to the working directory inside the container +# Copy application code to the container COPY . . -# Make port 80 available for links and/or publish +# Expose port 80 for the application 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"] +# Define the command to run the application in production +CMD ["gunicorn", "app:app", "-b", "0.0.0.0:80", "--log-file", "-", \ + "--access-logfile", "-", "--workers", "4", "--keep-alive", "0"] +