diff --git a/base-consensus-entrypoint b/base-consensus-entrypoint index cd2801fce..484808d96 100755 --- a/base-consensus-entrypoint +++ b/base-consensus-entrypoint @@ -1,26 +1,7 @@ #!/bin/bash set -eu -get_public_ip() { - # Define a list of HTTP-based providers - local PROVIDERS=( - "http://ifconfig.me" - "http://api.ipify.org" - "http://ipecho.net/plain" - "http://v4.ident.me" - ) - # Iterate through the providers until an IP is found or the list is exhausted - for provider in "${PROVIDERS[@]}"; do - local IP - IP=$(curl -s --max-time 10 --connect-timeout 5 "$provider") - # Check if IP contains a valid format (simple regex for an IPv4 address) - if [[ $IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "$IP" - return 0 - fi - done - return 1 -} +source ./helpers.sh if [[ -z "${BASE_NODE_NETWORK:-}" ]]; then echo "expected BASE_NODE_NETWORK to be set" 1>&2 diff --git a/geth/Dockerfile b/geth/Dockerfile index c32881405..a6c459381 100644 --- a/geth/Dockerfile +++ b/geth/Dockerfile @@ -40,5 +40,6 @@ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY geth/geth-entrypoint ./execution-entrypoint COPY op-node-entrypoint . COPY consensus-entrypoint . +COPY helpers.sh . CMD ["/usr/bin/supervisord"] diff --git a/helpers.sh b/helpers.sh new file mode 100644 index 000000000..5398f1d68 --- /dev/null +++ b/helpers.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Shared helper functions used by Base node entrypoints + +# get_public_ip attempts to discover the node's public IPv4 address +# by querying a list of HTTP-based IP detection services. +# Prints the IP to stdout and returns 0 on success, 1 on failure. +get_public_ip() { + local PROVIDERS=( + "http://ifconfig.me" + "http://api.ipify.org" + "http://ipecho.net/plain" + "http://v4.ident.me" + ) + + for provider in "${PROVIDERS[@]}"; do + local IP + IP=$(curl -s --max-time 10 --connect-timeout 5 "$provider") + if [[ $IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "$IP" + return 0 + fi + done + return 1 +} diff --git a/nethermind/Dockerfile b/nethermind/Dockerfile index 4c2df2a0e..af3a2be5c 100644 --- a/nethermind/Dockerfile +++ b/nethermind/Dockerfile @@ -47,5 +47,6 @@ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY nethermind/nethermind-entrypoint ./execution-entrypoint COPY op-node-entrypoint . COPY consensus-entrypoint . +COPY helpers.sh . CMD ["/usr/bin/supervisord"] diff --git a/op-node-entrypoint b/op-node-entrypoint index 893015882..ed6e9ed27 100755 --- a/op-node-entrypoint +++ b/op-node-entrypoint @@ -1,26 +1,7 @@ #!/bin/bash set -eu -get_public_ip() { - # Define a list of HTTP-based providers - local PROVIDERS=( - "http://ifconfig.me" - "http://api.ipify.org" - "http://ipecho.net/plain" - "http://v4.ident.me" - ) - # Iterate through the providers until an IP is found or the list is exhausted - for provider in "${PROVIDERS[@]}"; do - local IP - IP=$(curl -s --max-time 10 --connect-timeout 5 "$provider") - # Check if IP contains a valid format (simple regex for an IPv4 address) - if [[ $IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "$IP" - return 0 - fi - done - return 1 -} +source ./helpers.sh if [[ -z "$OP_NODE_NETWORK" && -z "$OP_NODE_ROLLUP_CONFIG" ]]; then echo "expected OP_NODE_NETWORK to be set" 1>&2 diff --git a/reth/Dockerfile b/reth/Dockerfile index 2c9eec55f..8ae69826f 100644 --- a/reth/Dockerfile +++ b/reth/Dockerfile @@ -71,5 +71,6 @@ COPY ./reth/reth-entrypoint ./execution-entrypoint COPY op-node-entrypoint . COPY base-consensus-entrypoint . COPY consensus-entrypoint . +COPY helpers.sh . CMD ["/usr/bin/supervisord"]