Skip to main content

Image

Container image specification built using a fluent, two-step pattern:

  1. Create a base image with a from_* constructor
  2. Customize with with_* methods (each returns a new Image)

Attributes​

AttributeTypeDescription
base_imagestr = nullThe full URI of the starting container image used as the foundation for this specification.
dockerfilePath = nullA file path to a custom Dockerfile used to build the image, which disables further layering.
registrystr = nullThe container registry where the image will be pushed to or pulled from.
namestr = nullThe identifier for the image used to construct the final URI and reference it in configuration.
platformTuple[Architecture, ...] = ("linux/amd64",)The target CPU architectures for the build, defaulting to linux/amd64.
python_versionTuple[int, int] = nullThe specific version of Python to be installed or expected within the container environment.
extendableboolean = falseWhether the image is extendable by other images, allowing additional layers to be added on top of it.

Methods​


validate()​

@classmethod
def validate()

Iterates through all defined image layers and triggers their individual validation logic.


from_debian_base()​

@classmethod
def from_debian_base(
python_version: Optional[Tuple[int, int]],
flyte_version: Optional[str],
install_flyte: bool,
registry: Optional[str],
registry_secret: Optional[str | Secret],
name: Optional[str],
platform: Optional[Tuple[Architecture, ...]]
) - > [Image](image.md?sid=flyte__image_image)

Use this method to start using the default base image, built from this library's base Dockerfile. Default images are multi-arch amd/arm64.

Parameters​

NameTypeDescription
python_versionOptional[Tuple[int, int]]If not specified, will use the current Python version.
flyte_versionOptional[str]Flyte version to use.
install_flyteboolIf True, will install the flyte library in the image.
registryOptional[str]Registry to use for the image.
registry_secret`Optional[strSecret]`
nameOptional[str]Name of the image if you want to override the default name.
platformOptional[Tuple[Architecture, ...]]Platform to use for the image, default is linux/amd64, use tuple for multiple values.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)An Image instance based on the standard Debian distribution.

from_base()​

@classmethod
def from_base(
image_uri: str
) - > [Image](image.md?sid=flyte__image_image)

Use this method to start with a pre-built base image. This image must already exist in the registry of course.

Parameters​

NameTypeDescription
image_uristrThe full URI of the image, in the format < registry >/< name >:< tag >.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)An Image instance referencing the provided URI.

from_ref_name()​

@classmethod
def from_ref_name(
name: str
) - > [Image](image.md?sid=flyte__image_image)

Creates an Image reference using a logical name that maps to a pre-configured image URI.

Parameters​

NameTypeDescription
namestrThe logical reference name defined in CLI or configuration.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)An Image instance associated with the reference name.

from_uv_script()​

@classmethod
def from_uv_script(
script: Path | str,
name: str,
registry: str | None,
registry_secret: Optional[str | Secret],
python_version: Optional[Tuple[int, int]],
index_url: Optional[str],
extra_index_urls: Union[str, List[str], Tuple[str, ...], None],
pre: bool,
extra_args: Optional[str],
platform: Optional[Tuple[Architecture, ...]],
secret_mounts: Optional[SecretRequest]
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified uv script. It uses the header of the script to determine the python version, dependencies to install.

Parameters​

NameTypeDescription
script`Pathstr`
namestrName of the resulting image.
registry`strNone`
registry_secret`Optional[strSecret]`
python_versionOptional[Tuple[int, int]]Python version for the image; defaults to current version.
index_urlOptional[str]Primary package index URL.
extra_index_urlsUnion[str, List[str], Tuple[str, ...], None]Additional package index URLs.
preboolWhether to allow pre-release package versions.
extra_argsOptional[str]Extra arguments to pass to the package installer.
platformOptional[Tuple[Architecture, ...]]Target architectures for the image.
secret_mountsOptional[SecretRequest]Secrets to mount during the build process.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)An Image instance configured to run the specified uv script.

clone()​

@classmethod
def clone(
registry: Optional[str],
registry_secret: Optional[str | Secret],
name: Optional[str],
base_image: Optional[str],
python_version: Optional[Tuple[int, int]],
addl_layer: Optional[Layer],
extendable: Optional[bool]
) - > [Image](image.md?sid=flyte__image_image)

