|
1 | 1 | import argparse |
2 | 2 | import json |
3 | | -import pathlib |
| 3 | +import os |
4 | 4 |
|
5 | 5 | from scripts.release.build.build_info import ( |
6 | 6 | DATABASE_IMAGE, |
|
10 | 10 | OPERATOR_IMAGE, |
11 | 11 | READINESS_PROBE_IMAGE, |
12 | 12 | UPGRADE_HOOK_IMAGE, |
| 13 | + OPS_MANAGER_IMAGE, |
| 14 | + AGENT_IMAGE, |
13 | 15 | BuildInfo, |
14 | 16 | load_build_info, |
15 | 17 | ) |
| 18 | +from scripts.release.kubectl_mongodb.promote_kubectl_plugin import upload_assets_to_github_release |
16 | 19 | from scripts.release.build.build_scenario import BuildScenario |
17 | 20 | from scripts.release.constants import ( |
18 | 21 | DEFAULT_CHANGELOG_PATH, |
19 | 22 | DEFAULT_RELEASE_INITIAL_VERSION, |
20 | 23 | DEFAULT_REPOSITORY_PATH, |
21 | 24 | ) |
22 | 25 |
|
| 26 | +SEARCH_IMAGE = "search" |
| 27 | +SEARCH_IMAGE_REPOSITORY = "quay.io/mongodb/mongodb-search" |
| 28 | + |
23 | 29 | RELEASE_INFO_IMAGES_ORDERED = [ |
24 | | - OPERATOR_IMAGE, |
25 | | - INIT_DATABASE_IMAGE, |
26 | | - INIT_APPDB_IMAGE, |
27 | | - INIT_OPS_MANAGER_IMAGE, |
28 | | - DATABASE_IMAGE, |
29 | | - READINESS_PROBE_IMAGE, |
30 | | - UPGRADE_HOOK_IMAGE, |
| 30 | + OPERATOR_IMAGE, # mongodb-kubernetes |
| 31 | + INIT_DATABASE_IMAGE, # mongodb-kubernetes-init-database |
| 32 | + INIT_APPDB_IMAGE, # mongodb-kubernetes-init-appdb |
| 33 | + INIT_OPS_MANAGER_IMAGE, # mongodb-kubernetes-init-ops-manager |
| 34 | + DATABASE_IMAGE, # mongodb-kubernetes-database |
| 35 | + READINESS_PROBE_IMAGE, # mongodb-kubernetes-readinessprobe |
| 36 | + UPGRADE_HOOK_IMAGE, # mongodb-kubernetes-operator-version-upgrade-post-start-hook |
31 | 37 | ] |
32 | 38 |
|
33 | | -# TODO: this is dummy version, to be replaced with actual versioning logic https://docs.google.com/document/d/1eJ8iKsI0libbpcJakGjxcPfbrTn8lmcZDbQH1UqMR_g/edit?tab=t.45ig7xr3e3w4#bookmark=id.748ik8snxcyl |
34 | | -DUMMY_VERSION = "dummy_version" |
35 | | - |
| 39 | +EXTERNAL_INFO_IMAGES = [ |
| 40 | + OPS_MANAGER_IMAGE, |
| 41 | + AGENT_IMAGE |
| 42 | +] |
36 | 43 |
|
37 | | -def create_release_info_json() -> str: |
| 44 | +def create_release_info_json(version: str) -> str: |
38 | 45 | build_info = load_build_info(scenario=BuildScenario.RELEASE) |
39 | 46 |
|
40 | | - release_info_json = convert_to_release_info_json(build_info) |
| 47 | + release_info_json = convert_to_release_info_json(build_info, version) |
41 | 48 |
|
42 | 49 | return json.dumps(release_info_json, indent=2) |
43 | 50 |
|
44 | 51 |
|
45 | | -def convert_to_release_info_json(build_info: BuildInfo) -> dict: |
46 | | - output = { |
| 52 | +def convert_to_release_info_json(build_info: BuildInfo, version: str) -> dict: |
| 53 | + release_json_data = os.path.join(os.getcwd(), "release.json") |
| 54 | + with open(release_json_data, "r") as fd: |
| 55 | + release_data = json.load(fd) |
| 56 | + |
| 57 | + release_info_output = { |
47 | 58 | "images": {}, |
48 | | - "binaries": {}, |
49 | | - "helm-charts": {}, |
50 | 59 | } |
51 | 60 | # Filter (and order) images to include only those relevant for release info |
52 | | - images = {name: build_info.images[name] for name in RELEASE_INFO_IMAGES_ORDERED} |
| 61 | + images = {name: build_info.images[name] for name in RELEASE_INFO_IMAGES_ORDERED + EXTERNAL_INFO_IMAGES} |
53 | 62 |
|
54 | 63 | for name, image in images.items(): |
55 | | - output["images"][name] = { |
| 64 | + release_info_output["images"][name] = { |
56 | 65 | "repositories": image.repositories, |
57 | 66 | "platforms": image.platforms, |
58 | | - "version": DUMMY_VERSION, |
59 | 67 | } |
| 68 | + |
| 69 | + if name == OPS_MANAGER_IMAGE: |
| 70 | + release_info_output["images"][name]["version"] = latest_om_version(release_data) |
| 71 | + continue |
60 | 72 |
|
61 | | - for name, binary in build_info.binaries.items(): |
62 | | - output["binaries"][name] = { |
63 | | - "platforms": binary.platforms, |
64 | | - "version": DUMMY_VERSION, |
65 | | - } |
| 73 | + if name == AGENT_IMAGE: |
| 74 | + release_info_output["images"][name]["version"] = latest_agent_version(release_data) |
| 75 | + continue |
66 | 76 |
|
67 | | - for name, chart in build_info.helm_charts.items(): |
68 | | - output["helm-charts"][name] = { |
69 | | - "registry": chart.registry, |
70 | | - "repository": chart.repository, |
71 | | - "version": DUMMY_VERSION, |
72 | | - } |
| 77 | + release_info_output["images"][name]["version"] = version |
| 78 | + |
| 79 | + # add search image detail |
| 80 | + release_info_output["images"][SEARCH_IMAGE] = { |
| 81 | + "repositories": SEARCH_IMAGE_REPOSITORY, |
| 82 | + "platforms": ["linux/arm64", "linux/amd64"], |
| 83 | + "version": latest_search_version(release_data) |
| 84 | + } |
| 85 | + |
| 86 | + release_info_output = add_om_agent_mappings(release_data, release_info_output) |
| 87 | + |
| 88 | + return release_info_output |
| 89 | + |
| 90 | +def add_om_agent_mappings(release_data, output): |
| 91 | + om_agent_mapping = release_data["supportedImages"]["latestOpsManagerAgentMapping"] |
| 92 | + output["latestOpsManagerAgentMapping"] = om_agent_mapping |
73 | 93 |
|
74 | 94 | return output |
75 | 95 |
|
| 96 | +def latest_om_version(release_data): |
| 97 | + return release_data["supportedImages"]["ops-manager"]["versions"][-1] |
| 98 | + |
| 99 | +def latest_agent_version(release_data): |
| 100 | + newest_om_version = release_data["supportedImages"]["ops-manager"]["versions"][-1] |
| 101 | + newest_om_mapping = release_data["supportedImages"]["mongodb-agent"]["opsManagerMapping"]["ops_manager"][newest_om_version] |
| 102 | + return newest_om_mapping["agent_version"] |
| 103 | + |
| 104 | +def latest_search_version(release_data): |
| 105 | + return release_data["search"]["version"] |
76 | 106 |
|
77 | 107 | if __name__ == "__main__": |
78 | 108 | parser = argparse.ArgumentParser( |
79 | 109 | description="Create relevant release artifacts information in JSON format.", |
80 | 110 | formatter_class=argparse.RawTextHelpFormatter, |
81 | 111 | ) |
| 112 | + parser.add_argument("--version", help="released MCK version", required=True) |
82 | 113 | args = parser.parse_args() |
83 | 114 |
|
84 | | - release_info = create_release_info_json() |
| 115 | + release_info_filename = f"release_info_{args.version}.json" |
85 | 116 |
|
86 | | - if args.output is not None: |
87 | | - with open(args.output, "w") as file: |
| 117 | + release_info = create_release_info_json(args.version) |
| 118 | + |
| 119 | + if release_info_filename is not None: |
| 120 | + with open(release_info_filename, "w") as file: |
88 | 121 | file.write(release_info) |
89 | | - else: |
90 | | - print(release_info) |
| 122 | + |
| 123 | + upload_assets_to_github_release([release_info_filename], args.version) |
0 commit comments