Skip to content

Commit

Permalink
added docker swarm
Browse files Browse the repository at this point in the history
  • Loading branch information
steveww committed Mar 9, 2018
1 parent 7cfc66d commit 292900d
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Swarm/create-swarm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh


if [ -z "$1" ]
then
echo "Usage: create-machines.sh [local|aws]"
exit 1
fi

case $1 in
local)
DRIVER=virtualbox
;;
aws)
DRIVER=amazonec2
;;
*)
echo "Unknown option"
exit 1
esac

for MACHINE in master worker-1 worker-2
do
echo "Creating $MACHINE"
if [ "$DRIVER" = "aws" ]
then
docker-machine create \
--driver $DRIVER \
--amazonec2-instance-type "t2.medium" \
$MACHINE
else
docker-machine create \
--driver $DRIVER \
$MACHINE
fi
done

sleep 3
echo " "
echo "Machines created"
echo "Configuring Swarm"

MASTER_IP=$(docker-machine ip master)

# create the swarm master
# connect local docker command to master machine
echo "Creating master"
eval $(docker-machine env master)
JOIN_CMD=$(docker swarm init --advertise-addr "$MASTER_IP" | awk '/^[ \t]+/{print $0}' -)

for MACHINE in $(docker-machine ls -q | fgrep worker)
do
echo "joining from $MACHINE"
eval $(docker-machine env $MACHINE)
$JOIN_CMD
done

echo " "
echo "Swarm is ready"

26 changes: 26 additions & 0 deletions Swarm/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

# set -x

# Read in vars from .env file

for VAR in $(egrep '^[A-Z]+=' ../.env)
do
export $VAR
done

# Connect to master
eval $(docker-machine env master)

docker stack deploy robot-shop -c ../docker-compose.yaml

sleep 3
echo " "
echo "Robot Shop deployed"
docker service ls

echo " "
IP=$(docker-machine ip master)
echo "Go to the shop http://${IP}:8080/ when all the services have started"
echo "This may take a while..."

31 changes: 31 additions & 0 deletions Swarm/instana-agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

# Config here
KEY="your unique key"
ENDPOINT="endpoint for your tennant"
# end of config

for MACHINE in $(docker-machine ls -q)
do
echo "starting agent on $MACHINE"
eval $(docker-machine env $MACHINE)
docker run \
-d \
--rm \
--name instana-agent \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /dev:/dev \
--volume /sys:/sys \
--volume /var/log:/var/log \
--privileged \
--net=host \
--pid=host \
--ipc=host \
--env="INSTANA_AGENT_KEY=$KEY" \
--env="INSTANA_AGENT_ENDPOINT=$ENDPOINT" \
--env="INSTANA_AGENT_ENDPOINT_PORT=443" \
--env="INSTANA_AGENT_ZONE=Stans-Robot-Shop" \
--env="INSTANA_AGENT_HTTP_LISTEN=*" \
instana/agent
done

44 changes: 44 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,31 @@ services:
- "27017"
networks:
- robot-shop
deploy:
replicas: 1
restart_policy:
condition: on-failure
redis:
image: redis:4.0.6
ports:
- "6379"
networks:
- robot-shop
deploy:
replicas: 1
restart_policy:
condition: on-failure
rabbitmq:
image: rabbitmq:3.7-management-alpine
ports:
- "5672"
- "15672"
networks:
- robot-shop
deploy:
replicas: 1
restart_policy:
condition: on-failure
catalogue:
build:
context: catalogue
Expand All @@ -31,6 +43,10 @@ services:
- "8080"
networks:
- robot-shop
deploy:
replicas: 1
restart_policy:
condition: on-failure
user:
build:
context: user
Expand All @@ -42,6 +58,10 @@ services:
- "8080"
networks:
- robot-shop
deploy:
replicas: 1
restart_policy:
condition: on-failure
cart:
build:
context: cart
Expand All @@ -52,6 +72,10 @@ services:
- "8080"
networks:
- robot-shop
deploy:
replicas: 1
restart_policy:
condition: on-failure
mysql:
build:
context: shipping/database
Expand All @@ -60,6 +84,10 @@ services:
- "3306"
networks:
- robot-shop
deploy:
replicas: 1
restart_policy:
condition: on-failure
shipping:
build:
context: shipping/service
Expand All @@ -70,6 +98,10 @@ services:
- "8080"
networks:
- robot-shop
deploy:
replicas: 1
restart_policy:
condition: on-failure
payment:
build:
context: payment
Expand All @@ -82,6 +114,10 @@ services:
- "8080"
networks:
- robot-shop
deploy:
replicas: 1
restart_policy:
condition: on-failure
dispatch:
build:
context: dispatch
Expand All @@ -90,6 +126,10 @@ services:
- rabbitmq
networks:
- robot-shop
deploy:
replicas: 1
restart_policy:
condition: on-failure
web:
build:
context: web
Expand All @@ -103,6 +143,10 @@ services:
- "8080:8080"
networks:
- robot-shop
deploy:
replicas: 1
restart_policy:
condition: on-failure
# Uncomment to enable Instana EUM
# environment:
# INSTANA_EUM_KEY: <your eum key here>
Expand Down

0 comments on commit 292900d

Please sign in to comment.