diff --git a/eventsourcingdb/container.py b/eventsourcingdb/container.py index 3be6b9b..484b9b9 100644 --- a/eventsourcingdb/container.py +++ b/eventsourcingdb/container.py @@ -3,6 +3,7 @@ import tarfile import time from http import HTTPStatus +from typing import ClassVar import docker import requests @@ -16,6 +17,10 @@ class Container: + # Images already pulled in this process. Every container start would + # otherwise hit the registry again, even though the image is local. + _pulled_images: ClassVar[set[str]] = set() + def __init__( self, ) -> None: @@ -191,11 +196,18 @@ def start(self) -> "Container": return self def _pull_or_get_image(self) -> None: + image = f"{self._image_name}:{self._image_tag}" + + if image in Container._pulled_images: + return + try: self._docker_client.images.pull(self._image_name, self._image_tag) except errors.APIError as e: self._handle_image_pull_error(e) + Container._pulled_images.add(image) + def _handle_image_pull_error(self, error) -> None: image_name = f"{self._image_name}:{self._image_tag}" try: