@@ -199,15 +199,12 @@ def _build_with_inject(
199199 inject : dict ,
200200 image_ref : str ,
201201 platform : str ,
202- context_path : str ,
203202 dockerfile : str ,
204- target : str ,
205203 build_args : dict ,
206- builder : Optional [str ],
207- cache : bool = False ,
208- pull : bool = False ,
209- secrets : Optional [List [str ]] = None ,
204+ build_kwargs : dict ,
210205 ) -> None :
206+ context_path = build_kwargs .get ("context_path" )
207+
211208 if not context_path or not os .path .isdir (context_path ):
212209 LOGGER .warning (
213210 f"Failed to inject { inject } for { image_ref } since path { context_path } isn't a directory."
@@ -258,18 +255,13 @@ def _build_with_inject(
258255 ), f"Failed to create context dir { context_dir } "
259256
260257 logs_itr = docker .buildx .build (
261- context_dir ,
262- tags = [image_ref ],
263- platforms = [platform ],
264- load = True ,
265- target = target ,
266- builder = builder ,
267258 build_args = build_args ,
268- cache = cache ,
269- pull = pull ,
259+ load = True ,
260+ platforms = [ platform ] ,
270261 stream_logs = True ,
271- secrets = secrets ,
272- ** self ._get_build_cache_options (builder ),
262+ tags = [image_ref ],
263+ ** build_kwargs ,
264+ ** self ._get_build_cache_options (build_kwargs .get ("builder" )),
273265 )
274266 self ._log_buildx (logs_itr , platform )
275267
@@ -328,17 +320,19 @@ def _build_single_image(
328320 )
329321
330322 # Build kwargs for the buildx build command
331- build_kwargs = {
332- " builder" : builder ,
333- "cache" : cache ,
334- "context_path" : path ,
335- "pull" : pull ,
336- "target" : target ,
337- }
338-
339- # Only pass secrets if they are provided
323+ build_kwargs = {}
324+ if builder :
325+ build_kwargs [ "builder" ] = builder
326+ if cache :
327+ build_kwargs [ "cache" ] = cache
328+ if path :
329+ build_kwargs [ "context_path" ] = path
330+ if pull :
331+ build_kwargs [ "pull" ] = pull
340332 if secrets :
341333 build_kwargs ["secrets" ] = secrets
334+ if target :
335+ build_kwargs ["target" ] = target
342336
343337 if inject and isinstance (inject , dict ):
344338 self ._build_with_inject (
@@ -347,7 +341,7 @@ def _build_single_image(
347341 platform = platform ,
348342 dockerfile = dockerfile ,
349343 build_args = build_args ,
350- ** build_kwargs ,
344+ build_kwargs = build_kwargs ,
351345 )
352346 else :
353347 logs_itr = docker .buildx .build (
0 commit comments