forked from OpenMined/PyDentity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage
executable file
·307 lines (251 loc) · 8.02 KB
/
manage
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/bash
export MSYS_NO_PATHCONV=1
export DOCKERHOST=${APPLICATION_URL-$(docker run --rm --net=host codenvy/che-ip)}
set -e
S2I_EXE=s2i
if [ -z $(type -P "$S2I_EXE") ]; then
echo -e "The ${S2I_EXE} executable is needed and not on your path."
echo -e "It can be downloaded from here: https://github.com/openshift/source-to-image/releases"
echo -e "Make sure you extract the binary and place it in a directory on your path."
exit 1
fi
SCRIPT_HOME="$(cd "$(dirname "$0")" && pwd)"
# =================================================================================================================
# Usage:
# -----------------------------------------------------------------------------------------------------------------
usage() {
cat <<-EOF
Usage: $0 [command] [options]
Commands:
up - Builds the images, creates the application containers
and starts the services based on the docker-compose.yml file.
You can pass in a list of containers to start.
By default all containers will be started.
The API_URL used by tob-web can also be redirected.
Examples:
$0 start
$0 start EXTERNAL-agent
start - Same as up
restart - Re-starts the application containers,
useful when updating one of the container images during development.
You can pass in a list of containers to be restarted.
By default all containers will be restarted.
Examples:
$0 start
$0 start faber-agent
logs - Display the logs from the docker compose run (ctrl-c to exit).
stop - Stops the services. This is a non-destructive process. The volumes and containers
are not deleted so they will be reused the next time you run start.
down - Brings down the services and removes the volumes (storage) and containers.
rm - Same as down
EOF
exit 1
}
# -----------------------------------------------------------------------------------------------------------------
# Default Settings:
# -----------------------------------------------------------------------------------------------------------------
DEFAULT_CONTAINERS="ngrok-external external-agent ngrok-multitenant multitenant-agent multitenant-notebook external-notebook ngrok-mediator mediator-agent mediator-notebook wallets-db"
# -----------------------------------------------------------------------------------------------------------------
# Functions:
# -----------------------------------------------------------------------------------------------------------------
function echoRed() {
_msg=${1}
_red='\e[31m'
_nc='\e[0m' # No Color
echo -e "${_red}${_msg}${_nc}"
}
function echoYellow() {
_msg=${1}
_yellow='\e[33m'
_nc='\e[0m' # No Color
echo -e "${_yellow}${_msg}${_nc}"
}
configureEnvironment() {
if [ -f .env ]; then
while read line; do
if [[ ! "$line" =~ ^\# ]] && [[ "$line" =~ .*= ]]; then
export ${line//[$'\r\n']/}
fi
done <.env
fi
for arg in "$@"; do
# Remove recognized arguments from the list after processing.
shift
# echo "arg: ${arg}"
# echo "Remaining: ${@}"
case "$arg" in
*=*)
# echo "Exporting ..."
export "${arg}"
;;
*)
# echo "Saving for later ..."
# If not recognized, save it for later procesing ...
set -- "$@" "$arg"
;;
esac
done
# global
export COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:controller}"
export GENESIS_URL="https://raw.githubusercontent.com/sovrin-foundation/sovrin/master/sovrin/pool_transactions_sandbox_genesis"
export WALLET_TYPE="indy"
# EXTERNAL-agent
export EXTERNAL_AGENT_NAME="EXTERNAL"
export EXTERNAL_ADMIN_PORT=8051
export EXTERNAL_HTTP_PORT=8050
export EXTERNAL_WEBHOOK_PORT=8052
export EXTERNAL_WEBHOOK_URL=${EXTERNAL_WEBHOOK_URL:-http://$DOCKERHOST:$EXTERNAL_WEBHOOK_PORT}
export EXTERNAL_AGENT_ENDPOINT=${EXTERNAL_AGENT_ENDPOINT:-http://$DOCKERHOST:$EXTERNAL_HTTP_PORT}
export EXTERNAL_WALLET_SEED="VAGENT_seed_00000000000000000000"
export EXTERNAL_WALLET_KEY="EXTERNAL_key_00000000000000000000000"
export EXTERNAL_WALLET_NAME="EXTERNAL Wallet"
export EXTERNAL_JUPYTER_PORT="8889"
export EXTERNAL_ADMIN_SECURE="true"
# MULTITENANT-agent
export MULTITENANT_AGENT_NAME="MULTITENANT"
export MULTITENANT_ADMIN_PORT=8021
export MULTITENANT_HTTP_PORT=8020
export MULTITENANT_WEBHOOK_PORT=8022
export MULTITENANT_WEBHOOK_URL=${MULTITENANT_WEBHOOK_URL:-http://$DOCKERHOST:$MULTITENANT_WEBHOOK_PORT}
export MULTITENANT_AGENT_ENDPOINT=${MULTITENANT_AGENT_ENDPOINT:-http://$DOCKERHOST:$MULTITENANT_HTTP_PORT}
export MULTITENANT_WALLET_SEED="IAGENT_seed_00000000000000000000"
export MULTITENANT_WALLET_KEY="MULTITENANT_key_00000000000000000000000"
export MULTITENANT_WALLET_NAME="MULTITENANT Wallet"
export MULTITENANT_JUPYTER_PORT="8888"
export MULTITENANT_ADMIN_SECURE="true"
# MEDIATOR-agent
export MEDIATOR_AGENT_NAME="MEDIATOR"
export MEDIATOR_ADMIN_PORT=8041
export MEDIATOR_HTTP_PORT=8040
export MEDIATOR_WEBHOOK_PORT=8042
export MEDIATOR_WEBHOOK_URL=${MEDIATOR_WEBHOOK_URL:-http://$DOCKERHOST:$MEDIATOR_WEBHOOK_PORT}
export MEDIATOR_AGENT_ENDPOINT=${MEDIATOR_AGENT_ENDPOINT:-http://$DOCKERHOST:$MEDIATOR_HTTP_PORT}
export MEDIATOR_WALLET_SEED="VAGENT_seed_00000000000000000000"
export MEDIATOR_WALLET_KEY="MEDIATOR_key_00000000000000000000000"
export MEDIATOR_WALLET_NAME="MEDIATOR Wallet"
export MEDIATOR_JUPYTER_PORT="8890"
export MEDIATOR_ADMIN_SECURE="true"
}
getInputParams() {
ARGS=""
for arg in $@; do
case "$arg" in
*=*)
# Skip it
;;
*)
ARGS+=" $arg"
;;
esac
done
echo ${ARGS}
}
getStartupParams() {
CONTAINERS=""
ARGS=""
for arg in $@; do
case "$arg" in
*=*)
# Skip it
;;
-*)
ARGS+=" $arg"
;;
*)
CONTAINERS+=" $arg"
;;
esac
done
if [ -z "$CONTAINERS" ]; then
CONTAINERS="$DEFAULT_CONTAINERS"
fi
echo ${ARGS} ${CONTAINERS}
}
deleteVolumes() {
_projectName=${COMPOSE_PROJECT_NAME:-docker}
echo "Stopping and removing any running containers ..."
docker-compose down -v
_pattern="^${_projectName}_\|^docker_"
_volumes=$(docker volume ls -q | grep ${_pattern})
if [ ! -z "${_volumes}" ]; then
echo "Removing project volumes ..."
echo ${_volumes} | xargs docker volume rm
else
echo "No project volumes exist."
fi
echo "Removing build cache ..."
rm -Rf ../client/tob-web/.cache
}
getSeedJson() {
_seed=${1}
if [ -z "${_seed}" ]; then
echo -e \\n"getSeedJson; Missing parameter!"\\n
exit 1
fi
echo "{\"seed\": \"${_seed}\"}"
}
generateSeeds() {
echo ${INDY_WALLET_SEED}
}
toLower() {
echo $(echo ${@} | tr '[:upper:]' '[:lower:]')
}
echoError() {
_msg=${1}
_red='\033[0;31m'
_nc='\033[0m' # No Color
echo -e "${_red}${_msg}${_nc}" >&2
}
functionExists() {
(
if [ ! -z ${1} ] && type ${1} &>/dev/null; then
return 0
else
return 1
fi
)
}
# =================================================================================================================
pushd "${SCRIPT_HOME}" >/dev/null
COMMAND=$(toLower ${1})
shift || COMMAND=usage
case "${COMMAND}" in
start | up)
export MULTITENANT_TUTORIAL="MULTITENANT_TUTORIAL"
echo $MULTITENANT_TUTORIAL
echoYellow "Starting up... This can take a couple of minutes."
_startupParams=$(getStartupParams $@)
configureEnvironment "$@"
docker-compose\
--log-level ERROR up \
--build --remove-orphans \
-d ${_startupParams}
docker-compose \
--log-level ERROR logs \
-f
;;
restart)
_startupParams=$(getStartupParams $@)
configureEnvironment "$@"
docker-compose stop ${_startupParams}
docker-compose up -d --build --remove-orphans ${_startupParams}
;;
logs)
configureEnvironment "$@"
docker-compose logs -f
;;
stop)
unset MULTITENANT_TUTORIAL
configureEnvironment
docker-compose stop
;;
rm | down)
unset MULTITENANT_TUTORIAL
configureEnvironment
docker-compose \
--log-level ERROR down \
-v
usage
;;
esac
popd >/dev/null