[feature/caching-rework] Centralize build planning - #2207
Open
lbussell wants to merge 9 commits into
Open
Conversation
Replace ad hoc cache checks with graph-based planning shared by matrix generation, build execution, and stale-image detection. Add composable policies, explicit actions, and causal explanations. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1d9f1ac1-4713-44b4-a6ba-17cb095984f6
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1d9f1ac1-4713-44b4-a6ba-17cb095984f6
lbussell
marked this pull request as ready for review
August 5, 2026 21:02
mthalman
reviewed
Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR centralizes build planning and policies across multiple separate commands. The design is not perfect as-is but I would like to work on improving it incrementally.
Design
The design centers around three new types:
BuildGraph,BuildPlanner, andIBuildPolicy.A
BuildGraphrepresents the relationships between the images in the manifest.The
BuildPlannertakes theBuildGraphin combination with anIBuildPolicyand uses it to determine what actions need to be taken.classDiagram direction LR class BuildCommand { } class GenerateBuildMatrixCommand { } class GetStaleImagesCommand { } class BuildTarget { } class BuildGraph { +Targets +Parents +Children +SharedBuildTargets } class BuildPlanner { +CreatePlanAsync(graph, imageInfo, policy) } class IBuildPolicy { } class BuildPlanItem { +Target +Action +Reasons +PublishedImage } class BuildAction { NoAction UsePublishedImage PublishExistingImage BuildImage } class BuildReason { +Message +Cause } class PublishedImage { +Source +Image +SharedTags } BuildCommand --> BuildGraph : creates GenerateBuildMatrixCommand --> BuildGraph : creates GetStaleImagesCommand --> BuildGraph : creates BuildCommand --> BuildPlanner : executes build plan GenerateBuildMatrixCommand --> BuildPlanner : uses for trimming GetStaleImagesCommand --> BuildPlanner : checks for stale images BuildGraph *-- BuildTarget BuildPlanner --> BuildGraph BuildPlanner --> IBuildPolicy : evaluates BuildPlanner --> BuildPlanItem : produces BuildPlanItem --> BuildTarget BuildPlanItem --> BuildAction BuildPlanItem *-- BuildReason BuildPlanItem --> PublishedImage PublishedImage --> BuildTarget : metadata sourceBuild policies
There are multiple "policies" that we check images against to determine what actions to take. Previously, all these checks were strewn about the codebase and not managed centrally anywhere.
The
CompositeBuildPolicycombines multiple different build policies into one that we can pass to the build planner.classDiagram direction LR class IBuildPolicy { +EvaluateAsync(context) BuildPolicyResult } class BuildPolicyContext { +BuildGraph Graph +BuildTarget Target +PublishedImages } class BuildPolicyResult { +BuildAction Action +BuildReason[] Reasons } class CompositeBuildPolicy { } class AlwaysBuildPolicy { } class MissingPublishedImagePolicy { } class TagSetChangedPolicy { } class DockerfileChangedPolicy { } class BaseImageChangedPolicy { } class ImageDigestCache { } class IGitService { } IBuildPolicy <|.. CompositeBuildPolicy IBuildPolicy <|.. AlwaysBuildPolicy IBuildPolicy <|.. MissingPublishedImagePolicy IBuildPolicy <|.. TagSetChangedPolicy IBuildPolicy <|.. DockerfileChangedPolicy IBuildPolicy <|.. BaseImageChangedPolicy IBuildPolicy --> BuildPolicyContext : input IBuildPolicy --> BuildPolicyResult : output CompositeBuildPolicy o-- IBuildPolicy : combines BuildPolicyResult --> BuildAction BuildPolicyResult *-- BuildReason BuildPolicyContext --> BuildGraph BuildPolicyContext --> BuildTarget BuildPolicyContext --> PublishedImage BaseImageChangedPolicy --> ImageDigestCache DockerfileChangedPolicy --> IGitService