Skip to content

Commit 75431dd

Browse files
committed
Docker: added wait-for-it to start goloop before provision & Readme changes
1 parent 22e7ffa commit 75431dd

File tree

4 files changed

+190
-3
lines changed

4 files changed

+190
-3
lines changed

devnet/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It's configured for one sealer account to allow running single node.
1111
docker build --tag bsc-node ./devnet/docker/bsc-node --build-arg KEYSTORE_PASS=<SECRET>
1212
```
1313

14-
Note: The docker folder contains test accounts which are copied during the docker build in the provisioning step.
14+
Note: The <SECRET> to unlock existing keystore is "Perlia0". The docker folder contains test accounts which are copied during the docker build in the provisioning step.
1515

1616
See [this page](https://geth.ethereum.org/docs/interface/managing-your-accounts) for information on how to create Ethereum accounts.
1717

devnet/docker/icon-bsc/provision.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export SCRIPTS_DIR=${SCRIPTS_DIR:-${BTPSIMPLE_SCRIPTS_DIR}}
99

1010
export BSC_NID="0x97"
1111
export BSC_BMC_NET="0x97.bsc"
12-
export BSC_RPC_URI=http://goloop:9080/api/v3/icon
1312

1413
# configure env in the container
1514
export GOLOOP_RPC_URI=http://goloop:9080/api/v3/icon
15+
export GOLOOP_RPC_ADMIN_URI=http://goloop:9080/admin/system
1616
export GOLOOP_CONFIG=$CONFIG_DIR/goloop.server.json
1717
export GOLOOP_KEY_STORE=$CONFIG_DIR/goloop.keystore.json
1818
export GOLOOP_KEY_SECRET=$CONFIG_DIR/goloop.keysecret
@@ -424,5 +424,6 @@ wait_for_file() {
424424
echo "waiting for the output file: $FILE_NAME"
425425
done
426426
}
427+
wait-for-it.sh $GOLOOP_RPC_ADMIN_URI
427428
# run provisioning
428429
provision

devnet/docker/icon-bsc/wait-for-it.sh

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
#!/bin/sh
2+
3+
# The MIT License (MIT)
4+
#
5+
# Copyright (c) 2017 Eficode Oy
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
set -- "$@" -- "$TIMEOUT" "$QUIET" "$PROTOCOL" "$HOST" "$PORT" "$result"
26+
TIMEOUT=15
27+
QUIET=0
28+
# The protocol to make the request with, either "tcp" or "http"
29+
PROTOCOL="tcp"
30+
31+
echoerr() {
32+
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
33+
}
34+
35+
usage() {
36+
exitcode="$1"
37+
cat << USAGE >&2
38+
Usage:
39+
$0 host:port|url [-t timeout] [-- command args]
40+
-q | --quiet Do not output any status messages
41+
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
42+
-- COMMAND ARGS Execute command with args after the test finishes
43+
USAGE
44+
exit "$exitcode"
45+
}
46+
47+
wait_for() {
48+
case "$PROTOCOL" in
49+
tcp)
50+
if ! command -v nc >/dev/null; then
51+
echoerr 'nc command is missing!'
52+
exit 1
53+
fi
54+
;;
55+
wget)
56+
if ! command -v wget >/dev/null; then
57+
echoerr 'wget command is missing!'
58+
exit 1
59+
fi
60+
;;
61+
esac
62+
63+
while :; do
64+
case "$PROTOCOL" in
65+
tcp)
66+
nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1
67+
;;
68+
http)
69+
wget --timeout=1 -q "$HOST" -O /dev/null > /dev/null 2>&1
70+
;;
71+
*)
72+
echoerr "Unknown protocol '$PROTOCOL'"
73+
exit 1
74+
;;
75+
esac
76+
77+
result=$?
78+
79+
if [ $result -eq 0 ] ; then
80+
if [ $# -gt 7 ] ; then
81+
for result in $(seq $(($# - 7))); do
82+
result=$1
83+
shift
84+
set -- "$@" "$result"
85+
done
86+
87+
TIMEOUT=$2 QUIET=$3 PROTOCOL=$4 HOST=$5 PORT=$6 result=$7
88+
shift 7
89+
exec "$@"
90+
fi
91+
exit 0
92+
fi
93+
94+
if [ "$TIMEOUT" -le 0 ]; then
95+
break
96+
fi
97+
TIMEOUT=$((TIMEOUT - 1))
98+
99+
sleep 1
100+
done
101+
echo "Operation timed out" >&2
102+
exit 1
103+
}
104+
105+
while :; do
106+
case "$1" in
107+
http://*|https://*)
108+
HOST="$1"
109+
PROTOCOL="http"
110+
shift 1
111+
;;
112+
*:* )
113+
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
114+
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
115+
shift 1
116+
;;
117+
-q | --quiet)
118+
QUIET=1
119+
shift 1
120+
;;
121+
-q-*)
122+
QUIET=0
123+
echoerr "Unknown option: $1"
124+
usage 1
125+
;;
126+
-q*)
127+
QUIET=1
128+
result=$1
129+
shift 1
130+
set -- -"${result#-q}" "$@"
131+
;;
132+
-t | --timeout)
133+
TIMEOUT="$2"
134+
shift 2
135+
;;
136+
-t*)
137+
TIMEOUT="${1#-t}"
138+
shift 1
139+
;;
140+
--timeout=*)
141+
TIMEOUT="${1#*=}"
142+
shift 1
143+
;;
144+
--)
145+
shift
146+
break
147+
;;
148+
--help)
149+
usage 0
150+
;;
151+
-*)
152+
QUIET=0
153+
echoerr "Unknown option: $1"
154+
usage 1
155+
;;
156+
*)
157+
QUIET=0
158+
echoerr "Unknown argument: $1"
159+
usage 1
160+
;;
161+
esac
162+
done
163+
164+
if ! [ "$TIMEOUT" -ge 0 ] 2>/dev/null; then
165+
echoerr "Error: invalid timeout '$TIMEOUT'"
166+
usage 3
167+
fi
168+
169+
case "$PROTOCOL" in
170+
tcp)
171+
if [ "$HOST" = "" ] || [ "$PORT" = "" ]; then
172+
echoerr "Error: you need to provide a host and port to test."
173+
usage 2
174+
fi
175+
;;
176+
http)
177+
if [ "$HOST" = "" ]; then
178+
echoerr "Error: you need to provide a host to test."
179+
usage 2
180+
fi
181+
;;
182+
esac
183+
184+
wait_for "$@"

doc/bsc-guide.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ navigate to btp directory
5858
make
5959
```
6060

61+
Note: In case make fails with "missing go.sum entry" with go-ethereum, tt can be fixed by manually adding `go mod download github.com/ethereum/go-ethereum`.
62+
6163
### Build JavaScore Contracts
6264
from btp directory, run
6365
```
@@ -94,7 +96,7 @@ Build with docker-compose using the following script
9496

9597
Once build is complete, start docker-compose
9698
```
97-
docker-compose up
99+
docker-compose up -d
98100
```
99101
If all successful, this should start docker network containing provisioned
100102
goloop, binance smart chain and BSC ICON BTP relayer.

0 commit comments

Comments
 (0)