Image Builders
zenml.image_builders
Image builders allow you to build container images.
Attributes
__all__ = ['BaseImageBuilderConfig', 'BaseImageBuilder', 'BaseImageBuilderFlavor', 'LocalImageBuilder', 'LocalImageBuilderConfig', 'LocalImageBuilderFlavor', 'BuildContext']
module-attribute
Classes
BaseImageBuilder(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: StackComponent
, ABC
Base class for all ZenML image builders.
Source code in src/zenml/stack/stack_component.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
Attributes
build_context_class: Type[BuildContext]
property
Build context class to use.
The default build context class creates a build context that works for the Docker daemon. Override this method if your image builder requires a custom context.
Returns:
Type | Description |
---|---|
Type[BuildContext]
|
The build context class. |
config: BaseImageBuilderConfig
property
The stack component configuration.
Returns:
Type | Description |
---|---|
BaseImageBuilderConfig
|
The configuration. |
is_building_locally: bool
abstractmethod
property
Whether the image builder builds the images on the client machine.
Returns:
Type | Description |
---|---|
bool
|
True if the image builder builds locally, False otherwise. |
Functions
build(image_name: str, build_context: BuildContext, docker_build_options: Dict[str, Any], container_registry: Optional[BaseContainerRegistry] = None) -> str
abstractmethod
Builds a Docker image.
If a container registry is passed, the image will be pushed to that registry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_name
|
str
|
Name of the image to build. |
required |
build_context
|
BuildContext
|
The build context to use for the image. |
required |
docker_build_options
|
Dict[str, Any]
|
Docker build options. |
required |
container_registry
|
Optional[BaseContainerRegistry]
|
Optional container registry to push to. |
None
|
Returns:
Type | Description |
---|---|
str
|
The Docker image repo digest or name. |
Source code in src/zenml/image_builders/base_image_builder.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
BaseImageBuilderConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: StackComponentConfig
Base config for image builders.
Source code in src/zenml/stack/stack_component.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
BaseImageBuilderFlavor
Bases: Flavor
, ABC
Base class for all ZenML image builder flavors.
Attributes
config_class: Type[BaseImageBuilderConfig]
property
implementation_class: Type[BaseImageBuilder]
property
type: StackComponentType
property
BuildContext(root: Optional[str] = None, dockerignore_file: Optional[str] = None)
Bases: Archivable
Image build context.
This class is responsible for creating an archive of the files needed to build a container image.
Initializes a build context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Optional[str]
|
Optional root directory for the build context. |
None
|
dockerignore_file
|
Optional[str]
|
Optional path to a dockerignore file. If not
given, a file called |
None
|
Source code in src/zenml/image_builders/build_context.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
Attributes
dockerignore_file: Optional[str]
property
The dockerignore file to use.
Returns:
Type | Description |
---|---|
Optional[str]
|
Path to the dockerignore file to use. |
Functions
get_files() -> Dict[str, str]
Gets all regular files that should be included in the archive.
Returns:
Type | Description |
---|---|
Dict[str, str]
|
A dict {path_in_archive: path_on_filesystem} for all regular files |
Dict[str, str]
|
in the archive. |
Source code in src/zenml/image_builders/build_context.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
write_archive(output_file: IO[bytes], archive_type: ArchiveType = ArchiveType.TAR_GZ) -> None
Writes an archive of the build context to the given file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_file
|
IO[bytes]
|
The file to write the archive to. |
required |
archive_type
|
ArchiveType
|
The type of archive to create. |
TAR_GZ
|
Source code in src/zenml/image_builders/build_context.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
LocalImageBuilder(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: BaseImageBuilder
Local image builder implementation.
Source code in src/zenml/stack/stack_component.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
Attributes
config: LocalImageBuilderConfig
property
The stack component configuration.
Returns:
Type | Description |
---|---|
LocalImageBuilderConfig
|
The configuration. |
is_building_locally: bool
property
Whether the image builder builds the images on the client machine.
Returns:
Type | Description |
---|---|
bool
|
True if the image builder builds locally, False otherwise. |
Functions
build(image_name: str, build_context: BuildContext, docker_build_options: Optional[Dict[str, Any]] = None, container_registry: Optional[BaseContainerRegistry] = None) -> str
Builds and optionally pushes an image using the local Docker client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_name
|
str
|
Name of the image to build and push. |
required |
build_context
|
BuildContext
|
The build context to use for the image. |
required |
docker_build_options
|
Optional[Dict[str, Any]]
|
Docker build options. |
None
|
container_registry
|
Optional[BaseContainerRegistry]
|
Optional container registry to push to. |
None
|
Returns:
Type | Description |
---|---|
str
|
The Docker image repo digest. |
Source code in src/zenml/image_builders/local_image_builder.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
LocalImageBuilderConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseImageBuilderConfig
Local image builder configuration.
Source code in src/zenml/stack/stack_component.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
LocalImageBuilderFlavor
Bases: BaseImageBuilderFlavor
Local image builder flavor.
Attributes
config_class: Type[LocalImageBuilderConfig]
property
docs_url: Optional[str]
property
A url to point at docs explaining this flavor.
Returns:
Type | Description |
---|---|
Optional[str]
|
A flavor docs url. |
implementation_class: Type[LocalImageBuilder]
property
logo_url: str
property
A url to represent the flavor in the dashboard.
Returns:
Type | Description |
---|---|
str
|
The flavor logo. |
name: str
property
The flavor name.
Returns:
Type | Description |
---|---|
str
|
The flavor name. |
sdk_docs_url: Optional[str]
property
A url to point at docs explaining this flavor.
Returns:
Type | Description |
---|---|
Optional[str]
|
A flavor docs url. |
Modules
base_image_builder
Base class for all ZenML image builders.
Classes
BaseImageBuilder(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: StackComponent
, ABC
Base class for all ZenML image builders.
Source code in src/zenml/stack/stack_component.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
build_context_class: Type[BuildContext]
property
Build context class to use.
The default build context class creates a build context that works for the Docker daemon. Override this method if your image builder requires a custom context.
Returns:
Type | Description |
---|---|
Type[BuildContext]
|
The build context class. |
config: BaseImageBuilderConfig
property
The stack component configuration.
Returns:
Type | Description |
---|---|
BaseImageBuilderConfig
|
The configuration. |
is_building_locally: bool
abstractmethod
property
Whether the image builder builds the images on the client machine.
Returns:
Type | Description |
---|---|
bool
|
True if the image builder builds locally, False otherwise. |
build(image_name: str, build_context: BuildContext, docker_build_options: Dict[str, Any], container_registry: Optional[BaseContainerRegistry] = None) -> str
abstractmethod
Builds a Docker image.
If a container registry is passed, the image will be pushed to that registry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_name
|
str
|
Name of the image to build. |
required |
build_context
|
BuildContext
|
The build context to use for the image. |
required |
docker_build_options
|
Dict[str, Any]
|
Docker build options. |
required |
container_registry
|
Optional[BaseContainerRegistry]
|
Optional container registry to push to. |
None
|
Returns:
Type | Description |
---|---|
str
|
The Docker image repo digest or name. |
Source code in src/zenml/image_builders/base_image_builder.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
BaseImageBuilderConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: StackComponentConfig
Base config for image builders.
Source code in src/zenml/stack/stack_component.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
BaseImageBuilderFlavor
Bases: Flavor
, ABC
Base class for all ZenML image builder flavors.
config_class: Type[BaseImageBuilderConfig]
property
implementation_class: Type[BaseImageBuilder]
property
type: StackComponentType
property
Functions
Modules
build_context
Image build context.
Classes
BuildContext(root: Optional[str] = None, dockerignore_file: Optional[str] = None)
Bases: Archivable
Image build context.
This class is responsible for creating an archive of the files needed to build a container image.
Initializes a build context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
Optional[str]
|
Optional root directory for the build context. |
None
|
dockerignore_file
|
Optional[str]
|
Optional path to a dockerignore file. If not
given, a file called |
None
|
Source code in src/zenml/image_builders/build_context.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
dockerignore_file: Optional[str]
property
The dockerignore file to use.
Returns:
Type | Description |
---|---|
Optional[str]
|
Path to the dockerignore file to use. |
get_files() -> Dict[str, str]
Gets all regular files that should be included in the archive.
Returns:
Type | Description |
---|---|
Dict[str, str]
|
A dict {path_in_archive: path_on_filesystem} for all regular files |
Dict[str, str]
|
in the archive. |
Source code in src/zenml/image_builders/build_context.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
write_archive(output_file: IO[bytes], archive_type: ArchiveType = ArchiveType.TAR_GZ) -> None
Writes an archive of the build context to the given file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_file
|
IO[bytes]
|
The file to write the archive to. |
required |
archive_type
|
ArchiveType
|
The type of archive to create. |
TAR_GZ
|
Source code in src/zenml/image_builders/build_context.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
Functions
Modules
local_image_builder
Local Docker image builder implementation.
Classes
LocalImageBuilder(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: BaseImageBuilder
Local image builder implementation.
Source code in src/zenml/stack/stack_component.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
config: LocalImageBuilderConfig
property
The stack component configuration.
Returns:
Type | Description |
---|---|
LocalImageBuilderConfig
|
The configuration. |
is_building_locally: bool
property
Whether the image builder builds the images on the client machine.
Returns:
Type | Description |
---|---|
bool
|
True if the image builder builds locally, False otherwise. |
build(image_name: str, build_context: BuildContext, docker_build_options: Optional[Dict[str, Any]] = None, container_registry: Optional[BaseContainerRegistry] = None) -> str
Builds and optionally pushes an image using the local Docker client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_name
|
str
|
Name of the image to build and push. |
required |
build_context
|
BuildContext
|
The build context to use for the image. |
required |
docker_build_options
|
Optional[Dict[str, Any]]
|
Docker build options. |
None
|
container_registry
|
Optional[BaseContainerRegistry]
|
Optional container registry to push to. |
None
|
Returns:
Type | Description |
---|---|
str
|
The Docker image repo digest. |
Source code in src/zenml/image_builders/local_image_builder.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
LocalImageBuilderConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseImageBuilderConfig
Local image builder configuration.
Source code in src/zenml/stack/stack_component.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
LocalImageBuilderFlavor
Bases: BaseImageBuilderFlavor
Local image builder flavor.
config_class: Type[LocalImageBuilderConfig]
property
docs_url: Optional[str]
property
A url to point at docs explaining this flavor.
Returns:
Type | Description |
---|---|
Optional[str]
|
A flavor docs url. |
implementation_class: Type[LocalImageBuilder]
property
logo_url: str
property
A url to represent the flavor in the dashboard.
Returns:
Type | Description |
---|---|
str
|
The flavor logo. |
name: str
property
The flavor name.
Returns:
Type | Description |
---|---|
str
|
The flavor name. |
sdk_docs_url: Optional[str]
property
A url to point at docs explaining this flavor.
Returns:
Type | Description |
---|---|
Optional[str]
|
A flavor docs url. |