-
Notifications
You must be signed in to change notification settings - Fork 43
/
start_ocean.sh
executable file
路438 lines (402 loc) 路 17.3 KB
/
start_ocean.sh
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#!/usr/bin/env bash
# start_ocean.sh
# Copyright (c) 2019 Ocean Protocol contributors
# SPDX-License-Identifier: Apache-2.0
IP="localhost"
optspec=":-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
exposeip)
IP="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
esac;;
esac
done
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
export BRIZO_ENV_FILE="${DIR}/brizo.env"
# Patch $DIR if spaces (BRIZO_ENV_FILE does not need patch)
DIR="${DIR/ /\\ }"
COMPOSE_DIR="${DIR}/compose-files"
# Default versions of Aquarius, Brizo, Keeper Contracts and Commons
export AQUARIUS_VERSION=${AQUARIUS_VERSION:-v1.0.2}
export BRIZO_VERSION=${BRIZO_VERSION:-v0.7.0}
export EVENTS_HANDLER_VERSION=${EVENTS_HANDLER_VERSION:-v0.3.0}
export KEEPER_VERSION=${KEEPER_VERSION:-v0.12.7}
export FAUCET_VERSION=${FAUCET_VERSION:-v0.3.2}
export COMMONS_SERVER_VERSION=${COMMONS_SERVER_VERSION:-v2.0.0-beta.2}
export COMMONS_CLIENT_VERSION=${COMMONS_CLIENT_VERSION:-v2.0.0-beta.2}
export PARITY_IMAGE="parity/parity:v2.5.7-stable"
export PROJECT_NAME="ocean"
export FORCEPULL="false"
# Ocean filesystem artifacts
export OCEAN_HOME="${HOME}/.ocean"
# keeper options
export KEEPER_OWNER_ROLE_ADDRESS="${KEEPER_OWNER_ROLE_ADDRESS}"
export KEEPER_DEPLOY_CONTRACTS="true"
export KEEPER_ARTIFACTS_FOLDER="${OCEAN_HOME}/keeper-contracts/artifacts"
# Specify which ethereum client to run or connect to: development, spree or nile
export KEEPER_NETWORK_NAME="spree"
export NODE_COMPOSE_FILE="${COMPOSE_DIR}/nodes/spree_node.yml"
# Ganache specific option, these two options have no effect when not running ganache-cli
export GANACHE_DATABASE_PATH="${DIR}"
export GANACHE_REUSE_DATABASE="false"
# Specify the ethereum default RPC container provider
if [ ${IP} = "localhost" ]; then
export KEEPER_RPC_HOST="keeper-node"
else
export KEEPER_RPC_HOST=${IP}
fi
export KEEPER_RPC_PORT="8545"
export KEEPER_RPC_URL="http://"${KEEPER_RPC_HOST}:${KEEPER_RPC_PORT}
# Use this seed only on Spree! (Spree is the default.)
export KEEPER_MNEMONIC="taxi music thumb unique chat sand crew more leg another off lamp"
# Enable acl-contract validation in Secret-store
export CONFIGURE_ACL="true"
export ACL_CONTRACT_ADDRESS=""
# Default Aquarius parameters: use Elasticsearch
export DB_MODULE="elasticsearch"
export DB_HOSTNAME="172.15.0.11"
export DB_PORT="9200"
export DB_USERNAME="elastic"
export DB_PASSWORD="changeme"
export DB_SSL="false"
export DB_VERIFY_CERTS="false"
export DB_CA_CERTS=""
export DB_CLIENT_KEY=""
export DB_CLIENT_CERT=""
CHECK_ELASTIC_VM_COUNT=true
export BRIZO_WORKERS=${BRIZO_WORKERS:-5}
export BRIZO_LOG_LEVEL="INFO"
export EVENTS_HANDLER_LOG_LEVEL="INFO"
export BRIZO_IPFS_GATEWAY=https://ipfs.oceanprotocol.com
# Set a valid parity address and password to have seamless interaction with the `keeper`
# it has to exist on the secret store signing node and as well on the keeper node
export PROVIDER_ADDRESS=0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0
export PROVIDER_PASSWORD=secret
export PROVIDER_KEYFILE="/accounts/provider.json"
export ACCOUNTS_FOLDER="../accounts"
if [ ${IP} = "localhost" ]; then
export SECRET_STORE_URL=http://secret-store:12001
export SIGNING_NODE_URL=http://secret-store-signing-node:8545
export AQUARIUS_URI=http://aquarius:5000
export FAUCET_URL=http://localhost:3001
export COMMONS_SERVER_URL=http://localhost:4000
export COMMONS_CLIENT_URL=http://localhost:3000
export COMMONS_KEEPER_RPC_HOST=http://localhost:8545
export COMMONS_SECRET_STORE_URL=http://localhost:12001
export BRIZO_URL=http://localhost:8030
else
export SECRET_STORE_URL=http://${IP}:12001
export SIGNING_NODE_URL=http://${IP}:8545
export AQUARIUS_URI=http://${IP}:5000
export FAUCET_URL=http://${IP}:3001
export COMMONS_SERVER_URL=http://${IP}:4000
export COMMONS_CLIENT_URL=http://${IP}:3000
export COMMONS_KEEPER_RPC_HOST=http://${IP}:8545
export COMMONS_SECRET_STORE_URL=http://${IP}:12001
export BRIZO_URL=http://${IP}:8030
fi
# Default Faucet options
export FAUCET_TIMESPAN=${FAUCET_TIMESPAN:-24}
#commons
export COMMONS_BRIZO_URL=${BRIZO_URL}
export COMMONS_AQUARIUS_URI=${AQUARIUS_URI}
export COMMONS_FAUCET_URL=${FAUCET_URL}
export COMMONS_IPFS_GATEWAY_URI=https://ipfs.oceanprotocol.com
export COMMONS_IPFS_NODE_URI=https://ipfs.oceanprotocol.com:443
export OPERATOR_SERVICE_URL=http://127.0.0.1:8050
# Export User UID and GID
export LOCAL_USER_ID=$(id -u)
export LOCAL_GROUP_ID=$(id -g)
#add aquarius to /etc/hosts
if [ ${IP} = "localhost" ]; then
if grep -q "aquarius" /etc/hosts; then
echo "aquarius exists"
else
echo "127.0.0.1 aquarius" | sudo tee -a /etc/hosts
fi
fi
# colors
COLOR_R="\033[0;31m" # red
COLOR_G="\033[0;32m" # green
COLOR_Y="\033[0;33m" # yellow
COLOR_B="\033[0;34m" # blue
COLOR_M="\033[0;35m" # magenta
COLOR_C="\033[0;36m" # cyan
# reset
COLOR_RESET="\033[00m"
function get_acl_address {
# detect keeper version
local version="${1:-latest}"
# sesarch in the file for the keeper version
line=$(grep "^${version}=" "${DIR}/ACL/${KEEPER_NETWORK_NAME}_addresses.txt")
# set address
address="${line##*=}"
# if address is still empty
if [ -z "${address}" ]; then
# fetch from latest line
line=$(grep "^latest=" "${DIR}/ACL/${KEEPER_NETWORK_NAME}_addresses.txt")
# set address
address="${line##*=}"
fi
echo "${address}"
}
function show_banner {
local output=$(cat .banner)
echo -e "$COLOR_B$output$COLOR_RESET"
echo ""
}
function configure_secret_store {
# restore default secret store config (Issue #126)
if [ -e "$DIR/networks/secret-store/config/config.toml.save" ]; then
cp "$DIR/networks/secret-store/config/config.toml.save" \
"$DIR/networks/secret-store/config/config.toml"
fi
}
function check_if_owned_by_root {
if [ -d "$OCEAN_HOME" ]; then
uid=$(ls -nd "$OCEAN_HOME" | awk '{print $3;}')
if [ "$uid" = "0" ]; then
printf $COLOR_R"WARN: $OCEAN_HOME is owned by root\n"$COLOR_RESET >&2
else
uid=$(ls -nd "$KEEPER_ARTIFACTS_FOLDER" | awk '{print $3;}')
if [ "$uid" = "0" ]; then
printf $COLOR_R"WARN: $KEEPER_ARTIFACTS_FOLDER is owned by root\n"$COLOR_RESET >&2
fi
fi
fi
}
function clean_local_contracts {
rm -f "${KEEPER_ARTIFACTS_FOLDER}/ready"
rm -f "${KEEPER_ARTIFACTS_FOLDER}/*.spree.json"
rm -f "${KEEPER_ARTIFACTS_FOLDER}/*.development.json"
}
function check_max_map_count {
vm_max_map_count=$(docker run --rm busybox sysctl -q vm.max_map_count)
vm_max_map_count=${vm_max_map_count##* }
vm_max_map_count=262144
if [ $vm_max_map_count -lt 262144 ]; then
printf $COLOR_R'vm.max_map_count current kernel value ($vm_max_map_count) is too low for Elasticsearch\n'$COLOR_RESET
printf $COLOR_R'You must update vm.max_map_count to at least 262144\n'$COLOR_RESET
printf $COLOR_R'Please refer to https://www.elastic.co/guide/en/elasticsearch/reference/6.6/vm-max-map-count.html\n'$COLOR_RESET
exit 1
fi
}
check_if_owned_by_root
show_banner
COMPOSE_FILES=""
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/dashboard.yml"
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/keeper_contracts.yml"
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/network_volumes.yml"
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/commons.yml"
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/aquarius_elasticsearch.yml"
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/brizo.yml"
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/events_handler.yml"
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/secret_store.yml"
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/secret_store_signing_node.yml"
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/faucet.yml"
DOCKER_COMPOSE_EXTRA_OPTS="${DOCKER_COMPOSE_EXTRA_OPTS:-}"
while :; do
case $1 in
--exposeip)
;;
#################################################
# Log level
#################################################
--debug)
export BRIZO_LOG_LEVEL="DEBUG"
export EVENTS_HANDLER_LOG_LEVEL="DEBUG"
;;
#################################################
# Disable color
#################################################
--no-ansi)
DOCKER_COMPOSE_EXTRA_OPTS+=" --no-ansi"
unset COLOR_R COLOR_G COLOR_Y COLOR_B COLOR_M COLOR_C COLOR_RESET
;;
#################################################
# Version switches
#################################################
--latest)
export AQUARIUS_VERSION="latest"
export BRIZO_VERSION="latest"
export EVENTS_HANDLER_VERSION="latest"
export KEEPER_VERSION="latest"
# TODO: Change label on Docker to refer `latest` to `master`
export FAUCET_VERSION="latest"
export COMMONS_SERVER_VERSION="latest"
export COMMONS_CLIENT_VERSION="latest"
printf $COLOR_Y'Switched to latest components...\n\n'$COLOR_RESET
;;
--force-pull)
export FORCEPULL="true"
printf $COLOR_Y'Pulling the latest revision of the used Docker images...\n\n'$COLOR_RESET
;;
#################################################
# Exclude switches
#################################################
--no-pleuston)
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/commons.yml/}"
printf $COLOR_Y'Starting without Commons...\n\n'$COLOR_RESET
;;
--no-commons)
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/commons.yml/}"
printf $COLOR_Y'Starting without Commons...\n\n'$COLOR_RESET
;;
--no-events-handler)
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/events_handler.yml/}"
printf $COLOR_Y'Starting without Events Handler...\n\n'$COLOR_RESET
;;
--no-brizo)
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/brizo.yml/}"
printf $COLOR_Y'Starting without Brizo...\n\n'$COLOR_RESET
;;
--no-aquarius)
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/aquarius_elasticsearch.yml/}"
printf $COLOR_Y'Starting without Aquarius...\n\n'$COLOR_RESET
;;
--no-secret-store)
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/secret_store.yml/}"
printf $COLOR_Y'Starting without Secret Store...\n\n'$COLOR_RESET
;;
--no-faucet)
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/faucet.yml/}"
printf $COLOR_Y'Starting without Faucet...\n\n'$COLOR_RESET
;;
--no-dashboard)
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/dashboard.yml/}"
printf $COLOR_Y'Starting without Dashboard ...\n\n'$COLOR_RESET
;;
--no-acl-contract)
export CONFIGURE_ACL="false"
printf $COLOR_Y'Disabling acl validation in secret-store...\n\n'$COLOR_RESET
;;
#################################################
# Only Secret Store
#################################################
--only-secret-store)
COMPOSE_FILES=""
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/network_volumes.yml"
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/secret_store.yml"
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/secret_store_signing_node.yml"
NODE_COMPOSE_FILE=""
printf $COLOR_Y'Starting only Secret Store...\n\n'$COLOR_RESET
;;
#################################################
# MongoDB
#################################################
--mongodb)
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/aquarius_mongodb.yml"
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/aquarius_elasticsearch.yml/}"
CHECK_ELASTIC_VM_COUNT=false
export DB_MODULE="mongodb"
export DB_HOSTNAME="mongodb"
export DB_PORT="27017"
printf $COLOR_Y'Starting with MongoDB...\n\n'$COLOR_RESET
;;
#################################################
# Contract/Storage switches
#################################################
--reuse-ganache-database)
export GANACHE_REUSE_DATABASE="true"
printf $COLOR_Y'Starting and reusing the database...\n\n'$COLOR_RESET
;;
#################################################
# Node type switches
#################################################
# spins up a new ganache blockchain
--local-ganache-node)
export NODE_COMPOSE_FILE="${COMPOSE_DIR}/nodes/ganache_node.yml"
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/secret_store.yml/}"
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/secret_store_signing_node.yml/}"
export KEEPER_MNEMONIC=''
export KEEPER_NETWORK_NAME="development"
export KEEPER_DEPLOY_CONTRACTS="true"
printf $COLOR_Y'Starting with local Ganache node...\n\n'$COLOR_RESET
printf $COLOR_Y'Starting without Secret Store...\n\n'$COLOR_RESET
printf $COLOR_Y'Starting without Secret Store signing node...\n\n'$COLOR_RESET
;;
# connects you to nile ocean testnet
--local-nile-node)
export NODE_COMPOSE_FILE="${COMPOSE_DIR}/nodes/nile_node.yml"
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/keeper_contracts.yml/}"
export KEEPER_MNEMONIC=''
export KEEPER_NETWORK_NAME="nile"
export KEEPER_DEPLOY_CONTRACTS="false"
export ACL_CONTRACT_ADDRESS="$(get_acl_address ${KEEPER_VERSION})"
printf $COLOR_Y'Starting with local Nile node...\n\n'$COLOR_RESET
;;
# connects you to duero ocean testnet
--local-duero-node)
export NODE_COMPOSE_FILE="${COMPOSE_DIR}/nodes/duero_node.yml"
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/keeper_contracts.yml/}"
export KEEPER_MNEMONIC=''
export KEEPER_NETWORK_NAME="duero"
export KEEPER_DEPLOY_CONTRACTS="false"
export ACL_CONTRACT_ADDRESS="$(get_acl_address ${KEEPER_VERSION})"
printf $COLOR_Y'Starting with local Duero node...\n\n'$COLOR_RESET
;;
# connects you to Pacific ocean network
--local-pacific-node)
export NODE_COMPOSE_FILE="${COMPOSE_DIR}/nodes/pacific_node.yml"
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/keeper_contracts.yml/}"
export KEEPER_MNEMONIC=''
export KEEPER_NETWORK_NAME="pacific"
export KEEPER_DEPLOY_CONTRACTS="false"
export ACL_CONTRACT_ADDRESS="$(get_acl_address ${KEEPER_VERSION})"
printf $COLOR_Y'Starting with local Pacific node...\n\n'$COLOR_RESET
printf $COLOR_Y'Starting without Secret Store...\n\n'$COLOR_RESET
;;
# spins up spree local testnet
--local-spree-node)
export NODE_COMPOSE_FILE="${COMPOSE_DIR}/nodes/spree_node.yml"
# use this seed only on spree!
export KEEPER_MNEMONIC="taxi music thumb unique chat sand crew more leg another off lamp"
export KEEPER_NETWORK_NAME="spree"
export KEEPER_DEPLOY_CONTRACTS="true"
printf $COLOR_Y'Starting with local Spree node...\n\n'$COLOR_RESET
;;
#################################################
# Cleaning switches
#################################################
--purge)
printf $COLOR_R'Doing a deep clean ...\n\n'$COLOR_RESET
eval docker-compose --project-name=$PROJECT_NAME "$COMPOSE_FILES" -f "${NODE_COMPOSE_FILE}" down
docker network rm ${PROJECT_NAME}_default || true
docker network rm ${PROJECT_NAME}_backend || true
docker network rm ${PROJECT_NAME}_secretstore || true
docker volume rm ${PROJECT_NAME}_secret-store || true
docker volume rm ${PROJECT_NAME}_keeper-node-duero || true
docker volume rm ${PROJECT_NAME}_keeper-node-nile || true
docker volume rm ${PROJECT_NAME}_keeper-node-pacific || true
docker volume rm ${PROJECT_NAME}_faucet || true
read -p "Are you sure you want to delete $KEEPER_ARTIFACTS_FOLDER? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm -rf "${KEEPER_ARTIFACTS_FOLDER}"
fi
;;
--) # End of all options.
shift
break
;;
-?*)
printf $COLOR_R'WARN: Unknown option (ignored): %s\n'$COLOR_RESET "$1" >&2
break
;;
*)
[ ${CHECK_ELASTIC_VM_COUNT} = "true" ] && check_max_map_count
printf $COLOR_Y'Starting Ocean...\n\n'$COLOR_RESET
configure_secret_store
[ -n "${NODE_COMPOSE_FILE}" ] && COMPOSE_FILES+=" -f ${NODE_COMPOSE_FILE}"
[ ${KEEPER_DEPLOY_CONTRACTS} = "true" ] && clean_local_contracts
[ ${FORCEPULL} = "true" ] && eval docker-compose "$DOCKER_COMPOSE_EXTRA_OPTS" --project-name=$PROJECT_NAME "$COMPOSE_FILES" pull
eval docker-compose "$DOCKER_COMPOSE_EXTRA_OPTS" --project-name=$PROJECT_NAME "$COMPOSE_FILES" up --remove-orphans
break
esac
shift
done