Adds option to automatically announce codex by its public IP (#621)

* Adds option to automatically announce codex by its public IP

* Review comments by Slava

* Make NAT_PUBLIC_IP_AUTO more verbose and error resistant

Signed-off-by: Slava <20563034+veaceslavdoina@users.noreply.github.com>

---------

Signed-off-by: Slava <20563034+veaceslavdoina@users.noreply.github.com>
Co-authored-by: Slava <20563034+veaceslavdoina@users.noreply.github.com>
This commit is contained in:
Ben Bierens 2023-11-17 14:48:25 +01:00 committed by GitHub
parent bece1b88a1
commit 750fe2392f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View File

@ -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"]

View File

@ -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

View File

@ -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