Develop a custom container registry

Learning how to develop a custom container registry.

Before diving into the specifics of this component type, it is beneficial to familiarize yourself with our general guide to writing custom component flavors in ZenML. This guide provides an essential understanding of ZenML's component flavor concepts.

Base Abstraction

In the current version of ZenML, container registries have a rather basic base abstraction. In essence, their base configuration only features a uri and their implementation features a non-abstract prepare_image_push method for validation.

from abc import abstractmethod

from typing import Type

from zenml.enums import StackComponentType

from zenml.stack import Flavor

from zenml.stack.authentication_mixin import (

AuthenticationConfigMixin,

AuthenticationMixin,

from zenml.utils import docker_utils

class BaseContainerRegistryConfig(AuthenticationConfigMixin):

"""Base config for a container registry."""

uri: str

class BaseContainerRegistry(AuthenticationMixin):

"""Base class for all ZenML container registries."""

def prepare_image_push(self, image_name: str) -> None:

"""Conduct necessary checks/preparations before an image gets pushed."""

def push_image(self, image_name: str) -> str:

"""Pushes a Docker image."""

if not image_name.startswith(self.config.uri):

raise ValueError(

f"Docker image `{image_name}` does not belong to container "

f"registry `{self.config.uri}`."

self.prepare_image_push(image_name)

return docker_utils.push_image(image_name)

class BaseContainerRegistryFlavor(Flavor):

"""Base flavor for container registries."""

@property

@abstractmethod

def name(self) -> str:

"""Returns the name of the flavor."""

@property

def type(self) -> StackComponentType:

"""Returns the flavor type."""

return StackComponentType.CONTAINER_REGISTRY

@property

def config_class(self) -> Type[BaseContainerRegistryConfig]:

"""Config class for this flavor."""

return BaseContainerRegistryConfig