Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
08521df
added Jenkinsfile for worker app to build with maven
initcron Jun 5, 2019
0fe0d08
add when condition for every stage
initcron Jun 5, 2019
3108756
updated changeset criteria from *.* to **
initcron Jun 5, 2019
de8fa7b
provide path to pom.xml
initcron Jun 5, 2019
449ad9d
added jenkinsfile with docker agent
initcron Jun 5, 2019
d683aba
remove changeset when condition
initcron Jun 5, 2019
a135216
- added Jenkinsfile for vote frontend app
initcron Jun 5, 2019
f6cf7a8
testing pwd with worker
initcron Jun 5, 2019
10899cd
testing pwd with worker
initcron Jun 5, 2019
375f2b6
updated Jenkinsfile for vote
initcron Jun 5, 2019
93c022e
run python container as root
initcron Jun 5, 2019
32a7e40
fix pom.xml path after adding dir step
initcron Jun 5, 2019
933e295
adding docker build stage for vote app
initcron Jun 5, 2019
914860f
use stage specific agents, any for docker build
initcron Jun 5, 2019
f204766
fixed syntax
initcron Jun 5, 2019
db2e63b
install python packages again while testing
initcron Jun 5, 2019
6248c18
poll scm trigger runs every 2 mins
initcron Jun 5, 2019
f17c22b
push image
initcron Jun 5, 2019
7f43f63
add docker build and publish step
initcron Jun 5, 2019
ad6f76e
scripted format of docker image build and publish
initcron Jun 5, 2019
2809bca
build and push image with branch name
initcron Jun 5, 2019
18c543d
- added Dockerfile for worker
initcron Jun 5, 2019
056194a
poll every 2mins
initcron Jun 5, 2019
afdde03
added unit tests for results nodejs app
initcron Jun 5, 2019
1298405
added Jenkinsfile for results app
initcron Jun 5, 2019
4473816
adding sonarqube analysis stage
initcron Jun 5, 2019
13b6a99
sonar fix
initcron Jun 5, 2019
eb4fde6
sonar fix
initcron Jun 5, 2019
8fd3010
sonar fix
initcron Jun 5, 2019
72035a2
renamed comnpose file
initcron Jun 5, 2019
985ff00
renamed sut to e2e, fixed results dockerfile path
initcron Jun 5, 2019
27b40c9
docker push images with branch name as tag
initcron Jun 6, 2019
52e087d
adding docker compose env, use images instead of building from src
initcron Jun 6, 2019
2c9bc81
updated name of vote image
initcron Jun 6, 2019
765412b
removed volume for postgres as e2e tests dont need data to persist
initcron Jun 6, 2019
8c0fa92
refactored e2e tests script which works with any stating point
initcron Jun 6, 2019
2cc580f
Merge branch 'e2e' of https://github.com/initcron-devops/example-voti…
initcron Jun 6, 2019
bd38594
conditionally run pipeline stages based on file changes
initcron Jun 6, 2019
c922f33
fix conditinoal for vote Jenkins pipe
initcron Jun 6, 2019
d7e69ef
adding sonarqubre scanners to vote and worker apps, runs only on master
initcron Jun 6, 2019
aa5c617
update image push format from branch-xx to branch-vxx
initcron Jun 6, 2019
cea1878
one more unit test for worker
initcron Jun 6, 2019
b6e9a6e
add break condition
initcron Jun 6, 2019
ca437de
adding integration test for vote app
initcron Jun 7, 2019
9b14bbc
use bash and not sh when running with jenkins
initcron Jun 7, 2019
f21fc4a
created README with build status
initcron Jun 9, 2019
a552fad
fixed build status
initcron Jun 9, 2019
5212ec3
testing badges
initcron Jun 9, 2019
f0457f6
test
initcron Jun 9, 2019
884e861
test
initcron Jun 9, 2019
031d70d
test
initcron Jun 9, 2019
859cc6c
test
initcron Jun 9, 2019
0b4535c
test
initcron Jun 9, 2019
7f83d7b
fix badge
initcron Jun 9, 2019
6b703cc
test
initcron Jun 20, 2019
6869be5
test
initcron Jun 20, 2019
936bc32
test
initcron Jun 20, 2019
de96c69
53wtst
initcron Jun 20, 2019
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Example Voting App
=========

