Skip to content

Commit

Permalink
Initial Project Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
henderstack committed May 7, 2018
0 parents commit 41cae61
Show file tree
Hide file tree
Showing 171 changed files with 52,339 additions and 0 deletions.
Empty file added README.md
Empty file.
43 changes: 43 additions & 0 deletions _docker_setup/create-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

eval `docker-machine env manager1`

array=('./flicks-service'
'./cinema-catalog-service'
'./booking-service'
'./payment-service'
'./notification-service'
)

# we go to the root of the project
cd ..

for ((i = 0; i < ${#array[@]}; ++i)); do
# we go to each folder
cd ${array[$i]}

# we get the name of our image
SERVICE=$(echo ${array[$i]} | cut -d'/' -f 2)

# we delete the image if it exists already
docker rmi bryan_henderson/$SERVICE

# we create or recreate our image
sh ./create-image.sh

# we get the image id so we can tag it
IMAGE_ID=$(docker images -q $SERVICE)

# we tag our image so we can publish it to our docker hub account
docker tag $IMAGE_ID bryan_henderson/$SERVICE:latest

# we publish our image to our docker hub account
docker push bryan_henderson/$SERVICE:latest

# we delete our local image because we are not going to need it
# and mantain clean our environment
docker rmi $SERVICE

# and we go back to the root again :D
cd ..
done
16 changes: 16 additions & 0 deletions _docker_setup/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

eval `docker-machine env manager1`

docker service rm flicks-service notification-service cinema-catalog-service payment-service booking-service

for server in manager1 worker1 worker2
do
eval `docker-machine env $server`

for image in bryan_henderson/flicks-service bryan_henderson/cinema-catalog-service bryan_henderson/booking-service bryan_henderson/payment-service bryan_henderson/notification-service
do
IMAGE=$(docker images $image -q)
docker rmi -f $IMAGE
done
done
134 changes: 134 additions & 0 deletions _docker_setup/setup-swarm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/bin/bash

# default parameters
DRIVER="virtualbox"
MANAGERS=1
WORKERS=2
DISK_SIZE="20000"
MEMORY="2048"
DOCKER_VERSION="https://github.com/boot2docker/boot2docker/releases/download/v1.13.0/boot2docker.iso"
ADDITIONAL_PARAMS=

function usage {
echo "Usage: bash $0 [OPTIONS]
Run a command in a new container
Options:
-d, --driver virtual machine provider or cloud provider (default virtualbox)
-m, --manager number of managers to create (default 1)
-w, --worker number of workers to create (default 2)
-v, --version boot2docker github url (default version 1.13.0)
-ds, --disksize hard disk size for docker-machine (default 20GB)
-r, --memory memory ram size for docker-machine (default 2GB)"
exit 1
}

# get parameters
while [ "$#" -gt 0 ]; do
case "$1" in
--driver|-d)
DRIVER="$2"
shift 2
;;
--manager|-m)
MANAGERS="$2"
shift 2
;;
--worker|-w)
WORKERS="$2"
shift 2
;;
--version|-v)
DOCKER_VERSION="$2"
shift 2
;;
--disksize|-ds)
DISK_SIZE="$2"
shift 2
;;
--memory|-r)
MEMORY="$2"
shift 2
;;
-h|--help)
usage
;;
esac
done

if [ "$DRIVER" == "virtualbox" ]; then
echo "-> about to create a swarm with $MANAGERS manager(s) and $WORKERS WORKERS on $DRIVER machines"
ADDITIONAL_PARAMS="--virtualbox-disk-size ${DISK_SIZE} --virtualbox-memory ${MEMORY} --virtualbox-boot2docker-url=${DOCKER_VERSION}"
fi

function getIP {
echo $(docker-machine ip $1)
}

function get_worker_token {
echo $(docker-machine ssh manager1 docker swarm join-token worker -q)
}

function createManagerNode {
# create manager machines
for i in $(seq 1 $MANAGERS);
do
echo "== Creating manager$i machine ...";
docker-machine create -d $DRIVER $ADDITIONAL_PARAMS manager$i
done
}

function createWorkerNode {
# create worker machines
for i in $(seq 1 $WORKERS);
do
echo "== Creating worker$i machine ...";
docker-machine create -d $DRIVER $ADDITIONAL_PARAMS worker$i
done
}

function initSwarmManager {
# initialize swarm mode and create a manager
echo '============================================'
echo "======> Initializing first swarm manager ..."
docker-machine ssh manager1 docker swarm init --advertise-addr $(getIP manager1)
}

function join_node_swarm {
# WORKERS join swarm
for node in $(seq 1 $WORKERS);
do
echo "======> worker$node joining swarm as worker ..."
docker-machine ssh worker$node docker swarm join --token $(get_worker_token) $(getIP manager1):2377
done
}

# Display status
function status {
echo "-> list swarm nodes"
docker-machine ssh manager1 docker node ls
echo
echo "-> list machines"
docker-machine ls
}

# Start RancherOS
function startRancherOS {
echo "-> Starting RancherOS to monitor the cluster"
docker-machine ssh manager1 docker run --name rancher --restart=unless-stopped -p 9000:8080 -d rancher/server
}

