@@ -198,19 +198,15 @@ def _build_with_inject(
198198 self ,
199199 inject : dict ,
200200 image_ref : str ,
201+ path : str ,
201202 platform : str ,
202- context_path : str ,
203203 dockerfile : str ,
204- target : str ,
205204 build_args : dict ,
206- builder : Optional [str ],
207- cache : bool = False ,
208- pull : bool = False ,
209- secrets : Optional [List [str ]] = None ,
205+ build_kwargs : dict ,
210206 ) -> None :
211- if not context_path or not os .path .isdir (context_path ):
207+ if not path or not os .path .isdir (path ):
212208 LOGGER .warning (
213- f"Failed to inject { inject } for { image_ref } since path { context_path } isn't a directory."
209+ f"Failed to inject { inject } for { image_ref } since path { path } isn't a directory."
214210 )
215211 return
216212
@@ -220,14 +216,14 @@ def _build_with_inject(
220216 ) as tmp_dir :
221217 context_dir = os .path .join (tmp_dir , f"{ dir_prefix } /" )
222218 shutil .copytree (
223- context_path ,
219+ path ,
224220 context_dir ,
225221 ignore = shutil .ignore_patterns (dir_prefix , ".git" ),
226222 symlinks = True ,
227223 )
228224
229225 for src , dest in inject .items ():
230- src_path = os .path .join (context_path , src )
226+ src_path = os .path .join (path , src )
231227
232228 # Remove '/' prefix
233229 if dest .startswith ("/" ):
@@ -259,17 +255,13 @@ def _build_with_inject(
259255
260256 logs_itr = docker .buildx .build (
261257 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,29 +320,31 @@ 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 pull :
329+ build_kwargs ["pull" ] = pull
340330 if secrets :
341331 build_kwargs ["secrets" ] = secrets
332+ if target :
333+ build_kwargs ["target" ] = target
342334
343335 if inject and isinstance (inject , dict ):
344336 self ._build_with_inject (
337+ path = path ,
345338 inject = inject ,
346339 image_ref = image_ref ,
347340 platform = platform ,
348341 dockerfile = dockerfile ,
349342 build_args = build_args ,
350- ** build_kwargs ,
343+ build_kwargs = build_kwargs ,
351344 )
352345 else :
353346 logs_itr = docker .buildx .build (
347+ path ,
354348 tags = [image_ref ],
355349 platforms = [platform ],
356350 load = True ,
0 commit comments