@@ -80,6 +80,7 @@ def __init__(
8080 cache_builders : Optional [List [str ]] = None ,
8181 cache_from : Optional [Union [dict , str ]] = None ,
8282 cache_to : Optional [Union [dict , str ]] = None ,
83+ secrets : Optional [List [str ]] = None ,
8384 ):
8485 self ._docker_registry = docker_registry
8586 self ._build_registry = build_registry
@@ -89,6 +90,7 @@ def __init__(
8990 self ._cache_builders = set (cache_builders if cache_builders else [])
9091 self ._cache_from = cache_from
9192 self ._cache_to = cache_to
93+ self ._secrets = secrets
9294 if self ._cache_from or self ._cache_to :
9395 LOGGER .info (
9496 f'Configuring multiplatform builds to cache from { cache_from } and to { cache_to } '
@@ -197,17 +199,18 @@ def _build_with_inject(
197199 inject : dict ,
198200 image_ref : str ,
199201 platform : str ,
200- path : str ,
202+ context_path : str ,
201203 dockerfile : str ,
202204 target : str ,
203205 build_args : dict ,
204206 builder : Optional [str ],
205207 cache : bool = False ,
206208 pull : bool = False ,
209+ secrets : Optional [List [str ]] = None ,
207210 ) -> None :
208- if not path or not os .path .isdir (path ):
211+ if not context_path or not os .path .isdir (context_path ):
209212 LOGGER .warning (
210- f"Failed to inject { inject } for { image_ref } since path { path } isn't a directory."
213+ f"Failed to inject { inject } for { image_ref } since path { context_path } isn't a directory."
211214 )
212215 return
213216
@@ -217,14 +220,14 @@ def _build_with_inject(
217220 ) as tmp_dir :
218221 context_dir = os .path .join (tmp_dir , f"{ dir_prefix } /" )
219222 shutil .copytree (
220- path ,
223+ context_path ,
221224 context_dir ,
222225 ignore = shutil .ignore_patterns (dir_prefix , ".git" ),
223226 symlinks = True ,
224227 )
225228
226229 for src , dest in inject .items ():
227- src_path = os .path .join (path , src )
230+ src_path = os .path .join (context_path , src )
228231
229232 # Remove '/' prefix
230233 if dest .startswith ("/" ):
@@ -265,6 +268,7 @@ def _build_with_inject(
265268 cache = cache ,
266269 pull = pull ,
267270 stream_logs = True ,
271+ secrets = secrets ,
268272 ** self ._get_build_cache_options (builder ),
269273 )
270274 self ._log_buildx (logs_itr , platform )
@@ -294,6 +298,7 @@ def _build_single_image(
294298 inject : dict ,
295299 cache : bool = False ,
296300 pull : bool = False ,
301+ secrets : Optional [List [str ]] = None ,
297302 ) -> None :
298303 """
299304 Builds a single image for the given platform.
@@ -307,6 +312,7 @@ def _build_single_image(
307312 target (str): The name of the stage to build in a multi-stage Dockerfile
308313 build_args (dict): The build args to pass to docker.
309314 inject (dict): The files to inject into the build context.
315+ secrets (List[str]): The secrets to pass to docker.
310316 """
311317 assert os .path .isdir (path ) and os .path .exists (dockerfile ), (
312318 f"Either path { path } ({ os .path .isdir (path )} ) or file "
@@ -321,32 +327,37 @@ def _build_single_image(
321327 f"Building image for platform { platform } with { builder or 'default' } builder"
322328 )
323329
330+ # 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
340+ if secrets :
341+ build_kwargs ["secrets" ] = secrets
342+
324343 if inject and isinstance (inject , dict ):
325344 self ._build_with_inject (
326345 inject = inject ,
327346 image_ref = image_ref ,
328347 platform = platform ,
329- path = path ,
330348 dockerfile = dockerfile ,
331- target = target ,
332349 build_args = build_args ,
333- builder = builder ,
334- cache = cache ,
335- pull = pull ,
350+ ** build_kwargs ,
336351 )
337352 else :
338353 logs_itr = docker .buildx .build (
339- path ,
340354 tags = [image_ref ],
341355 platforms = [platform ],
342356 load = True ,
343357 file = dockerfile ,
344- target = target ,
345358 build_args = build_args ,
346- builder = builder ,
347- cache = cache ,
348- pull = pull ,
349359 stream_logs = True ,
360+ ** build_kwargs ,
350361 ** self ._get_build_cache_options (builder ),
351362 )
352363 self ._log_buildx (logs_itr , platform )
@@ -398,11 +409,12 @@ def build_multiple_images(
398409 path : str = "." ,
399410 file : str = "Dockerfile" ,
400411 target : Optional [str ] = None ,
401- use_threading : bool = True ,
412+ use_threading : bool = False ,
402413 build_args : dict = None ,
403414 inject : dict = None ,
404415 cache : bool = False ,
405416 pull : bool = False ,
417+ secrets : Optional [List [str ]] = None ,
406418 ) -> BuiltImageInfo :
407419 """
408420 Builds multiple images for the given platforms. One image will be built for each platform.
@@ -498,6 +510,7 @@ def build_multiple_images(
498510 inject ,
499511 cache ,
500512 pull ,
513+ secrets ,
501514 )
502515 LOGGER .debug (f"Building { repo } for { platform } " )
503516 if use_threading :
0 commit comments