|
8 | 8 | import logging |
9 | 9 | import os |
10 | 10 | import platform as python_platform |
| 11 | +import random |
11 | 12 | import re |
12 | 13 | import shutil |
13 | 14 | import tempfile |
@@ -76,7 +77,7 @@ def __init__( |
76 | 77 | docker_registry: Optional[str] = None, |
77 | 78 | build_registry: Optional[str] = MP_LOCAL_REGISTRY, |
78 | 79 | temp_dir: str = os.getcwd(), |
79 | | - platform_builders: Optional[Dict[str, str]] = None, |
| 80 | + platform_builders: Optional[Union[Dict[str, List[str]], Dict[str, str]]] = None, |
80 | 81 | cache_builders: Optional[List[str]] = None, |
81 | 82 | cache_from: Optional[Union[dict, str]] = None, |
82 | 83 | cache_to: Optional[Union[dict, str]] = None, |
@@ -311,9 +312,23 @@ def _build_single_image( |
311 | 312 | f"'{dockerfile}' ({os.path.exists(dockerfile)}) does not exist!" |
312 | 313 | ) |
313 | 314 |
|
314 | | - builder = ( |
| 315 | + # Get the builder for the platform |
| 316 | + builders = ( |
315 | 317 | self._platform_builders.get(platform) if self._platform_builders else None |
316 | 318 | ) |
| 319 | + builder = None |
| 320 | + |
| 321 | + if builders: |
| 322 | + if isinstance(builders, str): |
| 323 | + builder = builders |
| 324 | + elif isinstance(builders, list): |
| 325 | + # Randomly select a builder from the list |
| 326 | + builder = random.choice(builders) |
| 327 | + else: |
| 328 | + raise BuildRunnerConfigurationError( |
| 329 | + f"Invalid platform builders configuration for platform {platform}" |
| 330 | + ) |
| 331 | + |
317 | 332 | LOGGER.debug(f"Building image {image_ref} for platform {platform}") |
318 | 333 | LOGGER.info( |
319 | 334 | f"Building image for platform {platform} with {builder or 'default'} builder" |
|
0 commit comments