File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff 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 ()))
Original file line number Diff line number Diff line change 1515"""Images integration tests."""
1616
1717import io
18+ import json
1819import platform
1920import tarfile
2021import 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\n LABEL 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 :
You can’t perform that action at this time.
0 commit comments