base.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import abc
  2. class RuntimeBuilder(abc.ABC):
  3. @abc.abstractmethod
  4. def build(
  5. self,
  6. path: str,
  7. tags: list[str],
  8. platform: str | None = None,
  9. ) -> str:
  10. """Build the runtime image.
  11. Args:
  12. path (str): The path to the runtime image's build directory.
  13. tags (list[str]): The tags to apply to the runtime image (e.g., ["repo:my-repo", "sha:my-sha"]).
  14. platform (str, optional): The target platform for the build. Defaults to None.
  15. Returns:
  16. str: The name:tag of the runtime image after build (e.g., "repo:sha").
  17. This can be different from the tags input if the builder chooses to mutate the tags (e.g., adding a
  18. registry prefix). This should be used for subsequent use (e.g., `docker run`).
  19. Raises:
  20. RuntimeError: If the build failed.
  21. """
  22. pass
  23. @abc.abstractmethod
  24. def image_exists(self, image_name: str, pull_from_repo: bool = True) -> bool:
  25. """Check if the runtime image exists.
  26. Args:
  27. image_name (str): The name of the runtime image (e.g., "repo:sha").
  28. pull_from_repo (bool): Whether to pull from the remote repo if the image not present locally
  29. Returns:
  30. bool: Whether the runtime image exists.
  31. """
  32. pass