Container Registries
zenml.container_registries
special
A container registry is a store for (Docker) containers. A ZenML workflow involving a container registry would automatically containerize your code to be transported across stacks running remotely. As part of the deployment to the cluster, the ZenML base image would be downloaded (from a cloud container registry) and used as the basis for the deployed 'run'.
For instance, when you are running a local container-based stack, you would therefore have a local container registry which stores the container images you create that bundle up your pipeline code. You could also use a remote container registry like the Elastic Container Registry at AWS in a more production setting.
azure_container_registry
AzureContainerRegistry (BaseContainerRegistry)
pydantic-model
Class for Azure Container Registry.
Source code in zenml/container_registries/azure_container_registry.py
class AzureContainerRegistry(BaseContainerRegistry):
"""Class for Azure Container Registry."""
# Class Configuration
FLAVOR: ClassVar[str] = ContainerRegistryFlavor.AZURE.value
base_container_registry
BaseContainerRegistry (StackComponent)
pydantic-model
Base class for all ZenML container registries.
Attributes:
Name | Type | Description |
---|---|---|
uri |
str |
The URI of the container registry. |
Source code in zenml/container_registries/base_container_registry.py
class BaseContainerRegistry(StackComponent):
"""Base class for all ZenML container registries.
Attributes:
uri: The URI of the container registry.
"""
uri: str
# Class Configuration
TYPE: ClassVar[StackComponentType] = StackComponentType.CONTAINER_REGISTRY
@validator("uri")
def strip_trailing_slash(cls, uri: str) -> str:
"""Removes trailing slashes from the URI."""
return uri.rstrip("/")
@property
def is_local(self) -> bool:
"""Returns whether the container registry is local or not.
Returns:
True if the container registry is local, False otherwise.
"""
return bool(re.fullmatch(r"localhost:[0-9]{4,5}", self.uri))
def prepare_image_push(self, image_name: str) -> None:
"""Method that subclasses can overwrite to do any necessary checks or
preparations before an image gets pushed.
Args:
image_name: Name of the docker image that will be pushed.
"""
def push_image(self, image_name: str) -> None:
"""Pushes a docker image.
Args:
image_name: Name of the docker image that will be pushed.
Raises:
ValueError: If the image name is not associated with this
container registry.
"""
if not image_name.startswith(self.uri):
raise ValueError(
f"Docker image `{image_name}` does not belong to container "
f"registry `{self.uri}`."
)
self.prepare_image_push(image_name)
docker_utils.push_docker_image(image_name)
is_local: bool
property
readonly
Returns whether the container registry is local or not.
Returns:
Type | Description |
---|---|
bool |
True if the container registry is local, False otherwise. |
prepare_image_push(self, image_name)
Method that subclasses can overwrite to do any necessary checks or preparations before an image gets pushed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_name |
str |
Name of the docker image that will be pushed. |
required |
Source code in zenml/container_registries/base_container_registry.py
def prepare_image_push(self, image_name: str) -> None:
"""Method that subclasses can overwrite to do any necessary checks or
preparations before an image gets pushed.
Args:
image_name: Name of the docker image that will be pushed.
"""
push_image(self, image_name)
Pushes a docker image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_name |
str |
Name of the docker image that will be pushed. |
required |
Exceptions:
Type | Description |
---|---|
ValueError |
If the image name is not associated with this container registry. |
Source code in zenml/container_registries/base_container_registry.py
def push_image(self, image_name: str) -> None:
"""Pushes a docker image.
Args:
image_name: Name of the docker image that will be pushed.
Raises:
ValueError: If the image name is not associated with this
container registry.
"""
if not image_name.startswith(self.uri):
raise ValueError(
f"Docker image `{image_name}` does not belong to container "
f"registry `{self.uri}`."
)
self.prepare_image_push(image_name)
docker_utils.push_docker_image(image_name)
strip_trailing_slash(uri)
classmethod
Removes trailing slashes from the URI.
Source code in zenml/container_registries/base_container_registry.py
@validator("uri")
def strip_trailing_slash(cls, uri: str) -> str:
"""Removes trailing slashes from the URI."""
return uri.rstrip("/")
default_container_registry
DefaultContainerRegistry (BaseContainerRegistry)
pydantic-model
Class for default ZenML container registries.
Source code in zenml/container_registries/default_container_registry.py
class DefaultContainerRegistry(BaseContainerRegistry):
"""Class for default ZenML container registries."""
# Class Configuration
FLAVOR: ClassVar[str] = ContainerRegistryFlavor.DEFAULT.value
dockerhub_container_registry
DockerHubContainerRegistry (BaseContainerRegistry)
pydantic-model
Class for DockerHub Container Registry.
Source code in zenml/container_registries/dockerhub_container_registry.py
class DockerHubContainerRegistry(BaseContainerRegistry):
"""Class for DockerHub Container Registry."""
# Class Configuration
FLAVOR: ClassVar[str] = ContainerRegistryFlavor.DOCKERHUB.value
gcp_container_registry
GCPContainerRegistry (BaseContainerRegistry)
pydantic-model
Class for GCP Container Registry.
Source code in zenml/container_registries/gcp_container_registry.py
class GCPContainerRegistry(BaseContainerRegistry):
"""Class for GCP Container Registry."""
# Class Configuration
FLAVOR: ClassVar[str] = ContainerRegistryFlavor.GCP.value
github_container_registry
GitHubContainerRegistry (BaseContainerRegistry)
pydantic-model
Class for GitHub Container Registry.
Source code in zenml/container_registries/github_container_registry.py
class GitHubContainerRegistry(BaseContainerRegistry):
"""Class for GitHub Container Registry."""
# Class Configuration
FLAVOR: ClassVar[str] = ContainerRegistryFlavor.GITHUB.value
gitlab_container_registry
GitLabContainerRegistry (BaseContainerRegistry)
pydantic-model
Class for GitLab Container Registry.
Source code in zenml/container_registries/gitlab_container_registry.py
class GitLabContainerRegistry(BaseContainerRegistry):
"""Class for GitLab Container Registry."""
# Class Configuration
FLAVOR: ClassVar[str] = ContainerRegistryFlavor.GITLAB.value