16
16
from packaging .version import Version
17
17
18
18
from lib .base_logger import logger
19
- from scripts .evergreen .release .images_signing import (
19
+ from scripts .release .build .image_build_configuration import ImageBuildConfiguration
20
+ from scripts .release .build .image_build_process import execute_docker_build
21
+ from scripts .release .build .image_signing import (
20
22
sign_image ,
21
23
verify_signature ,
22
24
)
23
- from scripts .release .build .image_build_configuration import ImageBuildConfiguration
24
- from scripts .release .build .image_build_process import build_image
25
-
26
- from .optimized_operator_build import build_operator_image_fast
27
25
28
26
TRACER = trace .get_tracer ("evergreen-agent" )
29
27
30
28
31
- def get_tools_distro (tools_version : str ) -> Dict [str , str ]:
32
- new_rhel_tool_version = "100.10.0"
33
- default_distro = {"arm" : "rhel90-aarch64" , "amd" : "rhel90-x86_64" }
34
- if Version (tools_version ) >= Version (new_rhel_tool_version ):
35
- return {"arm" : "rhel93-aarch64" , "amd" : "rhel93-x86_64" }
36
- return default_distro
37
-
38
-
39
- def load_release_file () -> Dict :
40
- with open ("release.json" ) as release :
41
- return json .load (release )
42
-
43
-
44
- @TRACER .start_as_current_span ("sonar_build_image" )
45
- def pipeline_process_image (
29
+ @TRACER .start_as_current_span ("build_image_generic" )
30
+ def build_image (
46
31
dockerfile_path : str ,
47
32
build_configuration : ImageBuildConfiguration ,
48
- dockerfile_args : Dict [str , str ] = None ,
33
+ build_args : Dict [str , str ] = None ,
49
34
build_path : str = "." ,
50
35
):
51
- """Builds a Docker image with arguments defined in `args`."""
36
+ """
37
+ Build an image then (optionally) sign the result.
38
+ """
52
39
image_name = build_configuration .image_name ()
53
40
span = trace .get_current_span ()
54
41
span .set_attribute ("mck.image_name" , image_name )
55
- if dockerfile_args :
56
- span .set_attribute ("mck.build_args" , str (dockerfile_args ))
57
42
58
- if not dockerfile_args :
59
- dockerfile_args = {}
60
- logger .info (f"Dockerfile args: { dockerfile_args } , for image: { image_name } " )
43
+ registry = build_configuration .base_registry
44
+ build_args = build_args or {}
61
45
62
- build_image (
63
- image_tag = build_configuration .version ,
64
- dockerfile_path = dockerfile_path ,
65
- dockerfile_args = dockerfile_args ,
66
- registry = build_configuration .registry ,
46
+ if build_args :
47
+ span .set_attribute ("mck.build_args" , str (build_args ))
48
+
49
+ logger .info (f"Building { image_name } , dockerfile args: { build_args } " )
50
+ logger .debug (f"Build args: { build_args } " )
51
+ logger .debug (f"Building { image_name } for platforms={ build_configuration .platforms } " )
52
+ logger .debug (f"build image generic - registry={ registry } " )
53
+
54
+ # Build docker registry URI and call build_image
55
+ image_full_uri = f"{ build_configuration .registry } :{ build_configuration .version } "
56
+
57
+ execute_docker_build (
58
+ tag = image_full_uri ,
59
+ dockerfile = dockerfile_path ,
60
+ path = build_path ,
61
+ args = build_args ,
62
+ push = True ,
67
63
platforms = build_configuration .platforms ,
68
- build_path = build_path ,
69
64
)
70
65
71
66
if build_configuration .sign :
72
- pipeline_sign_image (
73
- registry = build_configuration .registry ,
74
- version = build_configuration .version ,
75
- )
76
-
77
-
78
- @TRACER .start_as_current_span ("sign_image_in_repositories" )
79
- def pipeline_sign_image (registry : str , version : str ):
80
- logger .info ("Signing image" )
81
- sign_image (registry , version )
82
- verify_signature (registry , version )
67
+ logger .info ("Signing image" )
68
+ sign_image (build_configuration .registry , build_configuration .version )
69
+ verify_signature (build_configuration .registry , build_configuration .version )
83
70
84
71
85
72
def build_tests_image (build_configuration : ImageBuildConfiguration ):
@@ -110,10 +97,10 @@ def build_tests_image(build_configuration: ImageBuildConfiguration):
110
97
111
98
build_args = dict ({"PYTHON_VERSION" : python_version })
112
99
113
- pipeline_process_image (
100
+ build_image (
114
101
dockerfile_path = "docker/mongodb-kubernetes-tests/Dockerfile" ,
115
102
build_configuration = build_configuration ,
116
- dockerfile_args = build_args ,
103
+ build_args = build_args ,
117
104
build_path = "docker/mongodb-kubernetes-tests" ,
118
105
)
119
106
@@ -123,7 +110,7 @@ def build_mco_tests_image(build_configuration: ImageBuildConfiguration):
123
110
Builds image used to run community tests.
124
111
"""
125
112
126
- pipeline_process_image (
113
+ build_image (
127
114
dockerfile_path = "docker/mongodb-community-tests/Dockerfile" ,
128
115
build_configuration = build_configuration ,
129
116
)
@@ -144,11 +131,10 @@ def build_operator_image(build_configuration: ImageBuildConfiguration):
144
131
145
132
logger .info (f"Building Operator args: { args } " )
146
133
147
- image_name = "mongodb-kubernetes"
148
- pipeline_process_image (
134
+ build_image (
149
135
dockerfile_path = "docker/mongodb-kubernetes-operator/Dockerfile" ,
150
136
build_configuration = build_configuration ,
151
- dockerfile_args = args ,
137
+ build_args = args ,
152
138
)
153
139
154
140
@@ -158,10 +144,10 @@ def build_database_image(build_configuration: ImageBuildConfiguration):
158
144
"""
159
145
args = {"version" : build_configuration .version }
160
146
161
- pipeline_process_image (
147
+ build_image (
162
148
dockerfile_path = "docker/mongodb-kubernetes-database/Dockerfile" ,
163
149
build_configuration = build_configuration ,
164
- dockerfile_args = args ,
150
+ build_args = args ,
165
151
)
166
152
167
153
@@ -182,7 +168,7 @@ def find_om_in_releases(om_version: str, releases: Dict[str, str]) -> Optional[s
182
168
183
169
184
170
def get_om_releases () -> Dict [str , str ]:
185
- """Returns a dictionary representation of the Json document holdin all the OM
171
+ """Returns a dictionary representation of the Json document holding all the OM
186
172
releases.
187
173
"""
188
174
ops_manager_release_archive = (
@@ -208,10 +194,11 @@ def find_om_url(om_version: str) -> str:
208
194
209
195
def build_init_om_image (build_configuration : ImageBuildConfiguration ):
210
196
args = {"version" : build_configuration .version }
211
- pipeline_process_image (
197
+
198
+ build_image (
212
199
dockerfile_path = "docker/mongodb-kubernetes-init-ops-manager/Dockerfile" ,
213
200
build_configuration = build_configuration ,
214
- dockerfile_args = args ,
201
+ build_args = args ,
215
202
)
216
203
217
204
@@ -234,10 +221,10 @@ def build_om_image(build_configuration: ImageBuildConfiguration):
234
221
"om_download_url" : om_download_url ,
235
222
}
236
223
237
- pipeline_process_image (
224
+ build_image (
238
225
dockerfile_path = "docker/mongodb-enterprise-ops-manager/Dockerfile" ,
239
226
build_configuration = build_configuration ,
240
- dockerfile_args = args ,
227
+ build_args = args ,
241
228
)
242
229
243
230
@@ -247,10 +234,10 @@ def build_init_appdb_image(build_configuration: ImageBuildConfiguration):
247
234
mongodb_tools_url_ubi = "{}{}" .format (base_url , release ["mongodbToolsBundle" ]["ubi" ])
248
235
args = {"version" : build_configuration .version , "mongodb_tools_url_ubi" : mongodb_tools_url_ubi }
249
236
250
- pipeline_process_image (
237
+ build_image (
251
238
dockerfile_path = "docker/mongodb-kubernetes-init-appdb/Dockerfile" ,
252
239
build_configuration = build_configuration ,
253
- dockerfile_args = args ,
240
+ build_args = args ,
254
241
)
255
242
256
243
@@ -260,10 +247,11 @@ def build_init_database_image(build_configuration: ImageBuildConfiguration):
260
247
base_url = "https://fastdl.mongodb.org/tools/db/"
261
248
mongodb_tools_url_ubi = "{}{}" .format (base_url , release ["mongodbToolsBundle" ]["ubi" ])
262
249
args = {"version" : build_configuration .version , "mongodb_tools_url_ubi" : mongodb_tools_url_ubi }
263
- pipeline_process_image (
250
+
251
+ build_image (
264
252
"docker/mongodb-kubernetes-init-database/Dockerfile" ,
265
253
build_configuration = build_configuration ,
266
- dockerfile_args = args ,
254
+ build_args = args ,
267
255
)
268
256
269
257
@@ -272,7 +260,7 @@ def build_readiness_probe_image(build_configuration: ImageBuildConfiguration):
272
260
Builds image used for readiness probe.
273
261
"""
274
262
275
- pipeline_process_image (
263
+ build_image (
276
264
dockerfile_path = "docker/mongodb-kubernetes-readinessprobe/Dockerfile" ,
277
265
build_configuration = build_configuration ,
278
266
)
@@ -283,7 +271,7 @@ def build_upgrade_hook_image(build_configuration: ImageBuildConfiguration):
283
271
Builds image used for version upgrade post-start hook.
284
272
"""
285
273
286
- pipeline_process_image (
274
+ build_image (
287
275
dockerfile_path = "docker/mongodb-kubernetes-upgrade-hook/Dockerfile" ,
288
276
build_configuration = build_configuration ,
289
277
)
@@ -293,7 +281,6 @@ def build_agent_default_case(build_configuration: ImageBuildConfiguration):
293
281
"""
294
282
Build the agent only for the latest operator for patches and operator releases.
295
283
296
- See more information in the function: build_agent_on_agent_bump
297
284
"""
298
285
release = load_release_file ()
299
286
@@ -316,12 +303,12 @@ def build_agent_default_case(build_configuration: ImageBuildConfiguration):
316
303
if build_configuration .parallel_factor > 0 :
317
304
max_workers = build_configuration .parallel_factor
318
305
with ProcessPoolExecutor (max_workers = max_workers ) as executor :
319
- logger .info (f"running with factor of { max_workers } " )
320
- print (f"======= Versions to build { agent_versions_to_build } =======" )
306
+ logger .info (f"Running with factor of { max_workers } " )
307
+ logger . info (f"======= Agent versions to build { agent_versions_to_build } =======" )
321
308
for idx , agent_version in enumerate (agent_versions_to_build ):
322
309
# We don't need to keep create and push the same image on every build.
323
310
# It is enough to create and push the non-operator suffixed images only during releases to ecr and quay.
324
- print (f"======= Building Agent { agent_version } ({ idx } /{ len (agent_versions_to_build )} )" )
311
+ logger . info (f"======= Building Agent { agent_version } ({ idx } /{ len (agent_versions_to_build )} )" )
325
312
_build_agent_operator (
326
313
agent_version ,
327
314
build_configuration ,
@@ -446,10 +433,10 @@ def build_agent_pipeline(
446
433
"mongodb_agent_url_ubi" : mongodb_agent_url_ubi ,
447
434
}
448
435
449
- pipeline_process_image (
436
+ build_image (
450
437
dockerfile_path = "docker/mongodb-agent/Dockerfile" ,
451
438
build_configuration = build_configuration_copy ,
452
- dockerfile_args = args ,
439
+ build_args = args ,
453
440
)
454
441
455
442
@@ -463,3 +450,16 @@ def queue_exception_handling(tasks_queue):
463
450
raise Exception (
464
451
f"Exception(s) found when processing Agent images. \n See also previous logs for more info\n Failing the build"
465
452
)
453
+
454
+
455
+ def get_tools_distro (tools_version : str ) -> Dict [str , str ]:
456
+ new_rhel_tool_version = "100.10.0"
457
+ default_distro = {"arm" : "rhel90-aarch64" , "amd" : "rhel90-x86_64" }
458
+ if Version (tools_version ) >= Version (new_rhel_tool_version ):
459
+ return {"arm" : "rhel93-aarch64" , "amd" : "rhel93-x86_64" }
460
+ return default_distro
461
+
462
+
463
+ def load_release_file () -> Dict :
464
+ with open ("release.json" ) as release :
465
+ return json .load (release )
0 commit comments