diff --git a/docker/codex.Dockerfile b/docker/codex.Dockerfile index 4414b005..2c039252 100644 --- a/docker/codex.Dockerfile +++ b/docker/codex.Dockerfile @@ -32,7 +32,7 @@ ARG NAT_IP_AUTO WORKDIR ${APP_HOME} COPY --from=builder ${BUILD_HOME}/build/codex /usr/local/bin COPY --chmod=0755 docker/docker-entrypoint.sh / -RUN apt-get update && apt-get install -y libgomp1 bash && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y libgomp1 bash curl && rm -rf /var/lib/apt/lists/* ENV NAT_IP_AUTO=${NAT_IP_AUTO} ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["codex"] diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 3383f1fb..f2d76d23 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -15,7 +15,7 @@ services: # - CODEX_BOOTSTRAP_NODE=${CODEX_BOOTSTRAP_NODE} - CODEX_MAX_PEERS=${CODEX_MAX_PEERS:-160} - CODEX_AGENT_STRING=${CODEX_AGENT_STRING:-Codex} - - CODEX_API_BINDADDR=${CODEX_API_BINDADDR:-127.0.0.1} + - CODEX_API_BINDADDR=${CODEX_API_BINDADDR:-0.0.0.0} - CODEX_API_PORT=${CODEX_API_PORT:-8080} - CODEX_REPO_KIND=${CODEX_REPO_KIND:-fs} - CODEX_STORAGE_QUOTA=${CODEX_STORAGE_QUOTA:-8589934592} @@ -29,6 +29,8 @@ services: # - CODEX_MARKETPLACE_ADDRESS=${CODEX_MARKETPLACE_ADDRESS:-0x59b670e9fA9D0A427751Af201D676719a970857b} - CODEX_VALIDATOR=${CODEX_VALIDATOR:-false} - CODEX_VALIDATOR_MAX_SLOTS=${CODEX_VALIDATOR_MAX_SLOTS:-1000} + - NAT_IP_AUTO=false + - NAT_PUBLIC_IP_AUTO=https://ipinfo.io/ip ports: - 8080:8080/tcp # REST API - 8008:8008/tcp # Metrics diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 95146680..62165845 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -1,11 +1,28 @@ #!/bin/bash # Parameters -if [[ "${NAT_IP_AUTO}" == "true" ]]; then +if [[ "${NAT_IP_AUTO}" == "true" && -z "${NAT_PUBLIC_IP_AUTO}" ]]; then export CODEX_NAT=$(hostname --ip-address) - echo "Set CODEX_NAT: ${CODEX_NAT}" + echo "Internal: Set CODEX_NAT: ${CODEX_NAT}" fi +if [[ -n "${NAT_PUBLIC_IP_AUTO}" ]]; then + # Run for 60 seconds if fail + WAIT=60 + SECONDS=0 + SLEEP=5 + while (( SECONDS < WAIT )); do + export CODEX_NAT=$(curl -s -f -m 5 "${NAT_PUBLIC_IP_AUTO}") + # Check if exit code is 0 and returned value is not empty + [[ $? -eq 0 && -n "${CODEX_NAT}" ]] && { echo "Public: Set CODEX_NAT: ${CODEX_NAT}"; break; } || { echo "Can't get Public IP - Retry in $SLEEP seconds / $((WAIT - SECONDS))"; } + # Sleep and check again + sleep $SLEEP + done +fi + +# Stop Codex run if can't get Public IP +[[ -z "${CODEX_NAT}" ]] && { echo "Can't get Public IP in $WAIT seconds - Stop Codex run"; exit 1; } + # If marketplace is enabled from the testing environment, # The file has to be written before Codex starts. if [ -n "${PRIV_KEY}" ]; then