From 195e795458fd6d72623f900f9a4ff0d49050ff94 Mon Sep 17 00:00:00 2001 From: redartera Date: Tue, 15 Apr 2025 13:17:11 +0000 Subject: [PATCH 1/2] move _F_IMG_ID to the bottom Signed-off-by: redartera --- flytekit/image_spec/default_builder.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/flytekit/image_spec/default_builder.py b/flytekit/image_spec/default_builder.py index 0eee2e422d..b98fdb1640 100644 --- a/flytekit/image_spec/default_builder.py +++ b/flytekit/image_spec/default_builder.py @@ -139,6 +139,11 @@ USER flytekit RUN mkdir -p $$HOME && \ echo "export PATH=$$PATH" >> $$HOME/.profile + +# NOTE: Important to set this env var all the way at the bottom +# Otherwise the slightest change to an imagespec's ID would unnecessarily invalidate +# too many layers in the build cache. +ENV $_F_IMG_ID_ENV """) @@ -329,7 +334,7 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path): raise ValueError(msg) uv_python_install_command = prepare_python_install(image_spec, tmp_dir) - env_dict = {"PYTHONPATH": "/root", _F_IMG_ID: image_spec.id} + env_dict = {"PYTHONPATH": "/root"} if image_spec.env: env_dict.update(image_spec.env) @@ -405,6 +410,8 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path): else: extra_copy_cmds = "" + _f_img_id_env = f"{_F_IMG_ID}={image_spec.id}" + docker_content = DOCKER_FILE_TEMPLATE.substitute( UV_PYTHON_INSTALL_COMMAND=uv_python_install_command, APT_INSTALL_COMMAND=apt_install_command, @@ -413,6 +420,7 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path): PYTHON_EXEC=python_install_template.python_exec, BASE_IMAGE=base_image, ENV=env, + _F_IMG_ID_ENV=_f_img_id_env, COPY_COMMAND_RUNTIME=copy_command_runtime, ENTRYPOINT=entrypoint, RUN_COMMANDS=run_commands, From 02c6513360327201a8af70537668653615768aa5 Mon Sep 17 00:00:00 2001 From: redartera Date: Sun, 4 May 2025 11:30:39 +0000 Subject: [PATCH 2/2] apply lint Signed-off-by: redartera --- flytekit/image_spec/default_builder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flytekit/image_spec/default_builder.py b/flytekit/image_spec/default_builder.py index 71f2e24aad..c3f29e185c 100644 --- a/flytekit/image_spec/default_builder.py +++ b/flytekit/image_spec/default_builder.py @@ -418,7 +418,7 @@ def create_docker_context(image_spec: ImageSpec, tmp_dir: Path): if image_spec.builder_config is not None: uv_image = image_spec.builder_config.get("uv_image", uv_image) micromamba_image = image_spec.builder_config.get("micromamba_image", micromamba_image) - + _f_img_id_env = f"{_F_IMG_ID}={image_spec.id}" docker_content = DOCKER_FILE_TEMPLATE.substitute(