@@ -93,9 +93,15 @@ def serialize_path(value: Path | str) -> str:
9393 def from_image_target (cls , image_target : ImageTarget ) -> "BakeTarget" :
9494 """Create a BakeTarget from an ImageTarget."""
9595 kwargs = {"tags" : image_target .tags }
96+ platforms = image_target .image_os .platforms if image_target .image_os is not None else DEFAULT_PLATFORMS
97+
9698 if image_target .cache_name is not None :
97- kwargs ["cache_from" ] = [{"type" : "registry" , "ref" : image_target .cache_name }]
98- kwargs ["cache_to" ] = [{"type" : "registry" , "ref" : image_target .cache_name , "mode" : "max" }]
99+ cache_name = image_target .cache_name
100+ # Append platform suffix to cache name
101+ platform_suffix = "-" .join (p .removeprefix ("linux/" ).replace ("/" , "-" ) for p in platforms )
102+ cache_name = f"{ cache_name } -{ platform_suffix } "
103+ kwargs ["cache_from" ] = [{"type" : "registry" , "ref" : cache_name }]
104+ kwargs ["cache_to" ] = [{"type" : "registry" , "ref" : cache_name , "mode" : "max" }]
99105
100106 if image_target .temp_name is not None :
101107 kwargs ["tags" ] = [image_target .temp_name .rsplit (":" , 1 )[0 ]]
@@ -107,7 +113,7 @@ def from_image_target(cls, image_target: ImageTarget) -> "BakeTarget":
107113 image_os = image_target .image_os .name if image_target .image_os else None ,
108114 dockerfile = image_target .containerfile ,
109115 labels = image_target .labels ,
110- platforms = image_target . image_os . platforms if image_target . image_os is not None else DEFAULT_PLATFORMS ,
116+ platforms = platforms ,
111117 ** kwargs ,
112118 )
113119
0 commit comments