Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 272 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
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("norahns/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("norahns/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
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")
voteImage.push()
voteImage.push(sanitizedBranch) // Now uses "feature-monopipe" instead
}
}

}
}

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 {
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.'
}
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2 TRY

Example Voting App
=========

Expand Down
55 changes: 55 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
volumes:
db-data:

networks:
instavote:
driver: bridge

services:
vote:
image: norahns/vote:latest
build: ./vote
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
build: ./result
ports:
- 5001:80
depends_on:
- db
networks:
- instavote

worker:
image: norahns/worker:latest
build: ./worker
depends_on:
- redis
- db
networks:
- instavote
26 changes: 26 additions & 0 deletions result/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:22.4.0-slim

# 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

# 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
EXPOSE 80

ENTRYPOINT ["/usr/bin/tini", "--"]

CMD ["node", "server.js"]
Loading