base.py 1.5 KB

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