Verified Commit 25e7a001 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Support creating containers from tags

parent 769e60c0
Loading
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -190,8 +190,9 @@ class Image:

	_cache = dict[str, ShaID]()

	def __init__(self, iid: ShaID):
	def __init__(self, iid: ShaID, name: str|None = None):
		self.iid = iid
		self.name = name

	@classmethod
	def build(cls, context: Path, target: str = "", **build_args: str|None) -> Self:
@@ -224,7 +225,7 @@ class Image:
		except KeyError:
			docker(b"pull", repository)
			iid = cls._process_image(repository)
		return cls(iid)
		return cls(iid, repository)

	@classmethod
	def _process_image(cls, reference: str) -> ShaID:
@@ -234,6 +235,10 @@ class Image:
			((tag, iid) for tag in report.path("$.RepoTags", list[str])),
			reference=iid,
		)
		cls._cache.update(
			((tag, iid) for tag in report.path("$.RepoDigests", list[str])),
			reference=iid,
		)
		return iid

	def get_id(self) -> ShaID:
@@ -242,6 +247,12 @@ class Image:
		"""
		return self.iid

	def get_ref(self) -> str:
		"""
		Return a name or IID reference for an Image
		"""
		return self.name or self.iid


class Container:
	"""
@@ -365,7 +376,7 @@ class Container:
			docker_output(
				b"container", b"create",
				"--label", "uk.org.kodo.behave-utils",
				*opts, self.image.iid, *self.cmd,
				*opts, self.image.get_ref(), *self.cmd,
			),
		)
		assert self.cid