Skip to content

fix image build not using cache #559

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions podman/domain/images_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,16 @@ def _render_params(kwargs) -> dict[str, list[Any]]:
if "labels" in kwargs:
params["labels"] = json.dumps(kwargs.get("labels"))

if params["dockerfile"] is None:
params["dockerfile"] = f".containerfile.{random.getrandbits(160):x}"
def default(value, def_value):
return def_value if value is None else value

params["outputformat"] = default(
params["outputformat"], "application/vnd.oci.image.manifest.v1+json"
)
params["layers"] = default(params["layers"], True)
params["dockerfile"] = default(
params["dockerfile"], f".containerfile.{random.getrandbits(160):x}"
)

# Remove any unset parameters
return dict(filter(lambda i: i[1] is not None, params.items()))
14 changes: 14 additions & 0 deletions podman/tests/integration/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""Images integration tests."""

import io
import json
import platform
import tarfile
import types
Expand Down Expand Up @@ -144,6 +145,19 @@ def test_build(self):
self.assertIsNotNone(image)
self.assertIsNotNone(image.id)

def test_build_cache(self):
"""Check that building twice the same image uses caching"""
buffer = io.StringIO("""FROM quay.io/libpod/alpine_labels:latest\nLABEL test=value""")
image, _ = self.client.images.build(fileobj=buffer)
buffer.seek(0)
_, stream = self.client.images.build(fileobj=buffer)
for line in stream:
# Search for a line with contents "-> Using cache <image id>"
parsed = json.loads(line)['stream']
if "Using cache" in parsed:
break
self.assertEqual(parsed.split()[3], image.id)

def test_build_with_context(self):
context = io.BytesIO()
with tarfile.open(fileobj=context, mode="w") as tar:
Expand Down