From 292900dc428c3d84f02b320227196f974894e377 Mon Sep 17 00:00:00 2001 From: Steve Waterworth Date: Fri, 9 Mar 2018 14:54:55 +0000 Subject: [PATCH] added docker swarm --- Swarm/create-swarm.sh | 60 ++++++++++++++++++++++++++++++++++++++++++ Swarm/deploy.sh | 26 ++++++++++++++++++ Swarm/instana-agent.sh | 31 ++++++++++++++++++++++ docker-compose.yaml | 44 +++++++++++++++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100755 Swarm/create-swarm.sh create mode 100755 Swarm/deploy.sh create mode 100755 Swarm/instana-agent.sh diff --git a/Swarm/create-swarm.sh b/Swarm/create-swarm.sh new file mode 100755 index 0000000..f089744 --- /dev/null +++ b/Swarm/create-swarm.sh @@ -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" + diff --git a/Swarm/deploy.sh b/Swarm/deploy.sh new file mode 100755 index 0000000..1640dfa --- /dev/null +++ b/Swarm/deploy.sh @@ -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..." + diff --git a/Swarm/instana-agent.sh b/Swarm/instana-agent.sh new file mode 100755 index 0000000..524c1ce --- /dev/null +++ b/Swarm/instana-agent.sh @@ -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 + diff --git a/docker-compose.yaml b/docker-compose.yaml index 9e59541..321ec04 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,12 +8,20 @@ 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: @@ -21,6 +29,10 @@ services: - "15672" networks: - robot-shop + deploy: + replicas: 1 + restart_policy: + condition: on-failure catalogue: build: context: catalogue @@ -31,6 +43,10 @@ services: - "8080" networks: - robot-shop + deploy: + replicas: 1 + restart_policy: + condition: on-failure user: build: context: user @@ -42,6 +58,10 @@ services: - "8080" networks: - robot-shop + deploy: + replicas: 1 + restart_policy: + condition: on-failure cart: build: context: cart @@ -52,6 +72,10 @@ services: - "8080" networks: - robot-shop + deploy: + replicas: 1 + restart_policy: + condition: on-failure mysql: build: context: shipping/database @@ -60,6 +84,10 @@ services: - "3306" networks: - robot-shop + deploy: + replicas: 1 + restart_policy: + condition: on-failure shipping: build: context: shipping/service @@ -70,6 +98,10 @@ services: - "8080" networks: - robot-shop + deploy: + replicas: 1 + restart_policy: + condition: on-failure payment: build: context: payment @@ -82,6 +114,10 @@ services: - "8080" networks: - robot-shop + deploy: + replicas: 1 + restart_policy: + condition: on-failure dispatch: build: context: dispatch @@ -90,6 +126,10 @@ services: - rabbitmq networks: - robot-shop + deploy: + replicas: 1 + restart_policy: + condition: on-failure web: build: context: web @@ -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: