Skip to content

Commit 4c30e93

Browse files
popojkAtharva1723
authored andcommitted
[BUG] ImageSpec NoOpBuilder should always return True while calling should_build function (flyteorg#3311)
Signed-off-by: Alex Wu <[email protected]> Signed-off-by: Atharva <[email protected]>
1 parent a06e374 commit 4c30e93

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

flytekit/image_spec/noop_builder.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ class NoOpBuilder(ImageSpecBuilder):
66

77
builder_type = "noop"
88

9+
def should_build(self, image_spec: ImageSpec) -> bool:
10+
"""
11+
The build_image function of NoOpBuilder does not actually build a Docker image.
12+
Since no Docker build process occurs, we do not need to check for Docker daemon
13+
or existing images. Therefore, should_build should always return True.
14+
15+
Args:
16+
image_spec (ImageSpec): Image specification
17+
18+
Returns:
19+
bool: Always returns True
20+
"""
21+
return True
22+
923
def build_image(self, image_spec: ImageSpec) -> str:
1024
if not isinstance(image_spec.base_image, str):
1125
msg = "base_image must be a string to use the noop image builder"

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,38 @@ def test_with_builder_options():
359359
"existing_builder_option_1": "existing_builder_option_value_1",
360360
"new_builder_option_1": "new_builder_option_value_1"
361361
}
362+
363+
def test_noop_builder_updates_image_name_mapping():
364+
from flytekit.image_spec.noop_builder import NoOpBuilder
365+
366+
# Clear any existing mappings to ensure clean test state
367+
ImageBuildEngine._REGISTRY.pop("noop", None)
368+
ImageBuildEngine._IMAGE_NAME_TO_REAL_NAME.clear()
369+
370+
# Register NoOpBuilder
371+
ImageBuildEngine.register("noop", NoOpBuilder())
372+
373+
# Create an image spec with NoOpBuilder
374+
expected_image_name = "localhost:30000/test_image:latest"
375+
image_spec = ImageSpec(
376+
name="test_image",
377+
builder="noop",
378+
base_image=expected_image_name
379+
)
380+
381+
# Get the image name before building
382+
img_name = image_spec.image_name()
383+
384+
# Build the image
385+
ImageBuildEngine.build(image_spec)
386+
387+
# Verify that the mapping was created in _IMAGE_NAME_TO_REAL_NAME
388+
assert img_name in ImageBuildEngine._IMAGE_NAME_TO_REAL_NAME
389+
390+
# Verify the mapping value is correct
391+
actual_real_name = ImageBuildEngine._IMAGE_NAME_TO_REAL_NAME[img_name]
392+
assert actual_real_name == expected_image_name
393+
394+
# Clean up
395+
ImageBuildEngine._REGISTRY.pop("noop", None)
396+
ImageBuildEngine._IMAGE_NAME_TO_REAL_NAME.clear()

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ def test_noop_builder_error(base_image):
2222
image_spec = ImageSpec(base_image=base_image)
2323
with pytest.raises(ValueError, match=msg):
2424
builder.build_image(image_spec)
25+
26+
27+
def test_noop_builder_should_build():
28+
"""Test that NoOpBuilder.should_build always returns True."""
29+
builder = NoOpBuilder()
30+
31+
# Test with different image specs to ensure should_build always returns True
32+
test_cases = [
33+
ImageSpec(base_image="localhost:30000/flytekit"),
34+
ImageSpec(base_image="python:3.9"),
35+
ImageSpec(base_image="custom/image:latest"),
36+
]
37+
38+
for image_spec in test_cases:
39+
result = builder.should_build(image_spec)
40+
assert result is True, f"should_build should return True for {image_spec.base_image}"

0 commit comments

Comments
 (0)