-
Notifications
You must be signed in to change notification settings - Fork 0
Update cache tags to prevent collisions #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,12 +91,22 @@ def serialize_path(value: Path | str) -> str: | |
| return str(value) | ||
|
|
||
| @classmethod | ||
| def from_image_target(cls, image_target: ImageTarget) -> "BakeTarget": | ||
| """Create a BakeTarget from an ImageTarget.""" | ||
| def from_image_target(cls, image_target: ImageTarget, platforms: list[str] | None = None) -> "BakeTarget": | ||
| """Create a BakeTarget from an ImageTarget. | ||
|
|
||
| :param image_target: The ImageTarget to create a BakeTarget from. | ||
| :param platforms: Optional platform override (e.g., from CLI --platform flag). When provided, this takes | ||
| precedence over the image target's OS platform configuration for cache tag generation. | ||
| """ | ||
| kwargs = {"tags": image_target.tags} | ||
| if image_target.cache_name is not None: | ||
| kwargs["cache_from"] = [{"type": "registry", "ref": image_target.cache_name}] | ||
| kwargs["cache_to"] = [{"type": "registry", "ref": image_target.cache_name, "mode": "max"}] | ||
| effective_platforms = platforms or ( | ||
| image_target.image_os.platforms if image_target.image_os is not None else DEFAULT_PLATFORMS | ||
| ) | ||
| cache_platform = effective_platforms[0] if len(effective_platforms) == 1 else None | ||
| cache_name = image_target.cache_name(platform=cache_platform) | ||
| if cache_name is not None: | ||
| kwargs["cache_from"] = [{"type": "registry", "ref": cache_name}] | ||
| kwargs["cache_to"] = [{"type": "registry", "ref": cache_name, "mode": "max"}] | ||
|
Comment on lines
+105
to
+109
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So in theory, bake should handle shared caching correctly for multiplatform builds?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is correct. When we use bake, the multi-platform builds are handled natively. |
||
|
|
||
| if image_target.temp_name is not None: | ||
| kwargs["tags"] = [image_target.temp_name.rsplit(":", 1)[0]] | ||
|
|
@@ -153,11 +163,15 @@ def update_groups( | |
| return groups | ||
|
|
||
| @classmethod | ||
| def from_image_targets(cls, context: Path, image_targets: list[ImageTarget]) -> "BakePlan": | ||
| def from_image_targets( | ||
| cls, context: Path, image_targets: list[ImageTarget], platforms: list[str] | None = None | ||
| ) -> "BakePlan": | ||
| """Create a BakePlan from a list of ImageTarget objects. | ||
|
|
||
| :param context: The absolute path to the build context directory. | ||
| :param image_targets: A list of ImageTarget objects to include in the bake plan. | ||
| :param platforms: Optional platform override (e.g., from CLI --platform flag). When provided, this takes | ||
| precedence over each image target's OS platform configuration for cache tag generation. | ||
|
|
||
| :return: A BakePlan object containing the context, groups, and targets. | ||
| """ | ||
|
|
@@ -167,7 +181,7 @@ def from_image_targets(cls, context: Path, image_targets: list[ImageTarget]) -> | |
| targets: dict[str, BakeTarget] = {} | ||
|
|
||
| for image_target in image_targets: | ||
| bake_target = BakeTarget.from_image_target(image_target=image_target) | ||
| bake_target = BakeTarget.from_image_target(image_target=image_target, platforms=platforms) | ||
| groups = cls.update_groups( | ||
| groups=groups, | ||
| uid=image_target.uid, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be the first time I've ever seen the walrus operator used in the real world 😆, clever way of doing it!