Skip to content

Commit 3d63c7f

Browse files
committed
Add healthcheck to CI containers
To prevent geth containers from getting stuck Signed-off-by: Takeshi Arabiki <takeshi.arabiki@datachain.jp>
1 parent eb89c55 commit 3d63c7f

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

e2e/chains/bsc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ bootstrap:
1010

1111
.PHONY:network
1212
network:
13+
docker compose -f docker-compose.simple.yml up -d autoheal
1314
docker compose -f docker-compose.simple.yml up -d bsc-rpc bsc-validator1-1 bsc-validator1-2 bsc-validator1-3 bsc-validator1-4 bsc-validator1-5
1415
docker compose -f docker-compose.simple.yml up -d bsc-rpc2 bsc-validator2-1 bsc-validator2-2 bsc-validator2-3
1516

e2e/chains/bsc/docker-compose.simple.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ services:
7171
- ./scripts:/scripts
7272
- ./config:/config
7373
command: ash /scripts/bsc-rpc.sh
74+
healthcheck:
75+
test: ["CMD", "ash", "/scripts/healthcheck.sh"]
76+
interval: "5s"
77+
start_period: "10s"
7478

7579
bsc-rpc2: # This is the bootstrap node
7680
image: bsc-geth:docker-local
@@ -86,6 +90,10 @@ services:
8690
- ./scripts:/scripts
8791
- ./config:/config
8892
command: ash /scripts/bsc-rpc.sh
93+
healthcheck:
94+
test: ["CMD", "ash", "/scripts/healthcheck.sh"]
95+
interval: "5s"
96+
start_period: "10s"
8997

9098
bsc-validator1-1:
9199
image: bsc-geth:docker-local
@@ -217,6 +225,14 @@ services:
217225
- ./scripts:/scripts
218226
command: ash /scripts/bsc-validator.sh
219227

228+
autoheal:
229+
restart: always
230+
image: willfarrell/autoheal
231+
environment:
232+
- AUTOHEAL_CONTAINER_LABEL=all
233+
volumes:
234+
- /var/run/docker.sock:/var/run/docker.sock
235+
220236
networks:
221237
bsc:
222238
ipam:
@@ -227,4 +243,4 @@ networks:
227243
ipam:
228244
driver: default
229245
config:
230-
- subnet: 99.98.0.0/16
246+
- subnet: 99.98.0.0/16

e2e/chains/bsc/scripts/bsc-rpc.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ while [ "$i" -lt ${account_cnt} ]; do
1313
done
1414

1515
ETHSTATS=""
16-
geth --config ${DATA_DIR}/config.toml --datadir ${DATA_DIR} --netrestrict ${CLUSTER_CIDR} \
16+
# Use exec to handle signals
17+
exec geth --config ${DATA_DIR}/config.toml --datadir ${DATA_DIR} --netrestrict ${CLUSTER_CIDR} \
1718
--state.scheme=hash --db.engine=leveldb --verbosity ${VERBOSE} --nousb ${ETHSTATS} \
1819
--unlock ${unlock_sequences} --password /dev/null --ipcpath /gethipc --override.fixedturnlength 2

e2e/chains/bsc/scripts/bsc-validator.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ HOST_IP=$(hostname -i)
1010
echo "validator id: ${HOST_IP}"
1111

1212
ETHSTATS=""
13-
geth --config ${DATA_DIR}/config.toml --datadir ${DATA_DIR} --netrestrict ${CLUSTER_CIDR} \
13+
# Use exec to handle signals
14+
exec geth --config ${DATA_DIR}/config.toml --datadir ${DATA_DIR} --netrestrict ${CLUSTER_CIDR} \
1415
--verbosity ${VERBOSE} --nousb ${ETHSTATS} --state.scheme=hash --db.engine=leveldb \
1516
--bootnodes enode://${BOOTSTRAP_PUB_KEY}@${BOOTSTRAP_IP}:${BOOTSTRAP_TCP_PORT} \
1617
--mine --miner.etherbase=${VALIDATOR_ADDR} -unlock ${VALIDATOR_ADDR} --password /dev/null --blspassword /scripts/wallet_password.txt \
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
timestamp=$(geth attach --exec 'parseInt(eth.getBlockByNumber("latest").timestamp)' /gethipc)
6+
[ $(($(date '+%s') - $timestamp)) -lt 5 ]

0 commit comments

Comments
 (0)