base.py 1.2 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. ) -> str:
  9. """
  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. Returns:
  15. str: The name:tag of the runtime image after build (e.g., "repo:sha").
  16. This can be different from the tags input if the builder chooses to mutate the tags (e.g., adding a
  17. registry prefix). This should be used for subsequent use (e.g., `docker run`).
  18. Raises:
  19. RuntimeError: If the build failed.
  20. """
  21. pass
  22. @abc.abstractmethod
  23. def image_exists(self, image_name: str, pull_from_repo: bool = True) -> bool:
  24. """
  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