Skip to content

Commit 1bc8302

Browse files
authored
Add user-defined builder image in image spec (#3207)
Signed-off-by: Nelson Chen <[email protected]>
1 parent 8a4a19a commit 1bc8302

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

flytekit/image_spec/default_builder.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393

9494
DOCKER_FILE_TEMPLATE = Template("""\
9595
#syntax=docker/dockerfile:1.5
96-
FROM ghcr.io/astral-sh/uv:0.5.1 as uv
97-
FROM mambaorg/micromamba:2.0.3-debian12-slim as micromamba
96+
FROM $UV_IMAGE as uv
97+
FROM $MICROMAMBA_IMAGE as micromamba
9898
9999
FROM $BASE_IMAGE
100100
@@ -141,6 +141,9 @@
141141
echo "export PATH=$$PATH" >> $$HOME/.profile
142142
""")
143143

144+
DEFAULT_UV_IMAGE = "ghcr.io/astral-sh/uv:0.5.1"
145+
DEFAULT_MICROMAMBA_IMAGE = "mambaorg/micromamba:2.0.3-debian12-slim"
146+
144147

145148
def get_flytekit_for_pypi():
146149
"""Get flytekit version on PyPI."""
@@ -405,6 +408,12 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path):
405408
else:
406409
extra_copy_cmds = ""
407410

411+
uv_image = DEFAULT_UV_IMAGE
412+
micromamba_image = DEFAULT_MICROMAMBA_IMAGE
413+
if image_spec.builder_config is not None:
414+
uv_image = image_spec.builder_config.get("uv_image", uv_image)
415+
micromamba_image = image_spec.builder_config.get("micromamba_image", micromamba_image)
416+
408417
docker_content = DOCKER_FILE_TEMPLATE.substitute(
409418
UV_PYTHON_INSTALL_COMMAND=uv_python_install_command,
410419
APT_INSTALL_COMMAND=apt_install_command,
@@ -417,6 +426,8 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path):
417426
ENTRYPOINT=entrypoint,
418427
RUN_COMMANDS=run_commands,
419428
EXTRA_COPY_CMDS=extra_copy_cmds,
429+
UV_IMAGE=uv_image,
430+
MICROMAMBA_IMAGE=micromamba_image,
420431
)
421432

422433
dockerfile_path = tmp_dir / "Dockerfile"
@@ -452,6 +463,7 @@ class DefaultImageBuilder(ImageSpecBuilder):
452463
# "registry_config",
453464
"commands",
454465
"copy",
466+
"builder_config",
455467
}
456468

457469
def build_image(self, image_spec: ImageSpec) -> str:

flytekit/image_spec/image_spec.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class ImageSpec:
7474
use `builder="noop"`: `ImageSpec(base_image="ghcr.io/name/my-custom-image", builder="noop").with_runtime_packages(["numpy"])`.
7575
builder_options (Optional[Dict[str, Any]]): Additional options for the builder. This is a dictionary that will be passed to the builder.
7676
The options are builder-specific and may not be supported by all builders.
77+
builder_config (Optional[typing.Dict[str, typing.Any]]): Custom builder images configuration, such as uv and micromamba images.
7778
"""
7879

7980
name: str = "flytekit"
@@ -104,6 +105,7 @@ class ImageSpec:
104105
python_exec: Optional[str] = None
105106
runtime_packages: Optional[List[str]] = None
106107
builder_options: Optional[Dict[str, Any]] = None
108+
builder_config: Optional[typing.Dict[str, typing.Any]] = None
107109

108110
def __post_init__(self):
109111
self.name = self.name.lower()

tests/flytekit/unit/core/image_spec/test_default_builder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def test_create_docker_context(tmp_path):
4343
pip_secret_mounts=[(".gitconfig", '/etc/gitconfig'), ("secret_src_2", "secret_dst_2")],
4444
source_copy_mode=CopyFileDetection.ALL,
4545
copy=[tmp_file.relative_to(Path.cwd()).as_posix()],
46+
builder_config={"uv_image": "uv_image_local"},
4647
)
4748

4849
create_docker_context(image_spec, docker_context_path)
@@ -60,6 +61,8 @@ def test_create_docker_context(tmp_path):
6061
assert "--mount=type=secret,id=secret_0,target=/etc/gitconfig" in dockerfile_content
6162
assert "--mount=type=secret,id=secret_1,target=secret_dst_2" in dockerfile_content
6263
assert "COPY --chown=flytekit ./src /root" in dockerfile_content
64+
assert "uv_image_local" in dockerfile_content
65+
assert "mambaorg/micromamba:2.0.3-debian12-slim" in dockerfile_content
6366

6467
run_match = re.search(r"RUN.+mkdir my_dir", dockerfile_content)
6568
assert run_match

0 commit comments

Comments
 (0)