From 12829876ef1b3e4611c9ffab7786b3592fe5c270 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sat, 15 Jan 2022 11:35:23 -0800 Subject: [PATCH] Await SSH tunnel init using docker exec This change is from a different pull-request that was never finished. It adds a 5-second timeout to the wget command as requested in that PR. https://github.com/brthor/docker-push-ssh/pull/10 --- docker_push_ssh/cli.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docker_push_ssh/cli.py b/docker_push_ssh/cli.py index 0a88f57..9344ef8 100644 --- a/docker_push_ssh/cli.py +++ b/docker_push_ssh/cli.py @@ -38,12 +38,17 @@ def waitForSshTunnelInit(retries=20, delay=1.0): for _ in range(retries): time.sleep(delay) - try: - response = urllib2.urlopen("http://localhost:5000/v2/", timeout=5) - except (socket.error, urllib2.URLError, httplib.BadStatusLine): - continue + sshCheckCommandResult = Command("docker", [ + "exec", + "docker-push-ssh-tunnel", + "wget", + "-O", "/dev/null", + "-q", + "--timeout=5", + "http://localhost:5000/v2" + ]).environment_dict(os.environ).execute() - if response.getcode() == 200: + if not sshCheckCommandResult.failed(): return True return False