flytekit.image_spec.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)[source]#
This class is used to specify the docker image that will be used to run the task.
- Parameters:
name (str) – name of the image.
python_version (str) – python version of the image. Use default python in the base image if None.
builder (str | None) – Type of plugin to build the image. Use envd by default.
source_root (str | None) – source root of the image.
env (Dict[str, str] | None) – environment variables of the image.
registry (str | None) – registry of the image.
packages (List[str] | None) – list of python packages to install.
conda_packages (List[str] | None) – list of conda packages to install.
requirements (str | None) – path to the requirements.txt file.
apt_packages (List[str] | None) – list of apt packages to install.
cuda (str | None) – version of cuda to install.
cudnn (str | None) – version of cudnn to install.
base_image (str | ImageSpec | None) – base image of the image.
platform (str) – Specify the target platforms for the build output (for example, windows/amd64 or linux/amd64,darwin/arm64
pip_index (str | None) – Specify the custom pip index url
pip_extra_index_url (List[str] | None) – Specify one or more pip index urls as a list
registry_config (str | None) – Specify the path to a JSON registry config file
entrypoint (List[str] | None) – List of strings to overwrite the entrypoint of the base image with, set to [] to remove the entrypoint.
commands (List[str] | None) – Command to run during the building process
tag_format (str | None) – 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 (CopyFileDetection | None) –
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[str] | None) – List of files/directories to copy to /root. e.g. [“src/file1.txt”, “src/file2.txt”]
Methods
- exist()[source]#
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
- is_container()[source]#
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:
- with_apt_packages(apt_packages)[source]#
Builder that returns a new image spec with an additional list of apt packages that will be executed during the building process.
- with_commands(commands)[source]#
Builder that returns a new image spec with an additional list of commands that will be executed during the building process.
- with_copy(src)[source]#
Builder that returns a new image spec with the source files copied to the destination directory.
- with_packages(packages)[source]#
Builder that returns a new image speck with additional python packages that will be installed during the building process.
Attributes
- id
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
- name: str = 'flytekit'
- platform: str = 'linux/amd64'
- python_version: str = None
- source_copy_mode: CopyFileDetection | None = None
- tag
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.