Clone an existing image, optionally with a new name or registry.

Parameters​

NameTypeDescription
registryOptional[str]Registry to use for the image.
registry_secret`Optional[strSecret]`
nameOptional[str]Name of the image.
base_imageOptional[str]Base image to use for the image.
python_versionOptional[Tuple[int, int]]Python version for the image.
addl_layerOptional[Layer]Additional layer to add to the end of the image layers.
extendableOptional[bool]Whether the image can serve as a base for further layers.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance with the updated properties and layers.

from_dockerfile()​

@classmethod
def from_dockerfile(
file: Union[Path, str],
registry: str,
name: str,
platform: Union[Architecture, Tuple[Architecture, ...], None]
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified dockerfile. Note you cannot use additional layers after this.

Parameters​

NameTypeDescription
fileUnion[Path, str]Path to the Dockerfile.
registrystrRegistry to use for the image.
namestrName of the image.
platformUnion[Architecture, Tuple[Architecture, ...], None]Target architectures for the build.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)An Image instance defined by the provided Dockerfile.

uri()​

@classmethod
def uri() - > str

Returns the URI of the image in the format < registry >/< name >:< tag >.

Returns​

TypeDescription
strThe full resolvable URI of the image.

with_workdir()​

@classmethod
def with_workdir(
workdir: str
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified working directory. This will override any existing working directory.

Parameters​

NameTypeDescription
workdirstrThe absolute path to set as the container's working directory.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance with the updated working directory.

with_requirements()​

@classmethod
def with_requirements(
file: str | Path,
index_url: Optional[str],
extra_index_urls: Union[str, List[str], Tuple[str, ...], None],
pre: bool,
extra_args: Optional[str],
secret_mounts: Optional[SecretRequest]
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified requirements file layered on top of the current image. Cannot be used in conjunction with conda.

Parameters​

NameTypeDescription
file`strPath`
index_urlOptional[str]Primary package index URL.
extra_index_urlsUnion[str, List[str], Tuple[str, ...], None]Additional package index URLs.
preboolIf True, install pre-release packages.
extra_argsOptional[str]Extra arguments to pass to pip install.
secret_mountsOptional[SecretRequest]Secrets to mount during the build process.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance with the requirements file layer added.

with_pip_packages()​

@classmethod
def with_pip_packages(
*packages: str,
index_url: Optional[str],
extra_index_urls: Union[str, List[str], Tuple[str, ...], None],
pre: bool,
extra_args: Optional[str],
secret_mounts: Optional[SecretRequest]
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified pip packages layered on top of the current image. Cannot be used in conjunction with conda.

Parameters​

NameTypeDescription
*packagesstrList of pip packages to install, following pip install syntax.
index_urlOptional[str]Primary package index URL.
extra_index_urlsUnion[str, List[str], Tuple[str, ...], None]Additional package index URLs.
preboolWhether to allow pre-release versions.
extra_argsOptional[str]Extra arguments to pass to pip install.
secret_mountsOptional[SecretRequest]Secrets to mount during the build process.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance with the specified pip packages installed.

with_env_vars()​

@classmethod
def with_env_vars(
env_vars: Dict[str, str]
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified environment variables layered on top of the current image. Cannot be used in conjunction with conda.

Parameters​

NameTypeDescription
env_varsDict[str, str]Dictionary of environment variable keys and values.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance with the environment variables set.

with_source_folder()​

@classmethod
def with_source_folder(
src: Path,
dst: str,
copy_contents_only: bool
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified local directory layered on top of the current image.

Parameters​

NameTypeDescription
srcPathRoot folder of the source code from the build context to be copied.
dststrDestination folder path within the image.
copy_contents_onlyboolIf True, copies the contents of the source folder instead of the folder itself.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance containing the copied folder.

with_source_file()​

@classmethod
def with_source_file(
src: typing.Union[Path, typing.List[Path]],
dst: str
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified local file(s) layered on top of the current image.

Parameters​

NameTypeDescription
srctyping.Union[Path, typing.List[Path]]File or list of files from the build context to be copied.
dststrDestination folder path within the image.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance containing the copied file(s).

with_code_bundle()​

@classmethod
def with_code_bundle(
copy_style: Literal["loaded_modules", "all"],
dst: str
) - > [Image](image.md?sid=flyte__image_image)

Configure this image to automatically copy source code from root_dir when the runner's copy_style is "none".

Parameters​

NameTypeDescription
copy_styleLiteral["loaded_modules", "all"]Which files to copy: only imported modules or all files from root_dir.
dststrDestination directory in the container.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance with code bundling configured.

with_dockerignore()​

@classmethod
def with_dockerignore(
path: Path
) - > [Image](image.md?sid=flyte__image_image)

Adds a .dockerignore file to the image build context to exclude specific files and directories.

Parameters​

NameTypeDescription
pathPathPath to the .dockerignore file.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance with the dockerignore layer added.

with_uv_project()​

@classmethod
def with_uv_project(
pyproject_file: str | Path,
uvlock: Path | None,
index_url: Optional[str],
extra_index_urls: Union[List[str], Tuple[str, ...], None],
pre: bool,
extra_args: Optional[str],
secret_mounts: Optional[SecretRequest],
project_install_mode: typing.Literal["dependencies_only", "install_project"]
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified uv.lock file layered on top of the current image. Must have a corresponding pyproject.toml file in the same directory.

Parameters​

NameTypeDescription
pyproject_file`strPath`
uvlock`PathNone`
index_urlOptional[str]Primary package index URL.
extra_index_urlsUnion[List[str], Tuple[str, ...], None]Additional package index URLs.
preboolWhether to allow pre-release versions.
extra_argsOptional[str]Extra arguments to pass to pip install.
secret_mountsOptional[SecretRequest]Secrets to mount during the build process.
project_install_modetyping.Literal["dependencies_only", "install_project"]Whether to install only dependencies or the project itself as a package.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance with the uv project dependencies installed.

with_poetry_project()​

@classmethod
def with_poetry_project(
pyproject_file: str | Path,
poetry_lock: Path | None,
extra_args: Optional[str],
secret_mounts: Optional[SecretRequest],
project_install_mode: typing.Literal["dependencies_only", "install_project"]
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified pyproject.toml layered on top of the current image. Must have a corresponding pyproject.toml file in the same directory.

Parameters​

NameTypeDescription
pyproject_file`strPath`
poetry_lock`PathNone`
extra_argsOptional[str]Extra arguments to pass to the package installer.
secret_mountsOptional[SecretRequest]Secrets to mount during the build process.
project_install_modetyping.Literal["dependencies_only", "install_project"]Whether to install only dependencies or the project itself as a package.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance with the Poetry project dependencies installed.

with_apt_packages()​

@classmethod
def with_apt_packages(
*packages: str,
secret_mounts: Optional[SecretRequest]
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified apt packages layered on top of the current image.

Parameters​

NameTypeDescription
*packagesstrList of apt packages to install.
secret_mountsOptional[SecretRequest]Secrets to mount during the build process.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance with the system packages installed.

with_commands()​

@classmethod
def with_commands(
commands: List[str],
secret_mounts: Optional[SecretRequest]
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the specified commands layered on top of the current image. Be sure not to use RUN in your command.

Parameters​

NameTypeDescription
commandsList[str]List of shell commands to run.
secret_mountsOptional[SecretRequest]Secrets to mount during the build process.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance that will execute the specified commands during build.

with_local_v2()​

@classmethod
def with_local_v2() - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the local v2 builder. This will override any existing builder.

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance configured for local v2 execution.

with_local_v2_plugins()​

@classmethod
def with_local_v2_plugins(
plugins: str | list[str]| None
) - > [Image](image.md?sid=flyte__image_image)

Use this method to create a new image with the local v2 builder. This will override any existing builder.

Parameters​

NameTypeDescription
plugins`strlist[str]

Returns​

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image instance with the specified local plugins installed.