feat(docker): add codex network support for docker-entrypoint (#1262)

Co-authored-by: Ben Bierens <39762930+benbierens@users.noreply.github.com>
This commit is contained in:
Slava 2025-06-11 17:02:39 +03:00 committed by GitHub
parent f267d99ea8
commit e324ac8ca5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Environment variables from files # Environment variables from files in form of foo=bar
# If set to file path, read the file and export the variables # If set to file path, read the file and export the variables
# If set to directory path, read all files in the directory and export the variables # If set to directory path, read all files in the directory and export the variables
if [[ -n "${ENV_PATH}" ]]; then if [[ -n "${ENV_PATH}" ]]; then
@ -9,7 +9,12 @@ if [[ -n "${ENV_PATH}" ]]; then
set +a set +a
fi fi
# Bootstrap node from URL # Codex Network
if [[ -n "${NETWORK}" ]]; then
export BOOTSTRAP_NODE_FROM_URL="${BOOTSTRAP_NODE_FROM_URL:-https://spr.codex.storage/${NETWORK}}"
fi
# Bootstrap node URL
if [[ -n "${BOOTSTRAP_NODE_URL}" ]]; then if [[ -n "${BOOTSTRAP_NODE_URL}" ]]; then
BOOTSTRAP_NODE_URL="${BOOTSTRAP_NODE_URL}/api/codex/v1/spr" BOOTSTRAP_NODE_URL="${BOOTSTRAP_NODE_URL}/api/codex/v1/spr"
WAIT=${BOOTSTRAP_NODE_URL_WAIT:-300} WAIT=${BOOTSTRAP_NODE_URL_WAIT:-300}
@ -21,7 +26,6 @@ if [[ -n "${BOOTSTRAP_NODE_URL}" ]]; then
# Check if exit code is 0 and returned value is not empty # Check if exit code is 0 and returned value is not empty
if [[ $? -eq 0 && -n "${SPR}" ]]; then if [[ $? -eq 0 && -n "${SPR}" ]]; then
export CODEX_BOOTSTRAP_NODE="${SPR}" export CODEX_BOOTSTRAP_NODE="${SPR}"
echo "Bootstrap node: CODEX_BOOTSTRAP_NODE=${CODEX_BOOTSTRAP_NODE}"
break break
else else
# Sleep and check again # Sleep and check again
@ -31,6 +35,49 @@ if [[ -n "${BOOTSTRAP_NODE_URL}" ]]; then
done done
fi fi
# Bootstrap node from URL
if [[ -n "${BOOTSTRAP_NODE_FROM_URL}" ]]; then
WAIT=${BOOTSTRAP_NODE_FROM_URL_WAIT:-300}
SECONDS=0
SLEEP=1
# Run and retry if fail
while (( SECONDS < WAIT )); do
SPR=($(curl -s -f -m 5 "${BOOTSTRAP_NODE_FROM_URL}"))
# Check if exit code is 0 and returned value is not empty
if [[ $? -eq 0 && -n "${SPR}" ]]; then
for node in "${SPR[@]}"; do
bootstrap+="--bootstrap-node=$node "
done
set -- "$@" ${bootstrap}
break
else
# Sleep and check again
echo "Can't get SPR from ${BOOTSTRAP_NODE_FROM_URL} - Retry in $SLEEP seconds / $((WAIT - SECONDS))"
sleep $SLEEP
fi
done
fi
# Marketplace address from URL
if [[ -n "${MARKETPLACE_ADDRESS_FROM_URL}" ]]; then
WAIT=${MARKETPLACE_ADDRESS_FROM_URL_WAIT:-300}
SECONDS=0
SLEEP=1
# Run and retry if fail
while (( SECONDS < WAIT )); do
MARKETPLACE_ADDRESS=($(curl -s -f -m 5 "${MARKETPLACE_ADDRESS_FROM_URL}"))
# Check if exit code is 0 and returned value is not empty
if [[ $? -eq 0 && -n "${MARKETPLACE_ADDRESS}" ]]; then
export CODEX_MARKETPLACE_ADDRESS="${MARKETPLACE_ADDRESS}"
break
else
# Sleep and check again
echo "Can't get Marketplace address from ${MARKETPLACE_ADDRESS_FROM_URL} - Retry in $SLEEP seconds / $((WAIT - SECONDS))"
sleep $SLEEP
fi
done
fi
# Stop Codex run if unable to get SPR # Stop Codex run if unable to get SPR
if [[ -n "${BOOTSTRAP_NODE_URL}" && -z "${CODEX_BOOTSTRAP_NODE}" ]]; then if [[ -n "${BOOTSTRAP_NODE_URL}" && -z "${CODEX_BOOTSTRAP_NODE}" ]]; then
echo "Unable to get SPR from ${BOOTSTRAP_NODE_URL} in ${BOOTSTRAP_NODE_URL_WAIT} seconds - Stop Codex run" echo "Unable to get SPR from ${BOOTSTRAP_NODE_URL} in ${BOOTSTRAP_NODE_URL_WAIT} seconds - Stop Codex run"
@ -113,6 +160,12 @@ if [[ "$@" == *"prover"* ]]; then
[[ $? -ne 0 ]] && { echo "Failed to download circuit files"; exit 1; } [[ $? -ne 0 ]] && { echo "Failed to download circuit files"; exit 1; }
fi fi
# Show
echo -e "\nCodex run parameters:"
vars=$(env | grep CODEX_)
echo -e "${vars//CODEX_/ - CODEX_}"
echo -e " - $@\n"
# Run # Run
echo "Run Codex node" echo "Run Codex node"
exec "$@" exec "$@"