14
14
from opentelemetry import trace
15
15
16
16
from lib .base_logger import logger
17
+ from scripts .release .agent .validation import validate_agent_version_exists , validate_tools_version_exists ,load_agent_build_info
17
18
from scripts .release .build .image_build_configuration import ImageBuildConfiguration
18
19
from scripts .release .build .image_build_process import execute_docker_build
19
20
from scripts .release .build .image_signing import (
20
21
mongodb_artifactory_login ,
21
22
sign_image ,
22
23
verify_signature ,
23
24
)
24
- from scripts .release .detect_ops_manager_changes import (
25
+ from scripts .release .agent . detect_ops_manager_changes import (
25
26
detect_ops_manager_changes ,
26
27
get_currently_used_agents ,
27
28
get_all_agents_for_rebuild ,
30
31
TRACER = trace .get_tracer ("evergreen-agent" )
31
32
32
33
33
- def load_agent_build_info ():
34
- """Load agent platform mappings from build_info_agent.json"""
35
- with open ("build_info_agent.json" , "r" ) as f :
36
- return json .load (f )
37
-
38
-
39
34
def extract_tools_version_from_release (release : Dict ) -> str :
40
35
"""
41
36
Extract tools version from release.json mongodbToolsBundle.ubi field.
42
37
43
- Args:
44
- release: Release dictionary from release.json
45
-
46
38
Returns:
47
39
Tools version string (e.g., "100.12.2")
48
40
"""
@@ -54,22 +46,6 @@ def extract_tools_version_from_release(release: Dict) -> str:
54
46
return tools_version
55
47
56
48
57
- def get_build_arg_names (platform : str ) -> Dict [str , str ]:
58
- """
59
- Generate build argument names for a platform.
60
-
61
- Args:
62
- platform: Platform string (e.g., "linux/amd64")
63
-
64
- Returns:
65
- Dictionary with agent_build_arg and tools_build_arg keys
66
- """
67
- # Extract architecture from platform (e.g., "amd64" from "linux/amd64")
68
- arch = platform .split ("/" )[1 ]
69
-
70
- return {"agent_build_arg" : f"mongodb_agent_version_{ arch } " , "tools_build_arg" : f"mongodb_tools_version_{ arch } " }
71
-
72
-
73
49
def generate_tools_build_args (platforms : List [str ], tools_version : str ) -> Dict [str , str ]:
74
50
"""
75
51
Generate build arguments for MongoDB tools based on platform mappings.
@@ -90,12 +66,11 @@ def generate_tools_build_args(platforms: List[str], tools_version: str) -> Dict[
90
66
continue
91
67
92
68
mapping = agent_info ["platform_mappings" ][platform ]
93
- build_arg_names = get_build_arg_names ( platform )
69
+ arch = platform . split ( "/" )[ - 1 ]
94
70
95
- # Generate tools build arg only
96
71
tools_suffix = mapping ["tools_suffix" ].replace ("{TOOLS_VERSION}" , tools_version )
97
72
tools_filename = f"{ agent_info ['base_names' ]['tools' ]} -{ tools_suffix } "
98
- build_args [build_arg_names [ "tools_build_arg" ] ] = tools_filename
73
+ build_args [f"mongodb_tool_version_ { arch } " ] = tools_filename
99
74
100
75
return build_args
101
76
@@ -121,14 +96,14 @@ def generate_agent_build_args(platforms: List[str], agent_version: str, tools_ve
121
96
continue
122
97
123
98
mapping = agent_info ["platform_mappings" ][platform ]
124
- build_arg_names = get_build_arg_names ( platform )
99
+ arch = platform . split ( "/" )[ - 1 ]
125
100
126
101
agent_filename = f"{ agent_info ['base_names' ]['agent' ]} -{ agent_version } .{ mapping ['agent_suffix' ]} "
127
- build_args [build_arg_names [ "agent_build_arg" ] ] = agent_filename
102
+ build_args [f"mongodb_agent_version_ { arch } " ] = agent_filename
128
103
129
104
tools_suffix = mapping ["tools_suffix" ].replace ("{TOOLS_VERSION}" , tools_version )
130
105
tools_filename = f"{ agent_info ['base_names' ]['tools' ]} -{ tools_suffix } "
131
- build_args [build_arg_names [ "tools_build_arg" ] ] = tools_filename
106
+ build_args [f"mongodb_tool_version_ { arch } " ] = tools_filename
132
107
133
108
return build_args
134
109
@@ -339,6 +314,12 @@ def build_init_appdb_image(build_configuration: ImageBuildConfiguration):
339
314
340
315
# Extract tools version and generate platform-specific build args
341
316
tools_version = extract_tools_version_from_release (release )
317
+
318
+ # Validate that the tools version exists before attempting to build
319
+ if not validate_tools_version_exists (tools_version , build_configuration .platforms ):
320
+ logger .warning (f"Skipping build for init-appdb - tools version { tools_version } not found in repository" )
321
+ return
322
+
342
323
platform_build_args = generate_tools_build_args (
343
324
platforms = build_configuration .platforms , tools_version = tools_version
344
325
)
@@ -359,10 +340,15 @@ def build_init_appdb_image(build_configuration: ImageBuildConfiguration):
359
340
def build_init_database_image (build_configuration : ImageBuildConfiguration ):
360
341
release = load_release_file ()
361
342
base_url = "https://fastdl.mongodb.org/tools/db"
362
- mongodb_tools_url_ubi = "{}{}" .format (base_url , release ["mongodbToolsBundle" ]["ubi" ])
363
343
364
344
# Extract tools version and generate platform-specific build args
365
345
tools_version = extract_tools_version_from_release (release )
346
+
347
+ # Validate that the tools version exists before attempting to build
348
+ if not validate_tools_version_exists (tools_version , build_configuration .platforms ):
349
+ logger .warning (f"Skipping build for init-database - tools version { tools_version } not found in repository" )
350
+ return
351
+
366
352
platform_build_args = generate_tools_build_args (
367
353
platforms = build_configuration .platforms , tools_version = tools_version
368
354
)
@@ -429,15 +415,37 @@ def build_agent(build_configuration: ImageBuildConfiguration):
429
415
with ProcessPoolExecutor (max_workers = max_workers ) as executor :
430
416
logger .info (f"Running with factor of { max_workers } " )
431
417
logger .info (f"======= Agent versions to build { agent_versions_to_build } =======" )
418
+
419
+ successful_builds = []
420
+ skipped_builds = []
421
+
432
422
for idx , agent_tools_version in enumerate (agent_versions_to_build ):
433
- logger .info (f"======= Building Agent { agent_tools_version } ({ idx } /{ len (agent_versions_to_build )} )" )
423
+ agent_version = agent_tools_version [0 ]
424
+ tools_version = agent_tools_version [1 ]
425
+ logger .info (f"======= Building Agent { agent_tools_version } ({ idx + 1 } /{ len (agent_versions_to_build )} )" )
426
+
427
+ if not validate_agent_version_exists (agent_version , build_configuration .platforms ):
428
+ logger .warning (f"Skipping agent version { agent_version } - not found in repository" )
429
+ skipped_builds .append (agent_tools_version )
430
+ continue
431
+
432
+ if not validate_tools_version_exists (tools_version , build_configuration .platforms ):
433
+ logger .warning (f"Skipping agent version { agent_version } - tools version { tools_version } not found in repository" )
434
+ skipped_builds .append (agent_tools_version )
435
+ continue
436
+
437
+ successful_builds .append (agent_tools_version )
434
438
_build_agent (
435
439
agent_tools_version ,
436
440
build_configuration ,
437
441
executor ,
438
442
tasks_queue ,
439
443
)
440
444
445
+ logger .info (f"Build summary: { len (successful_builds )} successful, { len (skipped_builds )} skipped" )
446
+ if skipped_builds :
447
+ logger .info (f"Skipped versions: { skipped_builds } " )
448
+
441
449
queue_exception_handling (tasks_queue )
442
450
443
451
@@ -464,6 +472,7 @@ def build_agent_pipeline(
464
472
f"======== Building agent pipeline for version { agent_version } , build configuration version: { build_configuration .version } "
465
473
)
466
474
475
+ # Note: Validation is now done earlier in the build_agent function
467
476
# Generate platform-specific build arguments using the mapping
468
477
platform_build_args = generate_agent_build_args (
469
478
platforms = build_configuration .platforms , agent_version = agent_version , tools_version = tools_version
0 commit comments