Skip to content

Commit 8864814

Browse files
fix image build not using cache
This commit fixes issue #528 by adding a default value to parameters layers and outputformat. This change aligns the behavior with podman-remote. Signed-off-by: Federico Rizzo <[email protected]>
1 parent bfc70e6 commit 8864814

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

podman/domain/images_build.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,16 @@ def _render_params(kwargs) -> dict[str, list[Any]]:
204204
if "labels" in kwargs:
205205
params["labels"] = json.dumps(kwargs.get("labels"))
206206

207-
if params["dockerfile"] is None:
208-
params["dockerfile"] = f".containerfile.{random.getrandbits(160):x}"
207+
def default(value, def_value):
208+
return def_value if value is None else value
209+
210+
params["outputformat"] = default(
211+
params["outputformat"], "application/vnd.oci.image.manifest.v1+json"
212+
)
213+
params["layers"] = default(params["layers"], True)
214+
params["dockerfile"] = default(
215+
params["dockerfile"], f".containerfile.{random.getrandbits(160):x}"
216+
)
209217

210218
# Remove any unset parameters
211219
return dict(filter(lambda i: i[1] is not None, params.items()))

podman/tests/integration/test_images.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Images integration tests."""
1616

1717
import io
18+
import json
1819
import platform
1920
import tarfile
2021
import types
@@ -144,6 +145,19 @@ def test_build(self):
144145
self.assertIsNotNone(image)
145146
self.assertIsNotNone(image.id)
146147

148+
def test_build_cache(self):
149+
"""Check that building twice the same image uses caching"""
150+
buffer = io.StringIO("""FROM quay.io/libpod/alpine_labels:latest\nLABEL test=value""")
151+
image, _ = self.client.images.build(fileobj=buffer)
152+
buffer.seek(0)
153+
_, stream = self.client.images.build(fileobj=buffer)
154+
for line in stream:
155+
# Search for a line with contents "-> Using cache <image id>"
156+
parsed = json.loads(line)['stream']
157+
if "Using cache" in parsed:
158+
break
159+
self.assertEqual(parsed.split()[3], image.id)
160+
147161
def test_build_with_context(self):
148162
context = io.BytesIO()
149163
with tarfile.open(fileobj=context, mode="w") as tar:

0 commit comments

Comments
 (0)