1515
1616python -m scripts.release.main \
1717 --include upgrade-hook \
18- --include cli \
19- --include test \
2018 --include operator \
19+ --include init-appdb \
20+ --include database \
2121 --include mco-test \
22+ --include test \
2223 --include readiness-probe \
2324 --include operator-quick \
24- --include database \
25- --include init-appdb \
25+ --include cli \
2626 --include init-database \
2727 --include init-ops-manager \
2828 --include ops-manager
8282# TODO: better framework for multi arch builds (spike to come)
8383
8484TRACER = trace .get_tracer ("evergreen-agent" )
85- DEFAULT_IMAGE_TYPE = "ubi"
8685DEFAULT_NAMESPACE = "default"
8786
88- # QUAY_REGISTRY_URL sets the base registry for all release build stages. Context images and daily builds will push the
89- # final images to the registry specified here.
90- # This makes it easy to use ECR to test changes on the pipeline before pushing to Quay.
91- QUAY_REGISTRY_URL = "268558157000.dkr.ecr.us-east-1.amazonaws.com/julienben/staging-temp"
92-
93-
9487def make_list_of_str (value : Union [None , str , List [str ]]) -> List [str ]:
9588 if value is None :
9689 return []
@@ -109,38 +102,6 @@ def get_tools_distro(tools_version: str) -> Dict[str, str]:
109102 return default_distro
110103
111104
112- def operator_build_configuration (
113- base_registry : str ,
114- parallel : bool ,
115- debug : bool ,
116- architecture : Optional [List [str ]] = None ,
117- sign : bool = False ,
118- all_agents : bool = False ,
119- parallel_factor : int = 0 ,
120- ) -> BuildConfiguration :
121- bc = BuildConfiguration (
122- base_registry = base_registry ,
123- image_type = os .environ .get ("distro" , DEFAULT_IMAGE_TYPE ),
124- parallel = parallel ,
125- all_agents = all_agents or bool (os .environ .get ("all_agents" , False )),
126- debug = debug ,
127- architecture = architecture ,
128- sign = sign ,
129- parallel_factor = parallel_factor ,
130- )
131-
132- logger .info (f"is_running_in_patch: { is_running_in_patch ()} " )
133- logger .info (f"is_running_in_evg_pipeline: { is_running_in_evg_pipeline ()} " )
134- if is_running_in_patch () or not is_running_in_evg_pipeline ():
135- logger .info (
136- f"Running build not in evg pipeline (is_running_in_evg_pipeline={ is_running_in_evg_pipeline ()} ) "
137- f"or in pipeline but not from master (is_running_in_patch={ is_running_in_patch ()} ). "
138- "Adding 'master' tag to skip to prevent publishing to the latest dev image."
139- )
140-
141- return bc
142-
143-
144105def is_running_in_evg_pipeline ():
145106 return os .getenv ("RUNNING_IN_EVG" , "" ) == "true"
146107
@@ -150,24 +111,10 @@ def is_running_in_patch():
150111 return is_patch is not None and is_patch .lower () == "true"
151112
152113
153- def get_release () -> Dict :
114+ def load_release_file () -> Dict :
154115 with open ("release.json" ) as release :
155116 return json .load (release )
156117
157-
158- def get_git_release_tag () -> tuple [str , bool ]:
159- """Returns the git tag of the current run on releases, on non-release returns the patch id."""
160- release_env_var = os .getenv ("triggered_by_git_tag" )
161-
162- # that means we are in a release and only return the git_tag; otherwise we want to return the patch_id
163- # appended to ensure the image created is unique and does not interfere
164- if release_env_var is not None :
165- return release_env_var , True
166-
167- patch_id = os .environ .get ("version_id" , "latest" )
168- return patch_id , False
169-
170-
171118def create_and_push_manifest (image : str , tag : str , architectures : list [str ]) -> None :
172119 """
173120 Generates docker manifests by running the following commands:
@@ -212,34 +159,6 @@ def create_and_push_manifest(image: str, tag: str, architectures: list[str]) ->
212159 raise Exception (cp .stderr )
213160
214161
215- def try_get_platform_data (client , image ):
216- """Helper function to try and retrieve platform data."""
217- try :
218- return client .images .get_registry_data (image )
219- except Exception as e :
220- logger .error ("Failed to get registry data for image: {0}. Error: {1}" .format (image , str (e )))
221- return None
222-
223-
224- def check_multi_arch (image : str , suffix : str ) -> bool :
225- """
226- Checks if a docker image supports AMD and ARM platforms by inspecting the registry data.
227-
228- :param str image: The image name and tag
229- """
230- client = docker .from_env ()
231- platforms = ["linux/amd64" , "linux/arm64" ]
232-
233- for img in [image , image + suffix ]:
234- reg_data = try_get_platform_data (client , img )
235- if reg_data is not None and all (reg_data .has_platform (p ) for p in platforms ):
236- logger .info ("Base image {} supports multi architecture, building for ARM64 and AMD64" .format (img ))
237- return True
238-
239- logger .info ("Base image {} is single-arch, building only for AMD64." .format (img ))
240- return False
241-
242-
243162@TRACER .start_as_current_span ("sonar_build_image" )
244163def pipeline_process_image (
245164 image_name : str ,
@@ -353,8 +272,6 @@ def build_tests_image(build_configuration: BuildConfiguration):
353272
354273 buildargs = dict ({"PYTHON_VERSION" : python_version })
355274
356- image_tag , _ = get_git_release_tag () # TODO: correct tag for test image ?
357- # TODO: don't allow test images to be released to Quay
358275 pipeline_process_image (
359276 image_name ,
360277 image_tag = image_tag ,
@@ -376,10 +293,9 @@ def build_mco_tests_image(build_configuration: BuildConfiguration):
376293
377294 buildargs = dict ({"GOLANG_VERSION" : golang_version })
378295
379- image_tag , _ = get_git_release_tag () # TODO: correct tag for test image ?
380296 pipeline_process_image (
381297 image_name ,
382- image_tag = image_tag ,
298+ image_tag = build_configuration . version ,
383299 dockerfile_path = "docker/mongodb-community-tests/Dockerfile" ,
384300 dockerfile_args = buildargs ,
385301 base_registry = build_configuration .base_registry ,
@@ -392,10 +308,9 @@ def build_operator_image(build_configuration: BuildConfiguration):
392308 # repository with a given suffix.
393309 test_suffix = os .environ .get ("test_suffix" , "" )
394310 log_automation_config_diff = os .environ .get ("LOG_AUTOMATION_CONFIG_DIFF" , "false" )
395- version , _ = get_git_release_tag ()
396311
397312 args = {
398- "version" : version ,
313+ "version" : build_configuration . version ,
399314 "log_automation_config_diff" : log_automation_config_diff ,
400315 "test_suffix" : test_suffix ,
401316 "debug" : build_configuration .debug ,
@@ -422,10 +337,9 @@ def build_database_image(build_configuration: BuildConfiguration):
422337 """
423338 Builds a new database image.
424339 """
425- release = get_release ()
340+ release = load_release_file ()
426341 version = release ["databaseImageVersion" ]
427- version , _ = get_git_release_tag () # TODO: check how to properly retrieve version
428- args = {"version" : version }
342+ args = {"version" : build_configuration .version }
429343 build_image_generic (
430344 image_name = "mongodb-kubernetes-database" ,
431345 dockerfile_path = "docker/mongodb-kubernetes-database/Dockerfile" ,
@@ -450,7 +364,7 @@ def build_CLI_SBOM(build_configuration: BuildConfiguration):
450364 logger .error (f"Unrecognized architectures { build_configuration .architecture } . Skipping SBOM generation" )
451365 return
452366
453- release = get_release ()
367+ release = load_release_file ()
454368 version = release ["mongodbOperator" ]
455369
456370 for architecture in architectures :
@@ -521,13 +435,12 @@ def find_om_url(om_version: str) -> str:
521435
522436
523437def build_init_om_image (build_configuration : BuildConfiguration ):
524- release = get_release ()
438+ release = load_release_file ()
525439 version = release ["initOpsManagerVersion" ]
526- version , _ = get_git_release_tag () # TODO: check how to properly retrieve version
527- args = {"version" : version }
440+ args = {"version" : build_configuration .version }
528441 build_image_generic (
529- "mongodb-kubernetes-init-ops-manager" ,
530- "docker/mongodb-kubernetes-init-ops-manager/Dockerfile" ,
442+ image_name = "mongodb-kubernetes-init-ops-manager" ,
443+ dockerfile_path = "docker/mongodb-kubernetes-init-ops-manager/Dockerfile" ,
531444 registry_address = build_configuration .base_registry ,
532445 extra_args = args ,
533446 sign = build_configuration .sign ,
@@ -610,15 +523,15 @@ def build_image_generic(
610523
611524
612525def build_init_appdb (build_configuration : BuildConfiguration ):
613- release = get_release ()
526+ release = load_release_file ()
614527 version = release ["initAppDbVersion" ]
615528 base_url = "https://fastdl.mongodb.org/tools/db/"
616529 mongodb_tools_url_ubi = "{}{}" .format (base_url , release ["mongodbToolsBundle" ]["ubi" ])
617530 version , _ = get_git_release_tag () # TODO: check how to properly retrieve version
618531 args = {"version" : version , "is_appdb" : True , "mongodb_tools_url_ubi" : mongodb_tools_url_ubi }
619532 build_image_generic (
620- "mongodb-kubernetes-init-appdb" ,
621- "docker/mongodb-kubernetes-init-appdb/Dockerfile" ,
533+ image_name = "mongodb-kubernetes-init-appdb" ,
534+ dockerfile_path = "docker/mongodb-kubernetes-init-appdb/Dockerfile" ,
622535 registry_address = build_configuration .base_registry ,
623536 extra_args = args ,
624537 sign = build_configuration .sign ,
@@ -668,8 +581,8 @@ def build_community_image(build_configuration: BuildConfiguration, image_type: s
668581 image_name = image_name ,
669582 dockerfile_path = dockerfile_path ,
670583 registry_address = build_configuration .base_registry ,
671- is_multi_arch = True ,
672584 multi_arch_args_list = multi_arch_args_list ,
585+ is_multi_arch = True ,
673586 sign = build_configuration .sign ,
674587 )
675588
@@ -696,21 +609,27 @@ def build_agent_pipeline(
696609 mongodb_agent_url_ubi : str ,
697610 agent_version ,
698611):
612+ version = f"{ agent_version } _{ image_version } "
613+
614+ quay_agent_registry = (
615+ f"{ build_configuration .base_registry } /mongodb-agent-ubi"
616+ )
617+
699618 args = {
700- "version" : image_version ,
619+ "version" : version ,
620+ "agent_version" : agent_version ,
621+ "ubi_suffix" : "-ubi" ,
622+ "release_version" : image_version ,
623+ "init_database_image" : init_database_image ,
701624 "mongodb_tools_url_ubi" : mongodb_tools_url_ubi ,
702625 "mongodb_agent_url_ubi" : mongodb_agent_url_ubi ,
703- "init_database_image " : init_database_image ,
626+ "quay_registry " : quay_agent_registry ,
704627 }
705628
706- agent_quay_registry = build_configuration .base_registry + f"/mongodb-agent-ubi"
707- args ["quay_registry" ] = build_configuration .base_registry
708- args ["agent_version" ] = agent_version
709-
710629 build_image_generic (
711630 image_name = "mongodb-agent-ubi" ,
712631 dockerfile_path = "docker/mongodb-agent/Dockerfile" ,
713- registry_address = build_configuration . base_registry ,
632+ registry_address = quay_agent_registry ,
714633 extra_args = args ,
715634 sign = build_configuration .sign ,
716635 )
@@ -775,7 +694,7 @@ def build_agent_default_case(build_configuration: BuildConfiguration):
775694
776695 See more information in the function: build_agent_on_agent_bump
777696 """
778- release = get_release ()
697+ release = load_release_file ()
779698
780699 operator_version , is_release = get_git_release_tag ()
781700
@@ -824,13 +743,13 @@ def build_agent_on_agent_bump(build_configuration: BuildConfiguration):
824743 - operator releases
825744 - OM/CM bumps via PCT
826745
827- We don' t require building a full matrix on e2e test runs and operator releases.
746+ We don’ t require building a full matrix on e2e test runs and operator releases.
828747 "Operator releases" and "e2e test runs" require only the latest operator x agents
829748
830749 In OM/CM bumps, we release a new agent which we potentially require to release to older operators as well.
831750 This function takes care of that.
832751 """
833- release = get_release ()
752+ release = load_release_file ()
834753 is_release = build_configuration .is_release_step_executed ()
835754
836755 if build_configuration .all_agents :
@@ -955,7 +874,7 @@ def gather_latest_agent_versions(release: Dict) -> List[Tuple[str, str]]:
955874 """
956875 This function is used when we release a new agent via OM bump.
957876 That means we will need to release that agent with all supported operators.
958- Since we don' t want to release all agents again, we only release the latest, which will contain the newly added one
877+ Since we don’ t want to release all agents again, we only release the latest, which will contain the newly added one
959878 :return: the latest agent for each major version
960879 """
961880 agent_versions_to_build = list ()
@@ -1026,11 +945,11 @@ def get_builder_function_for_image_name() -> Dict[str, Callable]:
1026945
1027946# TODO: nam static: remove this once static containers becomes the default
1028947def build_init_database (build_configuration : BuildConfiguration ):
1029- release = get_release ()
948+ release = load_release_file ()
1030949 version = release ["initDatabaseVersion" ] # comes from release.json
1031950 base_url = "https://fastdl.mongodb.org/tools/db/"
1032951 mongodb_tools_url_ubi = "{}{}" .format (base_url , release ["mongodbToolsBundle" ]["ubi" ])
1033- version , _ = get_git_release_tag () # TODO: check how to properly retrieve version
952+ version = build_configuration . version # TODO: check how to properly retrieve version
1034953 args = {"version" : version , "mongodb_tools_url_ubi" : mongodb_tools_url_ubi , "is_appdb" : False }
1035954 build_image_generic (
1036955 "mongodb-kubernetes-init-database" ,
@@ -1039,30 +958,3 @@ def build_init_database(build_configuration: BuildConfiguration):
1039958 extra_args = args ,
1040959 sign = build_configuration .sign ,
1041960 )
1042-
1043-
1044- def build_image (image_name : str , build_configuration : BuildConfiguration ):
1045- """Builds one of the supported images by its name."""
1046- get_builder_function_for_image_name ()[image_name ](build_configuration )
1047-
1048-
1049- def build_all_images (
1050- images : Iterable [str ],
1051- base_registry : str ,
1052- debug : bool = False ,
1053- parallel : bool = False ,
1054- architecture : Optional [List [str ]] = None ,
1055- sign : bool = False ,
1056- all_agents : bool = False ,
1057- parallel_factor : int = 0 ,
1058- ):
1059- """Builds all the images in the `images` list."""
1060- build_configuration = operator_build_configuration (
1061- base_registry , parallel , debug , architecture , sign , all_agents , parallel_factor
1062- )
1063- if sign :
1064- mongodb_artifactory_login ()
1065- for idx , image in enumerate (images ):
1066- logger .info (f"====Building image { image } ({ idx } /{ len (images )- 1 } )====" )
1067- time .sleep (1 )
1068- build_image (image , build_configuration )
0 commit comments