-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_script.sh
executable file
·112 lines (99 loc) · 2.81 KB
/
start_script.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
#!/bin/bash
######################
####### CONFIG #######
######################
RPC_ENDPOINT="http://localhost:8545"
TOTAL_WAITING_TIME=45 # seconds
WAIT_FOR_INPUT=true
ROOT_DIR=$(pwd)
######################
function killCompose {
cd $ROOT_DIR
docker-compose down -v
}
function killAndExit {
echo "####### EXITTING... #######"
killCompose
exit 0
}
function graphCreate {
echo '####### DEPLOYING GRAPH #######'
cd wildcards-subgraph && yarn codegen && yarn create-local && yarn deploy-local
if [ "$?" -ne 0 ];
then
echo "ERROR: Could not deploy graph successfully - please fix graph errors and press 'g'"
fi
cd ..
}
function graphRedeploy {
echo '####### REDEPLOYING GRAPH #######'
cd wildcards-subgraph && yarn codegen && yarn deploy-local
if [ "$?" -ne 0 ];
then
echo "ERROR: Could not redeploy graph successfully - please fix graph errors and press 'g'"
fi
cd ..
}
function doneLoop {
echo "######################"
echo "######## DONE ########"
if [ $WAIT_FOR_INPUT = true ]; then
echo "####### PRESS R to RESTART ######"
echo "# PRESS G to REDEPLOY the graph #"
echo "######## PRESS Q to QUIT ########"
fi
echo "######################"
if [ $WAIT_FOR_INPUT = true ]; then
waitForInput
fi
}
function start {
echo "####### CLEANUP #######"
rm -rf data ganache-data
rm -f contracts/.openzeppelin/dev-321.json
echo "####### DOCKER-COMPOSE #######"
docker-compose up 2>&1 > /dev/null &
DOCKER_COMPOSE_UP_PID=$!
echo "####### WAITING FOR DOCKERS #######"
WAITING_TIME=0
until $(curl --output /dev/null -X POST --silent --fail -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' $RPC_ENDPOINT); do
SLEEP_AMOUNT=3
sleep $SLEEP_AMOUNT
WAITING_TIME=$(($WAITING_TIME+$SLEEP_AMOUNT))
if [ "$WAITING_TIME" -gt "$TOTAL_WAITING_TIME" ];
then
echo "ERROR: Could not reach ETH chain"
killAndExit
fi;
done
echo "####### DEPLOYING CONTRACTS #######"
cd contracts && truffle migrate --reset --network subgraphTest
if [ "$?" -ne 0 ];
then
echo "ERROR: Could not deploy contracts successfully"
killAndExit
fi
cd ..
graphCreate
doneLoop
}
function waitForInput {
while [ true ] ; do
read -n 1 k <&1
if [[ $k == "q" || $k == "Q" ]]; then
echo ""
killAndExit
elif [[ $k == "r" || $k == "R" ]]; then
echo ""
echo "######## RESTARTING ALL ########"
killCompose
sleep 3
start
elif [[ $k == "g" || $k == "G" ]]; then
echo ""
graphRedeploy
doneLoop
fi
done
}
start