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/result/Jenkinsfile b/result/Jenkinsfile new file mode 100644 index 00000000..a067a084 --- /dev/null +++ b/result/Jenkinsfile @@ -0,0 +1,36 @@ +pipeline { + agent any + + tools { + nodejs 'NodeJS 22.4.0' + } + + stages { + stage("build") { + when { + changeset "**/result/**" + } + steps { + echo 'Compiling result app..' + // 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 + } + } + } + + stage("test") { + when { + changeset "**/result/**" + } + steps { + echo 'Running Unit Tests on result app..' + dir('result') { + sh 'npm install' // Install dependencies in the 'result' directory + sh 'npm test' // Run tests in the 'result' directory + } + } + } + } +} + diff --git a/result/test/mock.test.js b/result/test/mock.test.js index aac87156..8b11b370 100644 --- a/result/test/mock.test.js +++ b/result/test/mock.test.js @@ -38,3 +38,8 @@ describe('mock test 6', () => { }); }); +describe('mock test 7', () => { + it('unit test 7', () => { + expect(true).to.be.true; + }); +}); 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"] + 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 && \ diff --git a/worker/Jenkinsfile b/worker/Jenkinsfile index b66016b2..35858d04 100644 --- a/worker/Jenkinsfile +++ b/worker/Jenkinsfile @@ -1,41 +1,90 @@ -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 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("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..' } } } +