<#3246 Make image_spec.tag a cached property> Pull...
# flyte-github
c
#3246 Make image_spec.tag a cached property Pull request opened by amitani ## Tracking issue N/A ## Why are the changes needed? Currently,
image_spec.tag
used by
image_spec.image_name()
calculates hash based on file contents every time. 1. This may lead to "ImagePullBackOff" when running the registered component, because flyte uses different image_name for registration from what is used in image build and push if the file content was modified while the image is built. 2. Going through files every time isn't efficient ## What changes were proposed in this pull request? 1. Make the
image_spec.tag
a cached_property, to avoid unnecessary recomputes. 2. If the image is actually built, check that the tag is still consistent with what was in the cache. This doesn't prevent if the content was just modified while creating docker context, but it should be rare. Alternative is to make image tag based on the created temporary context, but it will be a much bigger change. 3. This check is put right after context creation but before the build, because build is typically takes much longer and there is a higher chance of false alarm. ## How was this patch tested? Added a test to check if image build raises if cached tag is not consistent with the newly computed tag after context is created. I also manually checked that
ValueError
is raised at by
builder.build_image(image_spec)
if some file content is modified after
image_spec.image_name()
was called.
Copy code
from flytekit.image_spec import ImageSpec
from flytekit.image_spec.default_builder import DefaultImageBuilder                                          
image_spec = ImageSpec(name="my_flytekit", python_version="3.12", registry="localhost:30000", copy=['README.md'])
print(image_spec.image_name())
open('README.md', 'w').close()
builder = DefaultImageBuilder()
builder.build_image(image_spec)
raises
Copy code
ValueError: Hash-based image tag changed from hcychPh46DxCaAFG984sAg to AkFsLDxgsB7R45XBhl9EfA while creating the
context,indicating the content has been modified. Aborting because image tag may not match what is built.
### Setup process ### Screenshots ## Check all the applicable boxes • I updated the documentation accordingly. • All new and existing tests passed. • All commits are signed-off. ## Related PRs ## Docs link ### Summary by Bito This PR enhances the image_spec module with a cached_property for image tag computation, improving performance and reducing redundant file operations. It adds verification that hash-based tags remain unchanged during Docker context creation, ensuring image naming consistency and build reliability. The changes also fix a test to use the correct lock file path. Unit tests added: True Estimated effort to review (1-5, lower is better): 1 flyteorg/flytekit