Skip to content

Commit 20521e8

Browse files
committed
refactor: extract shared get_public_ip into helpers.sh
The get_public_ip() function was duplicated verbatim in both op-node-entrypoint and base-consensus-entrypoint (23 lines each). Any future change to IP detection logic would need to be made in two places, increasing the risk of drift. - Create helpers.sh with a single, documented get_public_ip function. - Replace the inline definitions in op-node-entrypoint and base-consensus-entrypoint with source ./helpers.sh. - Add COPY helpers.sh . to geth, reth, and nethermind Dockerfiles so the helper is available in all final images. No functional change.
1 parent 4e715e4 commit 20521e8

6 files changed

Lines changed: 29 additions & 40 deletions

File tree

base-consensus-entrypoint

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
11
#!/bin/bash
22
set -eu
33

4-
get_public_ip() {
5-
# Define a list of HTTP-based providers
6-
local PROVIDERS=(
7-
"http://ifconfig.me"
8-
"http://api.ipify.org"
9-
"http://ipecho.net/plain"
10-
"http://v4.ident.me"
11-
)
12-
# Iterate through the providers until an IP is found or the list is exhausted
13-
for provider in "${PROVIDERS[@]}"; do
14-
local IP
15-
IP=$(curl -s --max-time 10 --connect-timeout 5 "$provider")
16-
# Check if IP contains a valid format (simple regex for an IPv4 address)
17-
if [[ $IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
18-
echo "$IP"
19-
return 0
20-
fi
21-
done
22-
return 1
23-
}
4+
source ./helpers.sh
245

256
if [[ -z "${BASE_NODE_NETWORK:-}" ]]; then
267
echo "expected BASE_NODE_NETWORK to be set" 1>&2

geth/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
4040
COPY geth/geth-entrypoint ./execution-entrypoint
4141
COPY op-node-entrypoint .
4242
COPY consensus-entrypoint .
43+
COPY helpers.sh .
4344

4445
CMD ["/usr/bin/supervisord"]

helpers.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# Shared helper functions used by Base node entrypoints
3+
4+
# get_public_ip attempts to discover the node's public IPv4 address
5+
# by querying a list of HTTP-based IP detection services.
6+
# Prints the IP to stdout and returns 0 on success, 1 on failure.
7+
get_public_ip() {
8+
local PROVIDERS=(
9+
"http://ifconfig.me"
10+
"http://api.ipify.org"
11+
"http://ipecho.net/plain"
12+
"http://v4.ident.me"
13+
)
14+
15+
for provider in "${PROVIDERS[@]}"; do
16+
local IP
17+
IP=$(curl -s --max-time 10 --connect-timeout 5 "$provider")
18+
if [[ $IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
19+
echo "$IP"
20+
return 0
21+
fi
22+
done
23+
return 1
24+
}

nethermind/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
4747
COPY nethermind/nethermind-entrypoint ./execution-entrypoint
4848
COPY op-node-entrypoint .
4949
COPY consensus-entrypoint .
50+
COPY helpers.sh .
5051

5152
CMD ["/usr/bin/supervisord"]

op-node-entrypoint

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
11
#!/bin/bash
22
set -eu
33

4-
get_public_ip() {
5-
# Define a list of HTTP-based providers
6-
local PROVIDERS=(
7-
"http://ifconfig.me"
8-
"http://api.ipify.org"
9-
"http://ipecho.net/plain"
10-
"http://v4.ident.me"
11-
)
12-
# Iterate through the providers until an IP is found or the list is exhausted
13-
for provider in "${PROVIDERS[@]}"; do
14-
local IP
15-
IP=$(curl -s --max-time 10 --connect-timeout 5 "$provider")
16-
# Check if IP contains a valid format (simple regex for an IPv4 address)
17-
if [[ $IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
18-
echo "$IP"
19-
return 0
20-
fi
21-
done
22-
return 1
23-
}
4+
source ./helpers.sh
245

256
if [[ -z "$OP_NODE_NETWORK" && -z "$OP_NODE_ROLLUP_CONFIG" ]]; then
267
echo "expected OP_NODE_NETWORK to be set" 1>&2

reth/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,6 @@ COPY ./reth/reth-entrypoint ./execution-entrypoint
7171
COPY op-node-entrypoint .
7272
COPY base-consensus-entrypoint .
7373
COPY consensus-entrypoint .
74+
COPY helpers.sh .
7475

7576
CMD ["/usr/bin/supervisord"]

0 commit comments

Comments
 (0)