-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·112 lines (98 loc) · 3.15 KB
/
deploy.sh
File metadata and controls
executable file
·112 lines (98 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
## Load environment variables and deploy to the docker swarm.
##
## Usages:
## ./deploy-swarm prepare
##
set -eo pipefail
. ./scripts/deploy-stack.sh
load_env
DOCKER_STACKS=("basic-services" "cardano" "govaction-loader" "govtool" "test")
if [ "$1" == "destroy" ]
then
echo "This will remove everything in your stack except volumes, configs and secrets"
echo "Are you Sure? (Y/N)"
read user_input
if ! ( [ "$user_input" = "y" ] || [ "$user_input" = "Y" ])
then
exit 1
fi
echo "Proceeding..." # Delete the Docker stack if "destroy" argument is provided
REVERSE_STACKS=()
for ((i=${#STACKS[@]}-1; i>=0; i--)); do
REVERSE_STACKS+=("${STACKS[i]}")
done
for CUR_STACK in "${REVERSE_STACKS[@]}"; do
docker stack rm "$CUR_STACK"
sleep 6 # wait 6 seconds for each stack cleanup.
done
# ./gen-configs.sh clean
# for VOLUME in $(docker volume ls --filter "label=com.docker.stack.namespace=${STACK_NAME}" -q) "${STACK_NAME}-services_postgres"
# do
# echo -n "Removing Volume : "
# docker volume rm "$VOLUME"
# done
elif [ "$1" == 'prepare' ]
then
# Get the number of nodes in the swarm
NODES=$(docker node ls --format "{{.ID}}" | wc -l)
# If there is only one node, set the labels
if [ "$NODES" -eq 1 ]; then
NODE_ID=$(docker node ls --format "{{.ID}}")
docker node update --label-add govtool-test-stack=true \
--label-add blockchain=true \
--label-add gateway=true \
--label-add govtool=true \
--label-add gov-action-loader=true \
"$NODE_ID"
echo "Labels set on node: $NODE_ID"
else
echo "There are multiple nodes in the docker swarm."
echo "Please set the following labels to correct nodes manually."
echo " - govtool-test-stack "
echo " - blockchain"
echo " - gateway"
echo " - govtool"
echo " - gov-action-loader"
echo ""
echo " e.g. $ docker node update xxxx --label-add gateway=true"
exit 1
fi
elif [ "$1" == 'stack' ]
then
if [ "$#" -ne 2 ]
then
echo "stack requires the stack name".
echo "Usage :"
echo " > $0 stack [stack-name]".
echo ""
echo " stack-name : One of the following"ß
echo " $DOCKER_STACKS"
else
case "$2" in
all)
for DEPLOY_STACK in "${DOCKER_STACKS[@]}"; do
deploy-stack "$DEPLOY_STACK" "docker-compose-$DEPLOY_STACK.yml"
done
;;
*)
if [[ ! -f ./"docker-compose-$2.yml" ]]
then
echo "Invalid stack name. $2"
else
deploy-stack $2 "docker-compose-$2.yml"
fi
;;
esac
fi
else
echo "Something is wrong with the command"
echo
echo " Usage:"
echo " $0 (prepare | destroy | deploy)"
echo ''
echo " Options:"
echo " prepare -> set required labels to docker swarm node."
echo " destroy -> teardown everything except the volumes"
echo " deploy [stack_name] -> Deploy the stack."
fi