Skip to content

Commit f9ee48e

Browse files
committed
bera-geth skip init if home folder already there
1 parent 9fb50c1 commit f9ee48e

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

scripts/build/testing.mk

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
# ask_reset_dir_func checks if the directory passed in exists, and if so asks the user whether it
88
# should delete it. Note that on linux, docker may have created the directory with root
99
# permissions, so we may need to ask the user to delete it with sudo
10+
# Creates a flag file to indicate if the directory was reset
1011
define ask_reset_dir_func
1112
@abs_path=$(abspath $(1)); \
13+
rm -f .tmp/.dir_was_reset; \
1214
if test -d "$$abs_path"; then \
1315
read -p "Directory '$$abs_path' exists. Do you want to delete it? (y/n): " confirm && \
1416
if [ "$$confirm" = "y" ]; then \
@@ -17,10 +19,13 @@ define ask_reset_dir_func
1719
if test -d "$$abs_path"; then \
1820
echo "Failed to delete directory '$$abs_path'."; \
1921
exit 1; \
22+
else \
23+
mkdir -p .tmp && touch .tmp/.dir_was_reset; \
2024
fi; \
2125
fi \
2226
else \
2327
echo "Directory '$$abs_path' does not exist."; \
28+
mkdir -p .tmp && touch .tmp/.dir_was_reset; \
2429
fi
2530
endef
2631

@@ -76,12 +81,18 @@ start-reth:
7681
## Start an ephemeral `geth` node with docker
7782
start-geth:
7883
$(call ask_reset_dir_func, $(ETH_DATA_DIR))
79-
docker run \
80-
--rm -v $(PWD)/${TESTAPP_FILES_DIR}:/${TESTAPP_FILES_DIR} \
81-
-v $(PWD)/.tmp:/.tmp \
82-
ghcr.io/berachain/bera-geth:latest init \
83-
--datadir ${ETH_DATA_DIR} \
84-
${ETH_GENESIS_PATH}
84+
@if [ -f .tmp/.dir_was_reset ]; then \
85+
echo "Initializing geth..."; \
86+
docker run \
87+
--rm -v $(PWD)/${TESTAPP_FILES_DIR}:/${TESTAPP_FILES_DIR} \
88+
-v $(PWD)/.tmp:/.tmp \
89+
ghcr.io/berachain/bera-geth:latest init \
90+
--datadir ${ETH_DATA_DIR} \
91+
${ETH_GENESIS_PATH}; \
92+
rm -f .tmp/.dir_was_reset; \
93+
else \
94+
echo "Skipping geth init (directory was not reset)"; \
95+
fi
8596

8697
docker run \
8798
-p 30303:30303 \
@@ -114,13 +125,19 @@ start-bepolia:
114125

115126
start-geth-bepolia:
116127
$(call ask_reset_dir_func, $(ETH_DATA_DIR))
117-
docker run \
118-
--rm -v $(PWD)/${TESTAPP_FILES_DIR}:/${TESTAPP_FILES_DIR} \
119-
--rm -v $(PWD)/${BEPOLIA_NETWORK_FILES_DIR}:/${BEPOLIA_NETWORK_FILES_DIR} \
120-
-v $(PWD)/.tmp:/.tmp \
121-
ghcr.io/berachain/bera-geth:latest init \
122-
--datadir ${ETH_DATA_DIR} \
123-
${BEPOLIA_ETH_GENESIS_PATH}
128+
@if [ -f .tmp/.dir_was_reset ]; then \
129+
echo "Initializing geth..."; \
130+
docker run \
131+
--rm -v $(PWD)/${TESTAPP_FILES_DIR}:/${TESTAPP_FILES_DIR} \
132+
--rm -v $(PWD)/${BEPOLIA_NETWORK_FILES_DIR}:/${BEPOLIA_NETWORK_FILES_DIR} \
133+
-v $(PWD)/.tmp:/.tmp \
134+
ghcr.io/berachain/bera-geth:latest init \
135+
--datadir ${ETH_DATA_DIR} \
136+
${BEPOLIA_ETH_GENESIS_PATH}; \
137+
rm -f .tmp/.dir_was_reset; \
138+
else \
139+
echo "Skipping geth init (directory was not reset)"; \
140+
fi
124141

125142
@# Read bootnodes from the file; the file is mounted into the container.
126143
@bootnodes=`cat $(PWD)/$(BEPOLIA_NETWORK_FILES_DIR)/el-bootnodes.txt`; \
@@ -181,13 +198,19 @@ start-mainnet:
181198
# discovery bootnodes by region, refer to testing/networks/80094/el-bootnodes.txt
182199
start-geth-mainnet:
183200
$(call ask_reset_dir_func, $(ETH_DATA_DIR))
184-
docker run \
185-
--rm -v $(PWD)/${TESTAPP_FILES_DIR}:/${TESTAPP_FILES_DIR} \
186-
--rm -v $(PWD)/${MAINNET_NETWORK_FILES_DIR}:/${MAINNET_NETWORK_FILES_DIR} \
187-
-v $(PWD)/.tmp:/.tmp \
188-
ghcr.io/berachain/bera-geth:latest init \
189-
--datadir ${ETH_DATA_DIR} \
190-
${MAINNET_ETH_GENESIS_PATH}
201+
@if [ -f .tmp/.dir_was_reset ]; then \
202+
echo "Initializing geth..."; \
203+
docker run \
204+
--rm -v $(PWD)/${TESTAPP_FILES_DIR}:/${TESTAPP_FILES_DIR} \
205+
--rm -v $(PWD)/${MAINNET_NETWORK_FILES_DIR}:/${MAINNET_NETWORK_FILES_DIR} \
206+
-v $(PWD)/.tmp:/.tmp \
207+
ghcr.io/berachain/bera-geth:latest init \
208+
--datadir ${ETH_DATA_DIR} \
209+
${MAINNET_ETH_GENESIS_PATH}; \
210+
rm -f .tmp/.dir_was_reset; \
211+
else \
212+
echo "Skipping geth init (directory was not reset)"; \
213+
fi
191214

192215
@# Read bootnodes from the file; the file is mounted into the container.
193216
@bootnodes=`cat $(PWD)/$(MAINNET_NETWORK_FILES_DIR)/el-peers.txt`; \

0 commit comments

Comments
 (0)