Skip to content

Commit de1dadf

Browse files
szachovyCopilot
andcommitted
Address review: broaden exception handling, reuse Docker client
Catch docker.errors.DockerException and requests.exceptions.RequestException in pull_or_build_image to handle connection-level failures during pull. Pass outer ContainerConnection client to MySQLMgmt instead of creating a fresh docker.from_env() instance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 59b2f14 commit de1dadf

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/container.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(self, container: str | None) -> None:
104104
def pull_or_build_image(client: docker.client.DockerClient, image: str, build_context: str) -> None:
105105
try:
106106
client.images.pull(image)
107-
except docker.errors.APIError:
107+
except (docker.errors.DockerException, requests.exceptions.RequestException):
108108
client.images.build(path=build_context, tag=image)
109109

110110
def run_command_on_the_container(
@@ -288,6 +288,7 @@ class MySQLMgmt(ContainerInstance):
288288
# pylint: disable=too-many-instance-attributes
289289
def __init__(
290290
self,
291+
client: docker.client.DockerClient,
291292
virtual_ip_address: str,
292293
virtual_network_mask: str,
293294
virtual_network_interface: str,
@@ -297,6 +298,7 @@ def __init__(
297298
state: str,
298299
priority: str
299300
) -> None:
301+
self.client = client
300302
self.virtual_ip_address = virtual_ip_address
301303
self.virtual_network_mask = virtual_network_mask
302304
self.virtual_network_interface = virtual_network_interface
@@ -329,7 +331,7 @@ def setup_env(self) -> None:
329331
def run(self) -> None:
330332
self.setup_env()
331333
ContainerConnection.pull_or_build_image(
332-
docker.from_env(),
334+
self.client,
333335
"ghcr.io/szachovy/superset-cluster-mysql-mgmt:latest",
334336
"/opt/superset-cluster/mysql-mgmt"
335337
)
@@ -359,6 +361,7 @@ def run(self) -> None:
359361
return print(
360362
self.wait_until_healthy(
361363
MySQLMgmt( # type: ignore[arg-type]
364+
client=self.client,
362365
virtual_ip_address=virtual_ip_address,
363366
virtual_network_mask=virtual_network_mask,
364367
virtual_network_interface=virtual_network_interface,

0 commit comments

Comments
 (0)