1
0
mirror of https://github.com/oceanprotocol/barge.git synced 2024-11-22 17:50:13 +01:00
barge/start_ocean.sh

333 lines
12 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2020-09-08 18:23:10 +02:00
#
2023-02-22 12:18:02 +01:00
# Copyright (c) 2023 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
2019-01-28 11:45:47 +01:00
set -e
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 )"
DIR="${DIR/ /\\ }"
2018-11-29 12:32:38 +01:00
COMPOSE_DIR="${DIR}/compose-files"
2020-09-08 18:23:10 +02:00
# Default versions of Aquarius, Provider
2023-09-25 16:43:08 +02:00
export AQUARIUS_VERSION=${AQUARIUS_VERSION:-v5.1.5}
2022-12-10 09:02:31 +01:00
export ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION:-8.5.1}
2024-07-05 16:47:18 +02:00
export PROVIDER_VERSION=${PROVIDER_VERSION:-v2.1.6}
2023-11-22 12:53:12 +01:00
export SUBGRAPH_VERSION=${SUBGRAPH_VERSION:-v4.0.2}
2024-03-15 21:51:58 +01:00
export CONTRACTS_VERSION=${CONTRACTS_VERSION:-v2.0.4}
2021-06-09 08:46:50 +02:00
export RBAC_VERSION=${RBAC_VERSION:-next}
2023-11-21 18:59:51 +01:00
export GRAPH_NODE_VERSION=${GRAPH_NODE_VERSION:-v0.33.0}
2022-02-03 18:19:06 +01:00
2022-04-21 17:53:44 +02:00
export OPERATOR_SERVICE_VERSION=${OPERATOR_SERVICE_VERSION:-oceanprotocol/operator-service:v4main}
export OPERATOR_ENGINE_VERSION=${OPERATOR_ENGINE_VERSION:-oceanprotocol/operator-engine:v4main}
export POD_CONFIGURATION_VERSION=${POD_CONFIGURATION_VERSION:-oceanprotocol/pod-configuration:v4main}
export POD_PUBLISHING_VERSION=${POD_PUBLISHING_VERSION:-oceanprotocol/pod-publishing:v4main}
2022-04-21 17:44:18 +02:00
export WAIT_FOR_C2DIMAGES=${WAIT_FOR_C2DIMAGES:-false}
2022-02-03 18:19:06 +01:00
2023-05-24 12:11:15 +02:00
export PDR_PUBLISHER_VERSION=${PDR_PUBLISHER_VERSION:-latest}
2023-08-03 11:09:08 +02:00
export PDR_BACKEND_VERSION=${PDR_BACKEND_VERSION:-latest}
2023-05-22 09:06:10 +02:00
export PROJECT_NAME="ocean"
2022-01-14 11:31:01 +01:00
export FORCEPULL="false"
2018-12-17 10:22:39 +01:00
# Export LOG LEVEL
export AQUARIUS_LOG_LEVEL=${AQUARIUS_LOG_LEVEL:-INFO}
export PROVIDER_LOG_LEVEL=${PROVIDER_LOG_LEVEL:-INFO}
2022-09-22 22:23:05 +02:00
export SUBGRAPH_LOG_LEVEL=${SUBGRAPH_LOG_LEVEL:-info}
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)
# Specify the ethereum default RPC container provider
2019-10-10 12:28:19 +02:00
if [ ${IP} = "localhost" ]; then
export NETWORK_RPC_HOST="172.15.0.3"
2019-10-10 12:28:19 +02:00
else
export NETWORK_RPC_HOST=${IP}
2019-10-10 12:28:19 +02:00
fi
export NETWORK_RPC_PORT="8545"
export NETWORK_RPC_URL="http://"${NETWORK_RPC_HOST}:${NETWORK_RPC_PORT}
2023-05-15 10:20:52 +02:00
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"}
2023-05-15 10:20:52 +02:00
export GANACHE_INSTAMINE=${GANACHE_INSTAMINE:-"eager"}
export GANACHE_BLOCKTIME=${GANACHE_BLOCKTIME:-0}
export GANACHE_FORK=${GANACHE_FORK:-"istanbul"}
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-10-12 18:16:34 +02:00
export DEPLOY_CONTRACTS=true
2022-02-12 17:34:01 +01:00
export DEPLOY_SUBGRAPH=true
2021-04-30 14:12:13 +02:00
export OCEAN_ARTIFACTS_FOLDER="${OCEAN_HOME}/ocean-contracts/artifacts"
2021-10-27 17:26:28 +02:00
mkdir -p ${OCEAN_ARTIFACTS_FOLDER}
2022-01-14 11:31:01 +01:00
export OCEAN_C2D_FOLDER="${OCEAN_HOME}/ocean-c2d/"
mkdir -p ${OCEAN_C2D_FOLDER}
2023-05-22 09:06:10 +02:00
export OCEAN_SUBGRAPH_FOLDER="${OCEAN_HOME}/ocean-subgraph/"
rm -f "${OCEAN_SUBGRAPH_FOLDER}/ready"
mkdir -p ${OCEAN_SUBGRAPH_FOLDER}
2020-09-15 10:07:35 +02:00
export ADDRESS_FILE="${OCEAN_ARTIFACTS_FOLDER}/address.json"
echo "export ADDRESS_FILE=${ADDRESS_FILE}"
2022-01-14 11:31:01 +01:00
#certs folder
export OCEAN_CERTS_FOLDER="${OCEAN_HOME}/ocean-certs/"
mkdir -p ${OCEAN_CERTS_FOLDER}
# copy certs
cp -r ./certs/* ${OCEAN_CERTS_FOLDER}
2020-09-09 18:25:24 +02:00
# Specify which ethereum client to run or connect to: development
2020-10-12 15:47:51 +02:00
export CONTRACTS_NETWORK_NAME="development"
2018-12-27 15:14:20 +01:00
# Default Aquarius parameters: use Elasticsearch
export EVENTS_MONITOR_SLEEP_TIME=5
export DB_MODULE="elasticsearch"
2022-12-10 08:54:47 +01:00
export DB_HOSTNAME="http://172.15.0.6"
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
2019-02-08 10:57:56 +01:00
2022-02-03 09:40:12 +01:00
export IPFS_GATEWAY=http://172.15.0.16:5001
2022-02-03 12:18:38 +01:00
export IPFS_HTTP_GATEWAY=http://172.15.0.16:8080/ipfs/
2020-06-26 17:37:46 +02:00
#Provider
2023-03-29 22:48:20 +02:00
export REQUEST_TIMEOUT=10
2021-02-15 20:13:16 +01:00
export PROVIDER_WORKERS=10
2023-02-22 10:00:33 +01:00
export PROVIDER_IPFS_GATEWAY=https://gateway.ipfs.io/
2020-09-15 10:07:35 +02:00
export PROVIDER_PRIVATE_KEY=0xfd5c1ccea015b6d663618850824154a3b3fb2882c46cefb05b9a93fea8c3d215
2021-02-13 09:55:45 +01:00
export PROVIDER2_PRIVATE_KEY=0xc852b55146fd168ec3d392bbd70988c18463efa460a395dede376453aca1180e
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
#export OPERATOR_SERVICE_URL=http://127.0.0.1:8050
2022-02-01 13:58:54 +01:00
export OPERATOR_SERVICE_URL=${OPERATOR_SERVICE_URL:-"http://172.15.0.13:31000/"}
2019-12-10 14:48:40 +01: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
# reset
COLOR_RESET="\033[00m"
function show_banner {
local output=$(cat .banner)
echo -e "$COLOR_B$output$COLOR_RESET"
echo ""
}
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 "$OCEAN_ARTIFACTS_FOLDER" | awk '{print $3;}')
if [ "$uid" = "0" ]; then
printf $COLOR_R"WARN: $OCEAN_ARTIFACTS_FOLDER is owned by root\n"$COLOR_RESET >&2
fi
fi
fi
}
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
}
function clean_local_contracts {
rm -f "${OCEAN_ARTIFACTS_FOLDER}/ready"
rm -f "${OCEAN_ARTIFACTS_FOLDER}/*.json"
}
check_if_owned_by_root
show_banner
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"
2020-10-13 10:37:49 +02:00
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/aquarius.yml"
2021-04-09 11:44:50 +02:00
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/elasticsearch.yml"
2022-01-14 11:31:01 +01:00
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/ipfs.yml"
2020-06-26 17:37:46 +02:00
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/provider.yml"
2021-12-06 11:25:45 +01:00
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/redis.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"
DOCKER_COMPOSE_EXTRA_OPTS="${DOCKER_COMPOSE_EXTRA_OPTS:-}"
while :; do
case $1 in
2019-10-10 12:28:19 +02:00
--exposeip)
;;
#################################################
# 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)
export FORCEPULL="true"
printf $COLOR_Y'Pulling the latest revision of the used Docker images...\n\n'$COLOR_RESET
2018-12-17 10:22:39 +01:00
;;
#################################################
# Exclude switches
#################################################
2020-06-26 17:37:46 +02:00
--no-provider)
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/provider.yml/}"
2021-12-06 11:25:45 +01:00
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/redis.yml/}"
2020-06-28 14:15:53 +02:00
printf $COLOR_Y'Starting without Provider...\n\n'$COLOR_RESET
;;
--with-provider2)
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/provider2.yml"
2021-02-13 09:55:45 +01:00
printf $COLOR_Y'Starting with a 2nd Provider...\n\n'$COLOR_RESET
;;
2022-01-14 11:31:01 +01:00
--with-registry)
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/registry.yml"
printf $COLOR_Y'Starting with Registry...\n\n'$COLOR_RESET
;;
--with-c2d)
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/registry.yml"
2022-02-03 11:07:01 +01:00
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/ipfs.yml"
2022-01-14 11:31:01 +01:00
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/c2d.yml"
printf $COLOR_Y'Starting with C2D...\n\n'$COLOR_RESET
;;
2021-06-09 08:46:50 +02:00
--with-rbac)
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/rbac.yml"
printf $COLOR_Y'Starting with RBAC Server...\n\n'$COLOR_RESET
;;
2022-01-14 11:31:01 +01:00
--no-ipfs)
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/ipfs.yml/}"
printf $COLOR_Y'Starting without IPFS...\n\n'$COLOR_RESET
;;
2021-04-09 11:44:50 +02:00
--with-thegraph)
2022-01-14 11:31:01 +01:00
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/thegraph.yml"
2021-04-09 11:44:50 +02:00
printf $COLOR_Y'Starting with TheGraph...\n\n'$COLOR_RESET
;;
2018-12-06 09:16:50 +01:00
--no-aquarius)
2020-10-13 10:47:00 +02:00
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/aquarius.yml/}"
2018-12-06 09:16:50 +01:00
printf $COLOR_Y'Starting without Aquarius...\n\n'$COLOR_RESET
;;
2021-04-09 11:44:50 +02:00
--no-elasticsearch)
COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/elasticsearch.yml/}"
printf $COLOR_Y'Starting without Elastic search...\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
;;
--skip-deploy)
export DEPLOY_CONTRACTS=false
printf $COLOR_Y'Ocean contracts will not be deployed, the last deployment (if any) will be intact ...\n\n'$COLOR_RESET
;;
2022-02-12 17:34:01 +01:00
--skip-subgraph-deploy)
export DEPLOY_SUBGRAPH=false
printf $COLOR_Y'Ocean subgraph will not be deployed, the last deployment (if any) will be intact ...\n\n'$COLOR_RESET
;;
2023-05-15 10:20:52 +02:00
--predictoor)
2023-07-31 17:08:29 +02:00
# Add what we need
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/thegraph.yml"
# We should remove what is not needed for now, but ocean,py requires both aqua & provider
#COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/provider.yml/}"
#COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/redis.yml/}"
#COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/aquarius.yml/}"
#COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/elasticsearch.yml/}"
#COMPOSE_FILES="${COMPOSE_FILES/ -f ${COMPOSE_DIR}\/dashboard.yml/}"
# Enforce images
2023-11-28 08:31:48 +01:00
#export CONTRACTS_VERSION=predictoor
#export SUBGRAPH_VERSION=predictoor
2023-08-03 15:15:19 +02:00
export PDR_BACKEND_VERSION=${PDR_BACKEND_VERSION:-latest}
2023-07-31 17:08:29 +02:00
2023-05-15 10:20:52 +02:00
# replicate true blockchain behiavour
export GANACHE_INSTAMINE=strict
2023-05-15 11:09:10 +02:00
export GANACHE_BLOCKTIME=1
2023-05-15 10:20:52 +02:00
;;
2023-05-22 09:06:10 +02:00
--with-pdr-trueval)
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/pdr-trueval.yml"
printf $COLOR_Y'Starting with pdr-trueval...\n\n'$COLOR_RESET
;;
--with-pdr-trader)
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/pdr-trader.yml"
printf $COLOR_Y'Starting with pdr-trader...\n\n'$COLOR_RESET
;;
--with-pdr-predictoor)
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/pdr-predictoor.yml"
printf $COLOR_Y'Starting with pdr-predictoor...\n\n'$COLOR_RESET
;;
2023-05-24 12:11:15 +02:00
--with-pdr-publisher)
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/pdr-publisher.yml"
printf $COLOR_Y'Starting with pdr-publisher...\n\n'$COLOR_RESET
;;
2023-07-18 13:43:24 +02:00
--with-pdr-dfbuyer)
COMPOSE_FILES+=" -f ${COMPOSE_DIR}/pdr-dfbuyer.yml"
printf $COLOR_Y'Starting with pdr-dfbuyer...\n\n'$COLOR_RESET
;;
#################################################
# Cleaning switches
#################################################
--purge)
2018-12-17 10:22:39 +01:00
printf $COLOR_R'Doing a deep clean ...\n\n'$COLOR_RESET
eval docker-compose --project-name=$PROJECT_NAME "$COMPOSE_FILES" 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
;;
--) # End of all options.
2018-11-29 12:32:38 +01:00
shift
break
;;
-?*)
2018-11-29 12:32:38 +01:00
printf $COLOR_R'WARN: Unknown option (ignored): %s\n'$COLOR_RESET "$1" >&2
break
;;
*)
[ ${CHECK_ELASTIC_VM_COUNT} = "true" ] && check_max_map_count
2021-10-29 14:37:41 +02:00
printf $COLOR_Y'Starting Ocean V4...\n\n'$COLOR_RESET
[ ${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
2024-08-05 08:43:29 +02:00
eval docker compose "$DOCKER_COMPOSE_EXTRA_OPTS" --project-name=$PROJECT_NAME "$COMPOSE_FILES" up --remove-orphans
break
esac
shift
done