Skip to content

Container Registries

zenml.container_registries special

Initialization for ZenML's container registries module.

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

Implementation of an Azure Container Registry class.

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

Implementation of a base container registry class.

BaseContainerRegistry (StackComponent, AuthenticationMixin) 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, AuthenticationMixin):
    """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.

        Args:
            uri: The URI to be stripped.

        Returns:
            The URI without trailing slashes.
        """
        return uri.rstrip("/")

    @property
    def requires_authentication(self) -> bool:
        """Returns whether the container registry requires authentication.

        Returns:
            `True` if the container registry requires authentication,
            `False` otherwise.
        """
        return bool(self.authentication_secret)

    @property
    def credentials(self) -> Optional[Tuple[str, str]]:
        """Username and password to authenticate with this container registry.

        Returns:
            Tuple with username and password if this container registry
            requires authentication, `None` otherwise.
        """
        secret = self.get_authentication_secret(
            expected_schema_type=BasicAuthSecretSchema
        )
        if secret:
            return secret.username, secret.password

        return None

    @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)
credentials: Optional[Tuple[str, str]] property readonly

Username and password to authenticate with this container registry.

Returns:

Type Description
Optional[Tuple[str, str]]

Tuple with username and password if this container registry requires authentication, None otherwise.

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.

requires_authentication: bool property readonly

Returns whether the container registry requires authentication.

Returns:

Type Description
bool

True if the container registry requires authentication, 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.

Parameters:

Name Type Description Default
uri str

The URI to be stripped.

required

Returns:

Type Description
str

The URI without trailing slashes.

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.

    Args:
        uri: The URI to be stripped.

    Returns:
        The URI without trailing slashes.
    """
    return uri.rstrip("/")

default_container_registry

Implementation of a default container registry class.

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

Implementation of a DockerHub Container Registry class.

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

Implementation of a GCP Container Registry class.

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

Implementation of the GitHub Container Registry.

GitHubContainerRegistry (BaseContainerRegistry) pydantic-model

Class for GitHub Container Registry.

Attributes:

Name Type Description
automatic_token_authentication bool

If True, use automatic token authentication (https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow) when trying to access this container registry from within a GitHub Actions environment.

Source code in zenml/container_registries/github_container_registry.py
class GitHubContainerRegistry(BaseContainerRegistry):
    """Class for GitHub Container Registry.

    Attributes:
        automatic_token_authentication: If `True`, use automatic token
            authentication (https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow)
            when trying to access this container registry from within a GitHub
            Actions environment.
    """

    automatic_token_authentication: bool = False

    # Class Configuration
    FLAVOR: ClassVar[str] = ContainerRegistryFlavor.GITHUB

gitlab_container_registry

Implementation of a GitLab Container Registry class.

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