Fix Docker entrypoint NAT helper variables (#706)

Signed-off-by: Slava <20563034+veaceslavdoina@users.noreply.github.com>
This commit is contained in:
Slava 2024-02-15 15:57:50 +02:00 committed by GitHub
parent 6fab252bf1
commit 79af5c0e64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 18 deletions

View File

@ -1,28 +1,39 @@
#!/bin/bash #!/bin/bash
# Parameters # Parameters
if [[ "${NAT_IP_AUTO}" == "true" && -z "${NAT_PUBLIC_IP_AUTO}" ]]; then if [[ -z "${CODEX_NAT}" ]]; then
export CODEX_NAT=$(hostname --ip-address) if [[ "${NAT_IP_AUTO}" == "true" && -z "${NAT_PUBLIC_IP_AUTO}" ]]; then
echo "Internal: Set CODEX_NAT: ${CODEX_NAT}" export CODEX_NAT=$(hostname --ip-address)
echo "Private: CODEX_NAT=${CODEX_NAT}"
elif [[ -n "${NAT_PUBLIC_IP_AUTO}" ]]; then
# Run for 60 seconds if fail
WAIT=120
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
if [[ $? -eq 0 && -n "${CODEX_NAT}" ]]; then
echo "Public: CODEX_NAT=${CODEX_NAT}"
break
else
# Sleep and check again
echo "Can't get Public IP - Retry in $SLEEP seconds / $((WAIT - SECONDS))"
sleep $SLEEP
fi
done
fi
fi fi
if [[ -n "${NAT_PUBLIC_IP_AUTO}" ]]; then # Stop Codex run if can't get NAT IP when requested
# Run for 60 seconds if fail if [[ "${NAT_IP_AUTO}" == "true" && -z "${CODEX_NAT}" ]]; then
WAIT=60 echo "Can't get Private IP - Stop Codex run"
SECONDS=0 exit 1
SLEEP=5 elif [[ -n "${NAT_PUBLIC_IP_AUTO}" && -z "${CODEX_NAT}" ]]; then
while (( SECONDS < WAIT )); do echo "Can't get Public IP in $WAIT seconds - Stop Codex run"
export CODEX_NAT=$(curl -s -f -m 5 "${NAT_PUBLIC_IP_AUTO}") exit 1
# 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 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, # If marketplace is enabled from the testing environment,
# The file has to be written before Codex starts. # The file has to be written before Codex starts.
if [ -n "${PRIV_KEY}" ]; then if [ -n "${PRIV_KEY}" ]; then