Skip to content

Commit c5b8764

Browse files
anuartbtfx-copybara
authored andcommitted
no-op
PiperOrigin-RevId: 548556494
1 parent 96d4e43 commit c5b8764

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

tfx/components/infra_validator/model_server_runners/local_docker_runner.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
"""Module for LocalDockerModelServerRunner."""
1515

1616
import os
17+
import subprocess
1718
import time
18-
from typing import Any, Dict, Optional
19+
from typing import Any, Dict, Optional, Tuple
1920

2021
from absl import logging
2122
import docker
@@ -39,7 +40,7 @@ def _make_docker_client(config: infra_validator_pb2.LocalDockerConfig):
3940
return docker.DockerClient(**params)
4041

4142

42-
def _find_host_port(ports: Dict[str, Any], container_port: int) -> str:
43+
def _find_host(ports: Dict[str, Any], container_port: int) -> Tuple[str, str]:
4344
"""Find host port from container port mappings.
4445
4546
`ports` is a nested dictionary of the following structure:
@@ -65,10 +66,15 @@ def _find_host_port(ports: Dict[str, Any], container_port: int) -> str:
6566
Raises:
6667
ValueError: No corresponding host port was found.
6768
"""
69+
command = '/sbin/ip route|awk \'/default/ { print $3 }\''
70+
ip_address = subprocess.check_output(
71+
command, shell=True).decode('utf-8').strip()
72+
logging.info('Container IP address: %s', ip_address)
73+
6874
mappings = ports.get('{}/tcp'.format(container_port), [])
6975
for mapping in mappings:
7076
if mapping['HostIp'] == '0.0.0.0':
71-
return mapping['HostPort']
77+
return ip_address, mapping['HostPort']
7278
else:
7379
raise ValueError(
7480
'No HostPort found for ContainerPort={} (all port mappings: {})'
@@ -146,9 +152,11 @@ def WaitUntilRunning(self, deadline):
146152
continue
147153
# The container is running :)
148154
if status == 'running':
149-
host_port = _find_host_port(self._container.ports,
150-
self._serving_binary.container_port)
151-
self._endpoint = 'localhost:{}'.format(host_port)
155+
ip_address, host_port = _find_host(
156+
self._container.ports,
157+
self._serving_binary.container_port)
158+
159+
self._endpoint = '{}:{}'.format(ip_address, host_port)
152160
return
153161
# Docker status is one of {'created', 'restarting', 'running', 'removing',
154162
# 'paused', 'exited', or 'dead'}. Status other than 'created' and

tfx/examples/chicago_taxi_pipeline/taxi_pipeline_simple_airflow_e2e_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def _CheckPendingTasks(self, pending_task_names: Sequence[str]) -> Set[str]:
100100

101101
def setUp(self):
102102
super().setUp()
103+
#
103104
# setup airflow_home in a temp directory, config and init db.
104105
self._airflow_home = self.tmp_dir
105106
self.enter_context(

tfx/examples/penguin/penguin_pipeline_local_infraval_e2e_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""E2E Tests for tfx.examples.penguin.penguin_pipeline_local_infraval."""
1515

16+
#
1617
import os
1718

1819
from absl.testing import parameterized

0 commit comments

Comments
 (0)