Skip to content

Commit c81d0f5

Browse files
committed
Only push the cache when pushing the image
1 parent 40ec493 commit c81d0f5

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

posit-bakery/posit_bakery/config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ def build_targets(
752752
:param fail_fast: If True, stop building targets on the first failure.
753753
"""
754754
if strategy == ImageBuildStrategy.BAKE:
755-
bake_plan = BakePlan.from_image_targets(context=self.base_path, image_targets=self.targets)
755+
bake_plan = BakePlan.from_image_targets(context=self.base_path, image_targets=self.targets, push=push)
756756
set_opts = None
757757
if self.settings.temp_registry is not None and push:
758758
set_opts = {

posit-bakery/posit_bakery/image/bake/bake.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)