Skip to content
Merged
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
12 changes: 12 additions & 0 deletions eventsourcingdb/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tarfile
import time
from http import HTTPStatus
from typing import ClassVar

import docker
import requests
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down