This repository has been archived by the owner on May 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathlaunch.bash
executable file
·155 lines (142 loc) · 4.05 KB
/
launch.bash
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
#!/bin/bash
function help() {
echo "Launches Enigma Docker Network."
echo
echo "Usage:"
echo " $0 [-t] [-d] [-h] [-s] [-q]"
echo
echo "Options:"
echo " -c Test enigma network with sample coin-mixer contract."
echo " -d Run in development mode."
echo " -h Show this help."
echo " -t Spawn a terminal for every container/process."
echo " -q Stops Enigma Docker Network and removes containers."
echo " -s Run in simulation mode."
}
function check_config() {
if [ ! -f .env ]; then
echo 'Creating .env file from template'
cp .env-template .env
fi
}
function check_contractfolder() {
source .env
if [ ! -d "$GIT_FOLDER_CONTRACT" ]; then
echo "\"$GIT_FOLDER_CONTRACT\" does not exist."
echo "Please edit the \".env\" file and configure GIT_FOLDER_CONTRACT to point to your local copy of a valid Enigma contract repository."
exit 1
fi
}
function build_images() {
# Force rebuild of images every run
docker-compose $ARGF build
if [[ ! $? -eq 0 ]]; then
echo 'Build of docker images failed. Exiting.'
exit 1
fi
}
function boot_images() {
docker-compose $ARGF up &
echo 'Waiting for containers to start...'
sleep 5
if [ $TERMINALS ]; then
xterm -T 'Enigma Contract' -geometry 90x20+20+20 -e "docker attach enigma_contract_1" &
xterm -T 'Enigma Core' -geometry 120x20+600+20 -e "docker attach enigma_core_1" &
fi
}
function deploy_contract() {
echo 'Waiting for contract to be available...'
CONTRACT_IP='localhost'
while :
do
curl -s $CONTRACT_IP:8545 > /dev/null
result=$?
if [[ $result -eq 0 ]]; then
break
fi
sleep 5
done
echo "Deploying contracts on testnet..."
if [ $DEVELOP ]; then
source .env
pushd $GIT_FOLDER_CONTRACT
rm -rf build/contracts/*
darq-truffle migrate --reset --network development -f 1 --to 2
if [ $COINMIXER ]; then
darq-truffle migrate --reset --network development -f 3 --to 3
fi
popd
else
docker-compose exec contract bash -c "rm -rf ~/enigma-contract/build/contracts/*"
docker-compose exec contract bash -c "cd enigma-contract && darq-truffle migrate --reset --network ganache -f 1 --to 2"
if [ $COINMIXER ]; then
docker-compose exec contract bash -c "cd enigma-contract && darq-truffle migrate --reset --network development -f 3 --to 3"
fi
fi
docker-compose exec -d contract bash -c "./simpleHTTP1.bash"
docker-compose exec -d contract bash -c "./simpleHTTP2.bash"
}
function start_surface() {
echo "Starting Surface..."
if [ $TERMINALS ]; then
xterm -T 'Enigma Surface' -geometry 120x20+900+80 \
-e "docker-compose exec surface bash -c ./wait_launch.bash" &
else
docker-compose exec -d surface bash -c ./wait_launch.bash
fi
}
function start_app() {
if [ $COINMIXER ]; then
echo "Starting coin-mixer app..."
APP_CMD="cd enigma-contract && node integration/coin-mixer.js --url=http://enigma_contract_1:8545"
if [ $TERMINALS ]; then
xterm -T 'Enigma DApp' -geometry 152x20+20+330 -e "docker-compose exec contract bash -c \"$APP_CMD; bash\"" &
else
docker-compose exec -d contract bash -c "$APP_CMD"
fi
else
echo 'Ready to launch your app.'
fi
}
function launch() {
build_images
boot_images
deploy_contract
start_surface
start_app
}
check_config
# By default we run in HW mode, which can be overriden through option below
sed -e 's/SGX_MODE=.*/SGX_MODE=HW/g' .env > .env.tmp && mv .env.tmp .env
SIMUL=''
COINMIXER=''
ARGF="-f docker-compose.yml"
while getopts ":dhqst" opt; do
case $opt in
c) COINMIXER=True;;
d) check_contractfolder
ARGF="$ARGF -f docker-compose.develop.yml"
DEVELOP=True;;
h) help
exit 0;;
q) docker-compose down
exit 0;;
s) SIMUL=True
sed -e 's/SGX_MODE=.*/SGX_MODE=SW/g' .env > .env.tmp && mv .env.tmp .env;;
t) TERMINALS=True;;
\?) echo "Invalid option: -$OPTARG" >&2
exit 1;;
esac
done
if [ ! $SIMUL ]; then
if [ ! -c /dev/isgx ]; then
echo "Error: SGX driver not found. Run in simulation mode instead with:"
echo "$0 $@ -s"
exit 1
fi
ARGF="$ARGF -f docker-compose.hw.yml"
fi
if [ ! $DEVELOP ]; then
ARGF="$ARGF -f docker-compose.override.yml"
fi
launch