Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions container_overrides/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion tests/test_docker_compose_ports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down