function main {
createManagerNode
createWorkerNode
initSwarmManager
join_node_swarm
status
startRancherOS
}

function reset {
docker-machine rm manager1 worker1 worker2 -y
}

reset
main
25 changes: 25 additions & 0 deletions _docker_setup/start-services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

eval `docker-machine env manager1`

array=('./flicks-service'
'./cinema-catalog-service'
'./booking-service'
'./payment-service'
'./notification-service'
'./api-gateway'
)

# we go to the root of the project
cd ..

for ((i = 0; i < ${#array[@]}; ++i)); do
# we go to each folder
cd ${array[$i]}

# we create or recreate our image
sh ./start-service.sh

# and we go back to the root again :D
cd ..
done
3 changes: 3 additions & 0 deletions api-gateway/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["standard"]
}
1 change: 1 addition & 0 deletions api-gateway/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
17 changes: 17 additions & 0 deletions api-gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:8.11.1-alpine

ENV HOME=/home/nupp

COPY package.json npm-shrinkwrap.json $HOME/app/

COPY src/ $HOME/app/src

ADD https://github.com/Yelp/dumb-init/releases/download/v1.1.1/dumb-init_1.1.1_amd64 /usr/local/bin/dumb-init

WORKDIR $HOME/app

RUN chmod +x /usr/local/bin/dumb-init && \
npm cache clean && \
npm install --silent --progress=false --production

CMD ["dumb-init", "npm", "start"]
9 changes: 9 additions & 0 deletions api-gateway/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DB=booking
DB_USER=bryan_henderson
DB_PASS=bryansPword1975
DB_REPLS=rs1
DB_SERVERS='192.168.99.100:27017 192.168.99.101:27017 192.168.99.102:27017'
PORT=8080
DOCKER_HOST=tcp://192.168.99.100:2376
DOCKER_TLS_VERIFY=1
DOCKER_CERT_PATH=/certs
118 changes: 118 additions & 0 deletions api-gateway/integration-test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/* eslint-env mocha */
const supertest = require('supertest')
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
process.env.NODE_TLS_ACCEPT_UNTRUSTED_CERTIFICATES_THIS_IS_INSECURE = '1'

describe('API Gateway Service', () => {
it('returns a 200 for known flicks through api-gateway', (done) => {
const url = 'https://192.168.99.100:8080'
const api = supertest(url)
console.log(`Calling the server ${url}`)

api.get('/flicks/premieres')
.expect(200, done)
})

it('returns schedules for a flick through api-gateway', (done) => {
const url = 'https://192.168.99.101:8080'
const api = supertest(url)
console.log(`Calling the server ${url}`)

api.get('/flicks/588ababf2d029a6d15d0b5bf/1')
.expect(200, done)
})

it('can make a booking through api-gateway', function (done) {
this.timeout(5000)
const url = 'https://192.168.99.102:8080'
const api = supertest(url)
console.log(`Calling the server ${url}`)

const now = new Date()
now.setDate(now.getDate() + 1)
const user = {
name: 'Bryan',
lastName: 'Henderson',
email: '[email protected]',
creditCard: {
number: '4601565656565656',
cvc: '123',
exp_month: '12',
exp_year: '2022'
},
membership: '7777888899990000'
}

const booking = {
city: 'Mayberry',
cinema: 'Junction Theaters Megaplex 24',
movie: {
title: 'Doctor Zhivago',
format: 'IMAX'
},
schedule: now.toString(),
cinemaRoom: 7,
seats: ['121'],
totalAmount: 71
}

api.post('/booking')
.send({user, booking})
.expect(200, done)
})

it('can make a paymentOrder through api-gateway', function (done) {
this.timeout(3000)
const url = 'https://192.168.99.100:8080'
const api = supertest(url)
console.log(`Calling the server ${url}`)

const testPayment = {
userName: 'Bryan Henderson',
currency: 'usd',
number: '4242424242424242',
cvc: '123',
exp_month: '12',
exp_year: '2022',
amount: 71,
description: `
Tickect(s) for movie "Doctor Zhivago",
with seat(s) 121, 122
at time 8 / jun / 18`
}
api.post('/payment/makePurchase')
.send({paymentOrder: testPayment})
.expect(200, done)
})

it('can send a notification through api-gateway', function (done) {
this.timeout(3000)
const url = 'https://192.168.99.101:8080'
const api = supertest(url)
console.log(`Calling the server ${url}`)
const payload = {
city: 'Freeport',
userType: 'loyal',
totalAmount: 71,
cinema: {
name: 'Junction Theaters Megaplex 24',
room: '1',
seats: '121, 122'
},
movie: {
title: 'Doctor Zhivago',
format: 'IMAX',
schedule: new Date()
},
orderId: '1aa90cx',
description: 'some description',
user: {
name: 'Bryan Henderson',
email: '[email protected]'
}
}
api.post('/notification/sendEmail')
.send({payload})
.expect(200, done)
})
})
Loading

0 comments on commit 41cae61

Please sign in to comment.