ImageSpec#
- class flytekit.image_spec.ImageSpec(name='flytekit', python_version=None, builder=None, source_root=None, env=None, registry=None, packages=None, conda_packages=None, conda_channels=None, requirements=None, apt_packages=None, cuda=None, cudnn=None, base_image=None, platform='linux/amd64', pip_index=None, pip_extra_index_url=None, registry_config=None, entrypoint=None, commands=None, tag_format=None, source_copy_mode=None, copy=None)#
This class is used to specify the docker image that will be used to run the task.
- Args:
name: name of the image. python_version: python version of the image. Use default python in the base image if None. builder: Type of plugin to build the image. Use envd by default. source_root: source root of the image. env: environment variables of the image. registry: registry of the image. packages: list of python packages to install. conda_packages: list of conda packages to install. conda_channels: list of conda channels. requirements: path to the requirements.txt file. apt_packages: list of apt packages to install. cuda: version of cuda to install. cudnn: version of cudnn to install. base_image: base image of the image. platform: Specify the target platforms for the build output (for example, windows/amd64 or linux/amd64,darwin/arm64 pip_index: Specify the custom pip index url pip_extra_index_url: Specify one or more pip index urls as a list registry_config: Specify the path to a JSON registry config file entrypoint: List of strings to overwrite the entrypoint of the base image with, set to [] to remove the entrypoint. commands: Command to run during the building process tag_format: Custom string format for image tag. The ImageSpec hash passed in as spec_hash. For example,
to add a “dev” suffix to the image tag, set tag_format=”{spec_hash}-dev”
- source_copy_mode: This option allows the user to specify which source files to copy from the local host, into the image.
- Not setting this option means to use the default flytekit behavior. The default behavior is:
if fast register is used, source files are not copied into the image (because they’re already copied into the fast register tar layer).
if fast register is not used, then the LOADED_MODULES (aka ‘auto’) option is used to copy loaded Python files into the image.
If the option is set by the user, then that option is of course used.
copy: List of files/directories to copy to /root. e.g. [“src/file1.txt”, “src/file2.txt”]
- Parameters:
name (str)
python_version (str)
builder (str | None)
source_root (str | None)
env (Dict[str, str] | None)
registry (str | None)
packages (List[str] | None)
conda_packages (List[str] | None)
conda_channels (List[str] | None)
requirements (str | None)
apt_packages (List[str] | None)
cuda (str | None)
cudnn (str | None)
base_image (str | ImageSpec | None)
platform (str)
pip_index (str | None)
pip_extra_index_url (List[str] | None)
registry_config (str | None)
entrypoint (List[str] | None)
commands (List[str] | None)
tag_format (str | None)
source_copy_mode (CopyFileDetection | None)
copy (List[str] | None)
- exist()#
Check if the image exists in the registry. Return True if the image exists in the registry, False otherwise. Return None if failed to check if the image exists due to the permission issue or other reasons.
- Return type:
bool | None
- property id: str#
Calculate a unique hash as the ID for the ImageSpec, and it will be used to 1. Identify the imageSpec in the ImageConfig in the serialization context. 2. Check if the current container image in the pod is built from this image spec in is_container().
ImageConfig: - deduced abc: flyteorg/flytekit:123 - deduced xyz: flyteorg/flytekit:456
The result of this property also depends on whether or not update_image_spec_copy_handling was called.
- Returns:
a unique identifier of the ImageSpec
- image_name()#
Full image name with tag.
- Return type:
str
- is_container()#
Check if the current container image in the pod is built from current image spec. :return: True if the current container image in the pod is built from current image spec, False otherwise.
- Return type:
bool
- property tag: str#
Calculate a hash from the image spec. The hash will be the tag of the image. We will also read the content of the requirement file and the source root to calculate the hash. Therefore, it will generate different hash if new dependencies are added or the source code is changed.
Keep in mind the fields source_root and copy may be changed by update_image_spec_copy_handling, so when you call this property in relation to that function matter will change the output.
- with_apt_packages(apt_packages)#
Builder that returns a new image spec with an additional list of apt packages that will be executed during the building process.
- Parameters:
apt_packages (str | List[str])
- Return type:
- with_commands(commands)#
Builder that returns a new image spec with an additional list of commands that will be executed during the building process.
- Parameters:
commands (str | List[str])
- Return type:
- with_copy(src)#
Builder that returns a new image spec with the source files copied to the destination directory.
- Parameters:
src (str | List[str])
- Return type: