2018-09-27 11:30:07 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-09-08 18:23:10 +02:00
|
|
|
#
|
2019-03-11 15:47:16 +01:00
|
|
|
# Copyright (c) 2019 Ocean Protocol contributors
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2020-09-08 18:23:10 +02:00
|
|
|
#
|
|
|
|
# Usage: ./start_ocean.sh
|
|
|
|
#
|
|
|
|
|
2019-10-10 12:28:19 +02:00
|
|
|
IP="localhost"
|
|
|
|
optspec=":-:"
|
|
|
|
while getopts "$optspec" optchar; do
|
|
|
|
case "${optchar}" in
|
|
|
|
-)
|
|
|
|
case "${OPTARG}" in
|
|
|
|
exposeip)
|
|
|
|
IP="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
|
|
|
|
;;
|
|
|
|
esac;;
|
|
|
|
esac
|
|
|
|
done
|
2018-09-27 11:30:07 +02:00
|
|
|
|
2019-01-28 11:45:47 +01:00
|
|
|
set -e
|
2019-01-28 11:36:00 +01:00
|
|
|
|
2020-09-08 18:23:10 +02:00
|
|
|
# Patch $DIR if spaces
|
2018-11-29 12:32:38 +01:00
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
2018-12-19 10:52:44 +01:00
|
|
|
DIR="${DIR/ /\\ }"
|
2018-11-29 12:32:38 +01:00
|
|
|
COMPOSE_DIR="${DIR}/compose-files"
|
2018-12-05 10:46:50 +01:00
|
|
|
|
2020-09-08 18:23:10 +02:00
|
|
|
# Default versions of Aquarius, Provider
|
2019-05-06 09:05:04 +02:00
|
|
|
|
2020-09-23 13:49:36 +02:00
|
|
|
export AQUARIUS_VERSION=${AQUARIUS_VERSION:-v3}
|
2020-09-22 14:50:46 +02:00
|
|
|
export PROVIDER_VERSION=${PROVIDER_VERSION:-v0.3.0}
|
2020-10-02 09:36:24 +02:00
|
|
|
export CONTRACTS_VERSION=${CONTRACTS_VERSION:-v0.5.1}
|
2018-12-05 10:46:50 +01:00
|
|
|
export PROJECT_NAME="ocean"
|
2019-01-16 16:06:27 +01:00
|
|
|
export FORCEPULL="false"
|
2018-12-17 10:22:39 +01:00
|
|
|
|
2020-09-09 18:25:24 +02:00
|
|
|
# Export User UID and GID
|
|
|
|
export LOCAL_USER_ID=$(id -u)
|
|
|
|
export LOCAL_GROUP_ID=$(id -g)
|
|
|
|
|
2018-12-05 10:46:50 +01:00
|
|
|
|
2018-11-30 10:36:55 +01:00
|
|
|
# Specify the ethereum default RPC container provider
|
2019-10-10 12:28:19 +02:00
|
|
|
if [ ${IP} = "localhost" ]; then
|
2020-07-15 10:28:54 +02:00
|
|
|
export NETWORK_RPC_HOST="172.15.0.3"
|
2019-10-10 12:28:19 +02:00
|
|
|
else
|
2020-07-15 10:28:54 +02:00
|
|
|
export NETWORK_RPC_HOST=${IP}
|
2019-10-10 12:28:19 +02:00
|
|
|
fi
|
2020-07-15 10:28:54 +02:00
|
|
|
export NETWORK_RPC_PORT="8545"
|
|
|
|
export NETWORK_RPC_URL="http://"${NETWORK_RPC_HOST}:${NETWORK_RPC_PORT}
|
2020-09-09 18:25:24 +02:00
|
|
|
# Use this seed on ganache to always create the same wallets
|
2020-07-06 19:18:07 +02:00
|
|
|
export GANACHE_MNEMONIC=${GANACHE_MNEMONIC:-"taxi music thumb unique chat sand crew more leg another off lamp"}
|
2018-09-27 11:30:07 +02:00
|
|
|
|
2020-09-09 18:25:24 +02:00
|
|
|
# Ocean contracts
|
|
|
|
export OCEAN_HOME="${HOME}/.ocean"
|
|
|
|
export CONTRACTS_OWNER_ROLE_ADDRESS="${CONTRACTS_OWNER_ROLE_ADDRESS}"
|
2020-09-11 08:25:55 +02:00
|
|
|
export DEPLOY_CONTRACTS="true"
|
2020-09-09 18:25:24 +02:00
|
|
|
export OCEAN_ARTIFACTS_FOLDER="${OCEAN_HOME}/ocean-contracts/artifacts"
|
2020-09-15 10:07:35 +02:00
|
|
|
export ADDRESS_FILE="${OCEAN_ARTIFACTS_FOLDER}/address.json"
|
|
|
|
echo "export ADDRESS_FILE=${ADDRESS_FILE}"
|
2020-09-09 18:25:24 +02:00
|
|
|
# Specify which ethereum client to run or connect to: development
|
|
|
|
export CONTRACTS_NETWORK_NAME="ganache"
|
2018-12-27 15:14:20 +01:00
|
|
|
|
2019-06-26 11:47:01 +02:00
|
|
|
# Default Aquarius parameters: use Elasticsearch
|
|
|
|
export DB_MODULE="elasticsearch"
|
2020-06-28 14:33:29 +02:00
|
|
|
export DB_HOSTNAME="172.15.0.6"
|
2019-06-26 11:47:01 +02:00
|
|
|
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=""
|
2019-06-28 16:27:28 +02:00
|
|
|
CHECK_ELASTIC_VM_COUNT=true
|
2019-02-08 10:57:56 +01:00
|
|
|
|
2019-10-15 13:10:14 +02:00
|
|
|
|
2020-06-26 17:37:46 +02:00
|
|
|
#Provider
|
|
|
|
export PROVIDER_LOG_LEVEL=INFO
|
2020-09-08 10:39:52 +02:00
|
|
|
export PROVIDER_WORKERS=1
|
2020-06-26 17:37:46 +02:00
|
|
|
export PROVIDER_IPFS_GATEWAY=https://ipfs.oceanprotocol.com
|
2020-09-15 10:07:35 +02:00
|
|
|
export PROVIDER_PRIVATE_KEY=0xfd5c1ccea015b6d663618850824154a3b3fb2882c46cefb05b9a93fea8c3d215
|
2020-06-26 17:37:46 +02:00
|
|
|
|
2019-10-10 12:28:19 +02:00
|
|
|
if [ ${IP} = "localhost" ]; then
|
2020-07-01 18:20:33 +02:00
|
|
|
export AQUARIUS_URI=http://172.15.0.5:5000
|
2019-10-10 12:28:19 +02:00
|
|
|
else
|
|
|
|
export AQUARIUS_URI=http://${IP}:5000
|
|
|
|
fi
|
2019-07-18 15:41:41 +02:00
|
|
|
|
2020-02-17 09:04:29 +01:00
|
|
|
#export OPERATOR_SERVICE_URL=http://127.0.0.1:8050
|
|
|
|
export OPERATOR_SERVICE_URL=https://operator-api.operator.dev-ocean.com
|
2019-11-20 17:31:58 +01:00
|
|
|
|
2019-12-10 14:48:40 +01:00
|
|
|
|
2019-10-02 15:20:06 +02:00
|
|
|
#add aquarius to /etc/hosts
|
|
|
|
|
2019-10-11 07:12:56 +02:00
|
|
|
if [ ${IP} = "localhost" ]; then
|
|
|
|
if grep -q "aquarius" /etc/hosts; then
|
|
|
|
echo "aquarius exists"
|
|
|
|
else
|
2019-10-11 07:25:26 +02:00
|
|
|
echo "127.0.0.1 aquarius" | sudo tee -a /etc/hosts
|
2019-10-11 07:12:56 +02:00
|
|
|
fi
|
|
|
|
fi
|
2019-10-02 15:20:06 +02:00
|
|
|
|
2018-10-10 12:21:56 +02:00
|
|
|
# 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
|
2018-10-02 13:38:55 +02:00
|
|
|
|
2018-10-10 12:21:56 +02:00
|
|
|
# reset
|
|
|
|
COLOR_RESET="\033[00m"
|
2018-09-27 13:15:43 +02:00
|
|
|
|
2018-10-10 12:21:56 +02:00
|
|
|
function show_banner {
|
|
|
|
local output=$(cat .banner)
|
|
|
|
echo -e "$COLOR_B$output$COLOR_RESET"
|
|
|
|
echo ""
|
|
|
|
}
|
2018-09-27 13:15:43 +02:00
|
|
|
|
2019-03-28 23:07:20 +01:00
|
|
|
|
2019-03-11 15:47:16 +01:00
|
|
|
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
|
2020-07-15 10:28:54 +02:00
|
|
|
uid=$(ls -nd "$OCEAN_ARTIFACTS_FOLDER" | awk '{print $3;}')
|
2019-03-11 15:47:16 +01:00
|
|
|
if [ "$uid" = "0" ]; then
|
2020-07-15 10:28:54 +02:00
|
|
|
printf $COLOR_R"WARN: $OCEAN_ARTIFACTS_FOLDER is owned by root\n"$COLOR_RESET >&2
|
2019-03-11 15:47:16 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-04-03 09:26:06 +02:00
|
|
|
|
2019-06-28 16:27:28 +02:00
|
|
|
function check_max_map_count {
|
2019-07-12 08:37:45 +02:00
|
|
|
vm_max_map_count=$(docker run --rm busybox sysctl -q vm.max_map_count)
|
2019-06-28 16:27:28 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-09-11 08:25:55 +02:00
|
|
|
function clean_local_contracts {
|
|
|
|
rm -f "${OCEAN_ARTIFACTS_FOLDER}/ready"
|
|
|
|
rm -f "${OCEAN_ARTIFACTS_FOLDER}/*.json"
|
|
|
|
}
|
|
|
|
|
2019-03-11 15:47:16 +01:00
|
|
|
check_if_owned_by_root
|
2018-10-10 12:21:56 +02:00
|
|
|
show_banner
|
2018-10-02 13:13:10 +02:00
|
|
|
|
2018-11-29 12:32:38 +01:00
|
|
|
COMPOSE_FILES=""
|
|
|
|
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/network_volumes.yml"
|
2020-06-26 17:37:46 +02:00
|
|
|
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/dashboard.yml"
|
2019-06-26 11:47:01 +02:00
|
|
|
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/aquarius_elasticsearch.yml"
|
2020-06-26 17:37:46 +02:00
|
|
|
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/provider.yml"
|
2020-06-28 14:15:53 +02:00
|
|
|
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/ganache.yml"
|
2020-09-09 18:25:24 +02:00
|
|
|
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/ocean_contracts.yml"
|
|
|
|
|
2019-01-16 16:06:27 +01:00
|
|
|
DOCKER_COMPOSE_EXTRA_OPTS="${DOCKER_COMPOSE_EXTRA_OPTS:-}"
|
|
|
|
|
2018-10-10 12:21:56 +02:00
|
|
|
while :; do
|
|
|
|
case $1 in
|
2019-10-10 12:28:19 +02:00
|
|
|
--exposeip)
|
|
|
|
;;
|
2018-12-05 10:46:50 +01:00
|
|
|
#################################################
|
2019-01-16 16:06:27 +01:00
|
|
|
# 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
|
|
|
|
;;
|
2018-12-17 10:22:39 +01:00
|
|
|
--force-pull)
|
2019-01-16 16:06:27 +01:00
|
|
|
export FORCEPULL="true"
|
2019-02-28 12:18:53 +01:00
|
|
|
printf $COLOR_Y'Pulling the latest revision of the used Docker images...\n\n'$COLOR_RESET
|
2018-12-17 10:22:39 +01:00
|
|
|
;;
|
2018-12-05 10:46:50 +01:00
|
|
|
#################################################
|
|
|
|
# Exclude switches
|
|
|
|
#################################################
|
2020-06-26 17:37:46 +02:00
|
|
|
--no-provider)
|
|
|
|
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/provider.yml/}"
|
2020-06-28 14:15:53 +02:00
|
|
|
printf $COLOR_Y'Starting without Provider...\n\n'$COLOR_RESET
|
|
|
|
;;
|
|
|
|
--no-ganache)
|
|
|
|
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/ganache.yml/}"
|
2020-09-09 18:25:24 +02:00
|
|
|
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/ocean_contracts.yml/}"
|
2020-06-28 14:15:53 +02:00
|
|
|
printf $COLOR_Y'Starting without Ganache...\n\n'$COLOR_RESET
|
2018-12-06 09:16:50 +01:00
|
|
|
;;
|
|
|
|
--no-aquarius)
|
2019-06-26 11:47:01 +02:00
|
|
|
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/aquarius_elasticsearch.yml/}"
|
2018-12-06 09:16:50 +01:00
|
|
|
printf $COLOR_Y'Starting without Aquarius...\n\n'$COLOR_RESET
|
|
|
|
;;
|
2020-06-28 14:22:44 +02:00
|
|
|
--no-dashboard)
|
|
|
|
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/dashboard.yml/}"
|
|
|
|
printf $COLOR_Y'Starting without Dashboard ...\n\n'$COLOR_RESET
|
|
|
|
;;
|
2018-12-05 10:46:50 +01:00
|
|
|
#################################################
|
2019-06-26 11:47:01 +02:00
|
|
|
# MongoDB
|
2019-02-08 10:57:56 +01:00
|
|
|
#################################################
|
2019-06-26 11:47:01 +02:00
|
|
|
--mongodb)
|
|
|
|
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/aquarius_mongodb.yml"
|
|
|
|
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/aquarius_elasticsearch.yml/}"
|
2019-06-28 16:27:28 +02:00
|
|
|
CHECK_ELASTIC_VM_COUNT=false
|
2019-06-26 11:47:01 +02:00
|
|
|
export DB_MODULE="mongodb"
|
|
|
|
export DB_HOSTNAME="mongodb"
|
|
|
|
export DB_PORT="27017"
|
|
|
|
printf $COLOR_Y'Starting with MongoDB...\n\n'$COLOR_RESET
|
2019-02-08 10:57:56 +01:00
|
|
|
;;
|
|
|
|
#################################################
|
2018-12-05 10:46:50 +01:00
|
|
|
# Cleaning switches
|
|
|
|
#################################################
|
2018-11-30 10:55:15 +01:00
|
|
|
--purge)
|
2018-12-17 10:22:39 +01:00
|
|
|
printf $COLOR_R'Doing a deep clean ...\n\n'$COLOR_RESET
|
2019-08-26 09:14:05 +02:00
|
|
|
eval docker-compose --project-name=$PROJECT_NAME "$COMPOSE_FILES" -f "${NODE_COMPOSE_FILE}" down
|
2018-12-05 12:16:18 +01:00
|
|
|
docker network rm ${PROJECT_NAME}_default || true
|
2018-12-17 10:22:39 +01:00
|
|
|
docker network rm ${PROJECT_NAME}_backend || true
|
2018-11-15 11:02:31 +01:00
|
|
|
;;
|
2018-10-10 12:21:56 +02:00
|
|
|
--) # End of all options.
|
2018-11-29 12:32:38 +01:00
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
2018-10-10 12:21:56 +02:00
|
|
|
-?*)
|
2018-11-29 12:32:38 +01:00
|
|
|
printf $COLOR_R'WARN: Unknown option (ignored): %s\n'$COLOR_RESET "$1" >&2
|
|
|
|
break
|
|
|
|
;;
|
2018-10-10 12:21:56 +02:00
|
|
|
*)
|
2019-06-28 16:27:28 +02:00
|
|
|
[ ${CHECK_ELASTIC_VM_COUNT} = "true" ] && check_max_map_count
|
2020-06-26 17:37:46 +02:00
|
|
|
printf $COLOR_Y'Starting Ocean V3...\n\n'$COLOR_RESET
|
2020-09-11 08:25:55 +02:00
|
|
|
[ ${DEPLOY_CONTRACTS} = "true" ] && clean_local_contracts
|
2019-08-08 10:18:49 +02:00
|
|
|
[ ${FORCEPULL} = "true" ] && eval docker-compose "$DOCKER_COMPOSE_EXTRA_OPTS" --project-name=$PROJECT_NAME "$COMPOSE_FILES" pull
|
2019-07-26 18:03:42 +02:00
|
|
|
eval docker-compose "$DOCKER_COMPOSE_EXTRA_OPTS" --project-name=$PROJECT_NAME "$COMPOSE_FILES" up --remove-orphans
|
2018-10-10 12:21:56 +02:00
|
|
|
break
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|