Test 4

Getting started
---------------

Expand Down
3 changes: 3 additions & 0 deletions e2e/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VOTE_IMAGE=initcron/vote:master
WORKER_IMAGE=initcron/worker:master
RESULT_IMAGE=initcron/result:master
12 changes: 6 additions & 6 deletions e2e/docker-compose.test.yml → e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ version: '2'

services:

sut:
e2e:
build: ./tests/
depends_on:
- vote
- result
- worker
- db
- redis
networks:
- front-tier

vote:
build: ../vote/
image: ${VOTE_IMAGE}
ports: ["80"]
depends_on:
- redis
Expand All @@ -22,7 +24,7 @@ services:
- back-tier

result:
build: .
image: ${RESULT_IMAGE}
ports: ["80"]
depends_on:
- redis
Expand All @@ -32,7 +34,7 @@ services:
- back-tier

worker:
build: ../worker/
image: ${WORKER_IMAGE}
depends_on:
- redis
- db
Expand All @@ -47,8 +49,6 @@ services:

db:
image: postgres:9.4
volumes:
- "db-data:/var/lib/postgresql/data"
networks:
- back-tier

Expand Down
22 changes: 20 additions & 2 deletions e2e/tests/tests.sh
Original file line number Diff line number Diff line change
@@ -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 '1 vote'; 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------------"
Expand Down
77 changes: 77 additions & 0 deletions result/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
pipeline {

agent none

triggers { pollSCM('H/2 * * * *') }

stages {
stage('Build') {
when {
changeset "**/result/**"
}
agent {
docker {
image 'node:8.9-alpine'
}
}
steps {
echo 'Building..'
dir('result'){
sh 'npm install'
}
}
}

stage('Test') {
when {
changeset "**/result/**"
}
agent {
docker {
image 'node:8.9-alpine'
}
}
steps {
echo 'Testing..'
dir('result'){
sh 'npm install'
sh 'npm test'
}
}
}

stage('Sonarqube') {
when {
changeset "**/result/**"
branch 'master'
}
agent any
environment{
sonarpath = tool 'SonarScanner'
}
steps {
echo 'Running Sonarqube Analysis..'
withSonarQubeEnv('sonar') {
sh "${sonarpath}/bin/sonar-scanner -Dproject.settings=result/sonar-project.properties"
}
}
}

stage('Package with Docker') {
when {
changeset "**/result/**"
}
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}-v${env.BUILD_ID}", "./result")
customImage.push("${env.BRANCH_NAME}")
customImage.push()
}
}
}
}
}
}
8 changes: 6 additions & 2 deletions result/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
}
29 changes: 29 additions & 0 deletions result/test/mock.test.js
Original file line number Diff line number Diff line change
@@ -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;
});
});


80 changes: 80 additions & 0 deletions vote/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
pipeline {

agent none

triggers { pollSCM('H/2 * * * *') }

stages {

stage('Build') {
when {
changeset "**/vote/**"
}
agent {
docker {
image 'python:2.7-alpine'
args '--user root'
}
}
steps {
echo 'Building..'
dir('vote'){
sh 'pip install -r requirements.txt'
}
}
}

stage('Test') {
when {
changeset "**/vote/**"
}
agent {
docker {
image 'python:2.7-alpine'
args '--user root'
}
}
steps {
echo 'Testing..'
dir('vote'){
sh 'pip install -r requirements.txt'
sh 'nosetests -v'
}
}
}

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/**"
}
agent any
steps {
echo 'Building and Publishing Docker Image'
script {
docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') {
def customImage = docker.build("initcron/vote:${env.BRANCH_NAME}-v${env.BUILD_ID}", "./vote")
customImage.push("${env.BRANCH_NAME}")
customImage.push()
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions vote/integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine:3.9.4
WORKDIR /test
COPY . .
RUN apk add curl
CMD sh
26 changes: 26 additions & 0 deletions vote/integration/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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:

36 changes: 36 additions & 0 deletions vote/integration/test.sh
Original file line number Diff line number Diff line change
@@ -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


Loading