Set _F_IMG_ID env var all the way at the bottom during ImageSpec builds#3227
Conversation
Code Review Agent Run #e7657bActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Changelist by BitoThis pull request implements the following key changes.
|
fb9edb3 to
915badb
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3227 +/- ##
===========================================
+ Coverage 81.52% 93.20% +11.68%
===========================================
Files 343 37 -306
Lines 28627 2370 -26257
Branches 2935 0 -2935
===========================================
- Hits 23338 2209 -21129
+ Misses 4445 161 -4284
+ Partials 844 0 -844 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code Review Agent Run #0b48aaActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Signed-off-by: redartera <reda@artera.ai>
915badb to
195e795
Compare
Code Review Agent Run #133435Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Code Review Agent Run Status
|
Code Review Agent Run Status
|
pingsutw
left a comment
There was a problem hiding this comment.
Should we just move $ENV to the end of the Dockerfile? cc @thomasjpfan
It's hard to say, if one sets any of the UV environment variables, then you'll want the environment variables before the UV install command. |
+1 to @thomasjpfan - I preferred to only move |
Signed-off-by: redartera <reda@artera.ai>
Code Review Agent Run #b6be55Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Code Review Agent Run Status
|
…builds (flyteorg#3227) Signed-off-by: redartera <reda@artera.ai> Signed-off-by: Atharva <atharvakulkarni172003@gmail.com>
Why are the changes needed?
Docker build caching is highly sensitive to the order of operations in a Dockerfile. Currently, the
_F_IMG_IDenvironment variable (which contains a hash of theImageSpecdataclass) is set near the top of the generated Dockerfile. When this value changes due to modifications in the ImageSpec, it invalidates the cache for that layer and all subsequent layers, causing unnecessary rebuilds of the Python environment even when those layers haven't changed functionally (e.g.pythondependencies have remained the same but something changed in thecommandsorcopyblock following it)What changes were proposed in this pull request?
This PR moves the
_F_IMG_IDenvironment variable declaration to the bottom of the generated Dockerfile, after all major build steps (like uv/poetry/pip env installations). This placement ensures that changes to theImageSpecas a whole only invalidate the layers that are directly affected, preventing costly rebuilds of the Python environment when only commands or other non-environment components change.How was this patch tested?
The change was tested locally by modifying
flytekitand observing Docker build behavior. When the_F_IMG_IDis placed at the bottom of the Dockerfile, changes to components likecommandsonly invalidate the cache for those specific layers and what follows them, preserving the cache for expensive operations like Poetry environment setup.This improvement reduces build times and registry storage space by maintaining slightly better cache consistency, especially for iterative development workflows where small changes shouldn't trigger full environment rebuilds.
Summary by Bito
This PR optimizes Dockerfile generation by repositioning the _F_IMG_ID environment variable to the end of the build process. This strategic change preserves cache layers for steps unaffected by ImageSpec changes, preventing unnecessary rebuilds when only non-critical configuration changes occur. This significantly improves build times, reduces storage requirements, and enhances overall Docker build performance during development.Unit tests added: False
Estimated effort to review (1-5, lower is better): 1