Skip to content

buildable

REQUIREMENTS_SUBSTITUTIONS module-attribute

REQUIREMENTS_SUBSTITUTIONS = {'opencv-python=': 'opencv-python-headless='}

Buildable

Buildable()

Buildable is an abstract base class the encodes all the behavior needed to build a Chassis container.

Attributes:

Name Type Description
packaged

True if running in a built container.

metadata

The metadata for the model. It is initialized with no values.

requirements set[str]

A set of pip requirements needed by this model.

apt_packages set[str]

A set of apt-get packages required by this model.

additional_files set[str]

A set of additional files required by the model at runtime.

python_modules dict

A dictionary of Python objects that will be serialized using cloudpickle before being copied into the container. The key should be one of the constants defined in [chassis.runtime.constants][].

packaged instance-attribute

packaged = False

metadata instance-attribute

metadata = ModelMetadata.default()

requirements instance-attribute

requirements: set[str] = set()

apt_packages instance-attribute

apt_packages: set[str] = set()

additional_files instance-attribute

additional_files: set[str] = set()

python_modules instance-attribute

python_modules: dict = {}

merge_package

merge_package(package)

Allows for merging two Buildable objects. This will ensure that any pip requirements, apt packages, files, or modules are merged.

Parameters:

Name Type Description Default
package Buildable

Another Buildable object to merge into this one.

required

add_requirements

add_requirements(reqs)

Declare a pip requirement for your model.

The value of each requirement can be anything supported by a line in a requirements.txt file, including version constraints, etc.

All pip requirements declared via this method will be automatically installed when the container is built.

Parameters:

Name Type Description Default
reqs Union[str, list[str]]

Single python package (str) or list of python packages that are required dependencies to run the ChassisModel.process_fn attribute. These values are the same values that would follow pip install or that would be added to a Python dependencies txt file (e.g., requirements.txt)

required

add_apt_packages

add_apt_packages(packages)

Add an OS package that will be installed via apt-get.

If your model requires additional OS packages that are not part of the standard Python container, you can declare them here. Each package declared here will be apt-get install'd when the container is built.

Parameters:

Name Type Description Default
packages Union[str, list]

Single OS-level package (str) or list of OS-level packages that are required dependencies to run the ChassisModel.process_fn attribute. These values are the same values that can be installed via apt-get install.

required

get_packaged_path

get_packaged_path(path)

Convenience method for developers wanting to implement their own subclasses of Buildable. This method will return the final path in the built container of any additional files, etc.

Parameters:

Name Type Description Default
path str

The local path of a file.

required

Returns:

Type Description
str

The path the file will have in the final built container.

verify_prerequisites

verify_prerequisites(options)

Raises an exception if the object is not yet ready for building.

Models require having a name, version, and at least one input and one output.

Parameters:

Name Type Description Default
options BuildOptions

The BuildOptions used for the build.

required

prepare_context

prepare_context(options=DefaultBuildOptions)

Constructs the build context that will be used to build the container.

A build context is a directory containing a Dockerfile and any other resources the Dockerfile needs to build the container.

This method is called just before the build is initiated and compiles all the resources necessary to build the container. This includes the Dockerfile, required Chassis library code, the server implementation indicated by the BuildOptions, the cloudpickle'd model, the serialized model metadata, copies of any additional files, and a requirements.txt.

Typically, you won't call this method directly, it will be called automatically by a Builder. The one instance where you might want to use this method directly is if you want to inspect the contents of the build context before sending it to a Builder.

Parameters:

Name Type Description Default
options BuildOptions

The BuildOptions to be used for this build.

DefaultBuildOptions

Returns:

Type Description
BuildContext

A BuildContext object.

render_dockerfile

render_dockerfile(options)

Renders an appropriate Dockerfile for this object with the supplied BuildOptions.

Parameters:

Name Type Description Default
options BuildOptions

The BuildOptions that will be used for this build.

required

Returns:

Type Description
str

A string containing the contents for a Dockerfile.