-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuild.sh
executable file
·408 lines (372 loc) · 13.1 KB
/
build.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
#!/bin/bash
set -e
########################################################
build_all_images_for_local_deployment() {
if [ -f local/goloop ] || [ -f local/log ] || [ -f local/artifacts ]; then
echo "Previous deployment artifacts exist on local/{goloop,log,artifacts}. Clean using sudo make cleaimglocal. Then runimglocal"
exit 0
fi
echo "Start building docker containers for iconbridge, bsc and icon nodes"
#make -C ../../../ dist-javascore dist-sol iconbridge-image
mkdir -p ./data/bsc/node1
export DOCKER_DEFAULT_PLATFORM=linux/amd64
echo "Build BMR"
cd ../../..
docker build -f ./devnet/docker/icon-bsc/Dockerfile -t iconbridge_bsc:latest .
echo "Build BSC"
docker build --tag bsc-node ./devnet/docker/bsc-node --build-arg KEYSTORE_PASS=Perlia0
echo "Build ICON"
cd ./devnet/docker/goloop
docker build --tag icon-bsc_goloop:latest .
echo "Build Process Complete"
echo "To run the containers. Use command: make runimglocal"
echo "This will deploy the smart contracts on the locally deployed containers and run relay"
}
run_all_images_for_local_deployment() {
if [ -f local/goloop ] || [ -f local/log ] || [ -f local/artifacts ]; then
echo "Previous deployment artifacts exist on local/{goloop,log,artifacts}. Clean using sudo make cleaimglocal. Then runimglocal"
exit 0
fi
docker-compose -f docker-compose.yml up --remove-orphans -d
sleep 5
echo "Containers are running. Check progress with docker logs command"
}
clean_artifacts_of_local_deployment() {
echo "Cleaning Artifacts. Might require sudo privilege if not used i.e. sudo make cleanimglocal"
sleep 2
docker-compose down -v --remove-orphans
rm -rf local/artifacts
rm -rf local/goloop
rm -rf local/log
rm -rf data/bsc/node1
}
remove_artifacts_of_local_deployment() {
echo "Removing Artifacts. Might require sudo privilege if not used i.e. sudo make removeimglocal"
sleep 2
docker-compose down -v --remove-orphans
docker rmi -f icon-bsc_btp
docker rm -f javascore-dist
docker rmi -f iconbridge
docker rmi -f btp/javascore
rm -rf local/artifacts
rm -rf local/log
rm -rf local/goloop
rm -rf data/bsc/node1
}
########################################################
build_smart_contracts() {
echo "Creating build artifacts on PC"
#Run the script from icon-bridge/devnet/docker/icon-bsc
local ICON_BSC_DIR=${PWD}
local ROOT_DIR=$(echo "$(
cd "$(dirname "../../../../")"
pwd
)")
local BUILD_DIR=$ICON_BSC_DIR/build
local KEYSTORE_DIR=$ICON_BSC_DIR/_ixh/keystore
if [ ${#buildsuffix} != 0 ]; then
if [ ${buildsuffix} != "arctic" ]; then
echo "Accepted buildsuffix: arctic. Got ${buildsuffix}"
exit 0
fi
BUILD_DIR+=$buildsuffix
KEYSTORE_DIR=$ICON_BSC_DIR/_ixh_${buildsuffix}/keystore
fi
echo $BUILD_DIR
if [ -d $BUILD_DIR ]; then
echo "Save Previous Build Artifacts"
local datesuffix=$(date +%s)
mv $BUILD_DIR ${BUILD_DIR}_${datesuffix}
fi
local CONTRACTS_DIR="$BUILD_DIR/contracts"
local JAVASCORE_DIR="$CONTRACTS_DIR/javascore"
local SOLIDITY_DIR="$CONTRACTS_DIR/solidity"
mkdir -p "$JAVASCORE_DIR"
mkdir -p "$SOLIDITY_DIR"
mkdir -p "$KEYSTORE_DIR"
echo "Creating go build artifacts"
cd $ROOT_DIR/cmd/iconvalidators/
go build .
mv iconvalidators $ICON_BSC_DIR/
echo "Creating java build artifacts"
# build contracts
cd $ROOT_DIR/javascore
gradle clean
gradle bmc:optimizedJar
gradle bts:optimizedJar
cp bmc/build/libs/bmc-optimized.jar $JAVASCORE_DIR/bmc.jar
cp bts/build/libs/bts-optimized.jar $JAVASCORE_DIR/bts.jar
cp lib/irc2Tradeable-0.1.0-optimized.jar $JAVASCORE_DIR/irc2Tradeable.jar
# irc2-token
cd $ROOT_DIR
git clone https://github.com/icon-project/java-score-examples.git
cd java-score-examples
gradle irc2-token:clean
gradle irc2-token:optimizedJar
cp irc2-token/build/libs/irc2-token-0.9.1-optimized.jar $JAVASCORE_DIR/irc2.jar
rm -rf $ROOT_DIR/java-score-examples
echo "Creating solidity build artifacts"
# copy solidity
cp -r $ROOT_DIR/solidity/{bmc,bts} $SOLIDITY_DIR/
cd $SOLIDITY_DIR
cd bmc && yarn install
cd ..
cd bts && yarn install
echo "Build Artifacts have been created on path "$BUILD_DIR
}
build_chain_nodes() {
echo "Start building docker containers for bsc and icon nodes"
#make -C ../../../ dist-javascore dist-sol iconbridge-image
mkdir -p ./data/bsc/node1
export DOCKER_DEFAULT_PLATFORM=linux/amd64
cd ../../..
echo "Build BSC"
docker build --tag bsc-node ./devnet/docker/bsc-node --build-arg KEYSTORE_PASS=Perlia0
echo "Build ICON"
cd ./devnet/docker/goloop
docker build --tag icon-bsc_goloop:latest .
echo "Build Process Complete"
echo "To run the blockchain nodes. Use command: make runnodes"
}
run_chain_nodes() {
echo "Running block chain nodes locally"
docker-compose -f docker-compose-nodes.yml up -d
sleep 5
local ICON_BSC_DIR=${PWD}
if [ -d $ICON_BSC_DIR/_ixh ]; then
echo "Save Previous Deployment Artifacts"
local suffix=$(date +%s)
mv $ICON_BSC_DIR/_ixh $ICON_BSC_DIR/_ixh_${suffix}
fi
mkdir -p $ICON_BSC_DIR/_ixh/keystore
echo "Fetching GodKeys from blockChain nodes"
docker cp goloop:/goloop/config/goloop.keystore.json $ICON_BSC_DIR/_ixh/keystore/icon.god.wallet.json
docker cp goloop:/goloop/config/goloop.keysecret $ICON_BSC_DIR/_ixh/keystore/icon.god.wallet.secret
docker cp goloop:/goloop/config/nid.icon $ICON_BSC_DIR/_ixh/nid.icon
docker cp binancesmartchain:/bsc/keystore/UTC--2021-07-14T19-55-36.108252000Z--70e789d2f5d469ea30e0525dbfdd5515d6ead30d $ICON_BSC_DIR/_ixh/keystore/bsc.god.wallet.json
echo -n "Perlia0" >$ICON_BSC_DIR/_ixh/keystore/bsc.god.wallet.secret
ethkey inspect --json --private --passwordfile $ICON_BSC_DIR/_ixh/keystore/bsc.god.wallet.secret $ICON_BSC_DIR/_ixh/keystore/bsc.god.wallet.json | jq -r .PrivateKey >$ICON_BSC_DIR/_ixh/keystore/bsc.god.wallet.json.priv
echo "Nodes running"
docker ps --filter name=goloop --filter name=binancesmartchain
echo "Wait 1 minute before deploying smart contracts to ensure nodes have initialized"
}
clean_deployment_artifacts() {
echo "cleaning deployment artifacts. Move _ixh folder but retain _ixh/keystore"
ICON_BSC_DIR=${PWD}
if [ -d $ICON_BSC_DIR/_ixh ]; then
echo "Save Previous Deployment Artifacts"
local suffix=$(date +%s)
mv $ICON_BSC_DIR/_ixh $ICON_BSC_DIR/_ixh_${suffix}
if [ -d $ICON_BSC_DIR/_ixh_${suffix}/keystore ]; then
mkdir -p $ICON_BSC_DIR/_ixh
echo "Backup "$ICON_BSC_DIR/_ixh_${suffix}/keystore " inside "$ICON_BSC_DIR/_ixh/
cp -r $ICON_BSC_DIR/_ixh_${suffix}/keystore $ICON_BSC_DIR/_ixh/keystore
fi
fi
echo "Finished cleaning. Deploy new set of contracts with make runsc"
}
deploy_smart_contracts() {
echo "Deploying contracts. ./deploysc.sh"
cd scripts
if [[ $1 == "mainnet" || $1 == "testnet" ]]; then
if [ ! -f config_temp.sh ]; then
cp config.sh config_temp.sh
cp config/icon-bsc.config.$1.sh config.sh
fi
else
echo "Invalid network. Specify net=mainnet or testnet."
exit 0
fi
exists=$(cat config.sh | grep TAG | grep BSC | grep -i ${1} | wc -l)
if [ $exists == "0" ]; then
echo "Invalid Configuration. Check TAG of config file."
exit
fi
./deploysc.sh
if [ -f config_temp.sh ]; then
mv config_temp.sh config.sh
fi
}
deploy_smart_contracts_on_localnet() {
echo "Deploying contracts. ./deploysc.sh"
cd scripts
if [ ! -f config_testnet.sh ]; then
cp config.sh config_testnet.sh
cp config/icon-bsc.config.localnet.sh config.sh
fi
./deploysc.sh
if [ -f config_testnet.sh ]; then
mv config_testnet.sh config.sh
fi
}
deploy_smart_contracts_on_arctic() {
cd scripts
if [[ $1 == "mainnet" || $1 == "testnet" ]]; then
if [ ! -f config_temp.sh ]; then
cp config.sh config_temp.sh
cp config/icon-snow.config.$1.sh config.sh
fi
else
echo "Invalid network. Specify net=mainnet or testnet."
exit 0
fi
exists=$(cat config.sh | grep TAG | grep SNOW | grep -i ${1} | wc -l)
if [ $exists == "0" ]; then
echo "Invalid Configuration. Check TAG of config file."
exit
fi
./deploy_arctic.sh
if [ -f config_temp.sh ]; then
mv config_temp.sh config.sh
fi
}
########################################################
########################################################
audit_fixes_bsc() {
cd scripts
if [[ $1 == "mainnet" || $1 == "testnet" ]]; then
if [ ! -f config_temp.sh ]; then
cp config.sh config_temp.sh
cp config/icon-bsc.config.$1.sh config.sh
fi
else
echo "Invalid network. Specify net=mainnet or testnet."
exit 0
fi
exists=$(cat config.sh | grep TAG | grep BSC | grep -i ${1} | wc -l)
if [ $exists == "0" ]; then
echo "Invalid Configuration. Check TAG of config file."
exit
fi
./solidity_audit_fixes.sh
if [ -f config_temp.sh ]; then
mv config_temp.sh config.sh
fi
}
audit_fixes_arctic() {
cd scripts
if [[ $1 == "mainnet" || $1 == "testnet" ]]; then
if [ ! -f config_temp.sh ]; then
cp config.sh config_temp.sh
cp config/icon-snow.config.$1.sh config.sh
fi
else
echo "Invalid network. Specify net=mainnet or testnet."
exit 0
fi
exists=$(cat config.sh | grep TAG | grep SNOW | grep -i ${1} | wc -l)
if [ $exists == "0" ]; then
echo "Invalid Configuration. Check TAG of config file."
exit
fi
./solidity_audit_fixes.sh
if [ -f config_temp.sh ]; then
mv config_temp.sh config.sh
fi
}
audit_fixes_icon() {
cd scripts
if [[ $1 == "mainnet" || $1 == "testnet" ]]; then
if [ ! -f config_temp.sh ]; then
cp config.sh config_temp.sh
cp config/icon-bsc.config.$1.sh config.sh
fi
else
echo "Invalid network. Specify net=mainnet or testnet."
exit 0
fi
# upgrade both BTS and BMC contract
./upgrade.javascore.sh --bmc
./upgrade.javascore.sh --bts
if [ -f config_temp.sh ]; then
mv config_temp.sh config.sh
fi
echo "Done deploying ICON Audit Fixes"
}
########################################################
build_relay_img() {
echo "Build BMR"
cd ../../..
docker build -t localnets:5000/bmr:latest -f devnet/docker/icon-bsc/bmr.Dockerfile .
}
run_relay_img() {
local relayConfigPath=${PWD}/_ixh/bmr.config.json
if [ ! -f $relayConfigPath ]; then
echo "relay config does not exist on path "$relayConfigPath
exit 0
fi
cp $relayConfigPath ./bmr.config.json
docker-compose -f docker-compose-bmr.yml up -d
sleep 5
rm bmr.config.json
echo "Relay Running"
docker ps --filter name=bmr
}
run_relay_from_source() {
local relayConfigPath=${PWD}/_ixh/bmr.config.json
if [ ! -f $relayConfigPath ]; then
echo "relay config does not exist on path "$relayConfigPath
exit 0
fi
cd ../../../cmd/iconbridge/
go run . -config $relayConfigPath
}
run_e2e_tests() {
local e2eConfigPath=${PWD}/_ixh/e2e.config.json
if [ ! -f $e2eConfigPath ]; then
echo "e2e config does not exist on path "$e2eConfigPath
exit 0
fi
cd ../../../cmd/e2etest/
go run . -config $e2eConfigPath
}
stop_relay_img() {
docker-compose -f docker-compose-bmr.yml down
}
stop_chain_nodes() {
docker-compose -f docker-compose-nodes.yml down
}
########################################################
if [ $# -eq 0 ]; then
echo "No arguments supplied. Check README for details"
elif [ $1 == "buildimglocal" ]; then
build_all_images_for_local_deployment
elif [ $1 == "runimglocal" ]; then
run_all_images_for_local_deployment
elif [ $1 == "cleanimglocal" ]; then
clean_artifacts_of_local_deployment
elif [ $1 == "removeimglocal" ]; then
remove_artifacts_of_local_deployment
elif [ $1 == "buildsc" ]; then
build_smart_contracts
elif [ $1 == "buildnodes" ]; then
build_chain_nodes
elif [ $1 == "runnodes" ]; then
run_chain_nodes
elif [ $1 == "stopnodes" ]; then
stop_chain_nodes
elif [ $1 == "deploysc" ]; then
deploy_smart_contracts $2
elif [ $1 == "deploysclocalnet" ]; then
deploy_smart_contracts_on_localnet
elif [ $1 == "runrelaysrc" ]; then
run_relay_from_source
elif [ $1 == "rune2etests" ]; then
run_e2e_tests
elif [ $1 == "cleanartifacts" ]; then
clean_deployment_artifacts
elif [ $1 == "buildrelayimg" ]; then
build_relay_img
elif [ $1 == "runrelayimg" ]; then
run_relay_img
elif [ $1 == "stoprelayimg" ]; then
stop_relay_img
elif [ $1 == "deployscarctic" ]; then
deploy_smart_contracts_on_arctic $2
elif [ $1 == "bscaudit" ]; then
audit_fixes_bsc $2
elif [ $1 == "iconaudit" ]; then
audit_fixes_icon $2
elif [ $1 == "arcticaudit" ]; then
audit_fixes_arctic $2
fi