Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Get container host addresses from testcontainers #3946

Merged
merged 2 commits into from
Mar 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ def __init__(
"must be include into pytest plugins"
)
self.exposed_port = self.container.get_exposed_port("8080")
self.container_host = self.container.get_container_host_ip()
self.client = Trino(
user="user",
catalog="memory",
host="localhost",
host=self.container_host,
port=self.exposed_port,
source="trino-python-client",
http_scheme="http",
Expand Down Expand Up @@ -123,7 +124,7 @@ def get_prefixed_table_name(self, suffix: str) -> str:

def create_offline_store_config(self) -> FeastConfigBaseModel:
return TrinoOfflineStoreConfig(
host="localhost",
host=self.container_host,
port=self.exposed_port,
catalog="memory",
dataset=self.project_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def create_online_store(self) -> Dict[str, str]:
container=self.container, predicate=log_string_to_wait_for, timeout=10
)
exposed_port = self.container.get_exposed_port("6379")
return {"type": "redis", "connection_string": f"localhost:{exposed_port},db=0"}
container_host = self.container.get_container_host_ip()
return {
"type": "redis",
"connection_string": f"{container_host}:{exposed_port},db=0",
}

def teardown(self):
self.container.stop()
6 changes: 4 additions & 2 deletions sdk/python/tests/unit/test_sql_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ def pg_registry():
)
logger.info("Waited for %s seconds until postgres container was up", waited)
container_port = container.get_exposed_port(5432)
container_host = container.get_container_host_ip()

registry_config = RegistryConfig(
registry_type="sql",
path=f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@127.0.0.1:{container_port}/{POSTGRES_DB}",
path=f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{container_host}:{container_port}/{POSTGRES_DB}",
)

yield SqlRegistry(registry_config, "project", None)
Expand Down Expand Up @@ -100,10 +101,11 @@ def mysql_registry():
)
logger.info("Waited for %s seconds until mysql container was up", waited)
container_port = container.get_exposed_port(3306)
container_host = container.get_container_host_ip()

registry_config = RegistryConfig(
registry_type="sql",
path=f"mysql+pymysql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@127.0.0.1:{container_port}/{POSTGRES_DB}",
path=f"mysql+pymysql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{container_host}:{container_port}/{POSTGRES_DB}",
)

yield SqlRegistry(registry_config, "project", None)
Expand Down
Loading