@@ -90,7 +90,7 @@ def serialize_path(value: Path | str) -> str:
9090 return str (value )
9191
9292 @classmethod
93- def from_image_target (cls , image_target : ImageTarget ) -> "BakeTarget" :
93+ def from_image_target (cls , image_target : ImageTarget , push : bool = False ) -> "BakeTarget" :
9494 """Create a BakeTarget from an ImageTarget."""
9595 kwargs = {"tags" : image_target .tags }
9696 platforms = image_target .image_os .platforms if image_target .image_os is not None else DEFAULT_PLATFORMS
@@ -101,7 +101,8 @@ def from_image_target(cls, image_target: ImageTarget) -> "BakeTarget":
101101 platform_suffix = "-" .join (p .removeprefix ("linux/" ).replace ("/" , "-" ) for p in platforms )
102102 cache_name = f"{ cache_name } -{ platform_suffix } "
103103 kwargs ["cache_from" ] = [{"type" : "registry" , "ref" : cache_name }]
104- kwargs ["cache_to" ] = [{"type" : "registry" , "ref" : cache_name , "mode" : "max" }]
104+ if push :
105+ kwargs ["cache_to" ] = [{"type" : "registry" , "ref" : cache_name , "mode" : "max" }]
105106
106107 if image_target .temp_name is not None :
107108 kwargs ["tags" ] = [image_target .temp_name .rsplit (":" , 1 )[0 ]]
@@ -157,11 +158,12 @@ def update_groups(
157158 return groups
158159
159160 @classmethod
160- def from_image_targets (cls , context : Path , image_targets : list [ImageTarget ]) -> "BakePlan" :
161+ def from_image_targets (cls , context : Path , image_targets : list [ImageTarget ], push : bool = False ) -> "BakePlan" :
161162 """Create a BakePlan from a list of ImageTarget objects.
162163
163164 :param context: The absolute path to the build context directory.
164165 :param image_targets: A list of ImageTarget objects to include in the bake plan.
166+ :param push: Whether images will be pushed. Controls cache_to behavior.
165167
166168 :return: A BakePlan object containing the context, groups, and targets.
167169 """
@@ -171,7 +173,7 @@ def from_image_targets(cls, context: Path, image_targets: list[ImageTarget]) ->
171173 targets : dict [str , BakeTarget ] = {}
172174
173175 for image_target in image_targets :
174- bake_target = BakeTarget .from_image_target (image_target = image_target )
176+ bake_target = BakeTarget .from_image_target (image_target = image_target , push = push )
175177 groups = cls .update_groups (
176178 groups = groups ,
177179 uid = image_target .uid ,
0 commit comments