diff --git a/Dockerfile b/Dockerfile index 1488954..426139c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,10 +17,28 @@ RUN apt-get update && \ # Give IBC more time to detect the login/config dialog on the current headless # GCE target. The upstream 60s default has been too short during keepalive # recovery and caused intermittent exit code 1112 before the Gateway became -# API-ready. -RUN sed -i 's/^LoginDialogDisplayTimeout=60$/LoginDialogDisplayTimeout=180/' \ - /home/ibgateway/ibc/config.ini \ - /home/ibgateway/ibc/config.ini.tmpl +# API-ready. Fail the image build if the setting is not actually applied. +RUN python3 - <<'PY' +from pathlib import Path +import re + +paths = [ + Path("/home/ibgateway/ibc/config.ini"), + Path("/home/ibgateway/ibc/config.ini.tmpl"), +] +for path in paths: + text = path.read_text(encoding="utf-8") + updated = re.sub( + r"(?m)^LoginDialogDisplayTimeout\s*=.*$", + "LoginDialogDisplayTimeout=180", + text, + ) + if updated == text and "LoginDialogDisplayTimeout=180" not in text: + updated = f"{text.rstrip()}\nLoginDialogDisplayTimeout=180\n" + path.write_text(updated, encoding="utf-8") + if "LoginDialogDisplayTimeout=180" not in updated: + raise SystemExit(f"failed to set LoginDialogDisplayTimeout in {path}") +PY COPY --chown=1000:1000 ./container_overrides/run.sh /home/ibgateway/scripts/run.sh RUN chmod a+x /home/ibgateway/scripts/run.sh diff --git a/container_overrides/run.sh b/container_overrides/run.sh index 536afa4..0fad2c2 100644 --- a/container_overrides/run.sh +++ b/container_overrides/run.sh @@ -63,6 +63,7 @@ start_vnc() { } start_IBC() { + configure_ibc_login_dialog_timeout echo ".> Starting IBC in ${TRADING_MODE} mode, with params:" echo ".> Version: ${TWS_MAJOR_VRSN}" echo ".> program: ${IBC_COMMAND:-gateway}" @@ -82,6 +83,27 @@ start_IBC() { echo "$_p" >"/tmp/pid_${TRADING_MODE}" } +configure_ibc_login_dialog_timeout() { + local timeout="${IBC_LOGIN_DIALOG_DISPLAY_TIMEOUT:-180}" + local files=( + "${IBC_INI:-/home/ibgateway/ibc/config.ini}" + "/home/ibgateway/ibc/config.ini" + "/home/ibgateway/ibc/config.ini.tmpl" + ) + local file + + for file in "${files[@]}"; do + if [ ! -f "$file" ]; then + continue + fi + if grep -Eq '^LoginDialogDisplayTimeout\s*=' "$file"; then + sed -i -E "s/^LoginDialogDisplayTimeout\s*=.*/LoginDialogDisplayTimeout=${timeout}/" "$file" + else + printf '\nLoginDialogDisplayTimeout=%s\n' "$timeout" >>"$file" + fi + done +} + start_process() { set_ports apply_settings diff --git a/tests/test_docker_compose_ports.sh b/tests/test_docker_compose_ports.sh index 44d7b2e..9e6ce1f 100644 --- a/tests/test_docker_compose_ports.sh +++ b/tests/test_docker_compose_ports.sh @@ -8,7 +8,8 @@ run_override="$repo_dir/container_overrides/run.sh" grep -Fq 'pip3 install pyotp ib_insync --break-system-packages' "$dockerfile" grep -Fq 'FROM gnzsnz/ib-gateway:10.37.1q' "$dockerfile" -grep -Fq "LoginDialogDisplayTimeout=60$/LoginDialogDisplayTimeout=180" "$dockerfile" +grep -Fq 'LoginDialogDisplayTimeout=180' "$dockerfile" +grep -Fq 'failed to set LoginDialogDisplayTimeout' "$dockerfile" grep -Fq '/home/ibgateway/ibc/config.ini.tmpl' "$dockerfile" grep -Fq 'COPY --chown=1000:1000 ./container_overrides/run.sh /home/ibgateway/scripts/run.sh' "$dockerfile" grep -Fq 'chmod a+x /home/ibgateway/scripts/run.sh' "$dockerfile" @@ -17,6 +18,9 @@ grep -Fq 'libglib2.0-0' "$dockerfile" grep -Fq 'libxtst6' "$dockerfile" grep -Fq 'Xvfb "$DISPLAY" -ac -screen 0 "${IB_XVFB_SCREEN:-1024x768x24}" &' "$run_override" grep -Fq -- '-ncache_cr -noxdamage' "$run_override" +grep -Fq 'configure_ibc_login_dialog_timeout' "$run_override" +grep -Fq 'IBC_LOGIN_DIALOG_DISPLAY_TIMEOUT:-180' "$run_override" +grep -Fq 'LoginDialogDisplayTimeout=${timeout}' "$run_override" grep -Fq ' - "4001:4003"' "$compose_file" grep -Fq ' - "4002:4004"' "$compose_file"