Skip to content

Commit 64ca2a8

Browse files
authored
CLOUDP-295785 - build_info.json + script to create release_info.json (#307)
## Summary New `build_info.json` file that contains information about each image, binary and helm-chart that we are building per environment. This will necessary for: - building images in dev and staging (different platforms and registries) - building binaries (in dev we only need linux/amd64) - creating SBOMs - we need information about the image location as well as the supported platforms - promoting images - `build_info.json` stores information about production repositories After new build and release process will start to use `build_info.json`, we can get rid of duplicated information in `release.json` script. Added `release_info.py` script that builds relevant release information. This file will be added to GitHub Release assets and backup in S3 storage. This will be helpful for promotion process. Additionally our customers requested for information about all image versions that are shipped with the operator. This file will provide such information. ``` ➜ mongodb-kubernetes git:(ar-related-versions) ✗ python3 -m scripts.release.release_info --help usage: release_info.py [-h] [-p ] [-c ] [-s ] [-v ] [--output ] Create relevant release artifacts information in JSON format. options: -h, --help show this help message and exit -p, --path Path to the Git repository. Default is the current directory '.' -c, --changelog-path Path to the changelog directory relative to a current working directory. Default is 'changelog/' -s, --initial-commit-sha SHA of the initial commit to start from if no previous version tag is found. -v, --initial-version Version to use if no previous version tag is found. Default is '1.0.0' --output, -o Path to save the release information file. If not provided, prints to stdout. ``` ## Proof of Work Passing unit tests + tested the script locally. Example output of command `python3 -m scripts.release.release_info --initial-version "1.3.0" -o release_info.json`: ```json { "images": { "mongodbOperator": { "repository": "quay.io/mongodb/mongodb-kubernetes", "platforms": [ "linux/arm64", "linux/amd64" ], "version": "1.3.0" }, "initDatabase": { "repository": "quay.io/mongodb/mongodb-kubernetes-init-database", "platforms": [ "linux/arm64", "linux/amd64" ], "version": "1.3.0" }, "initAppDb": { "repository": "quay.io/mongodb/mongodb-kubernetes-init-appdb", "platforms": [ "linux/arm64", "linux/amd64" ], "version": "1.3.0" }, "initOpsManager": { "repository": "quay.io/mongodb/mongodb-kubernetes-init-ops-manager", "platforms": [ "linux/arm64", "linux/amd64" ], "version": "1.3.0" }, "database": { "repository": "quay.io/mongodb/mongodb-kubernetes-database", "platforms": [ "linux/arm64", "linux/amd64" ], "version": "1.3.0" }, "readinessprobe": { "repository": "quay.io/mongodb/mongodb-kubernetes-readinessprobe", "platforms": [ "linux/arm64", "linux/amd64" ], "version": "1.0.22" }, "operator-version-upgrade-post-start-hook": { "repository": "quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook", "platforms": [ "linux/arm64", "linux/amd64" ], "version": "1.0.9" } }, "binaries": { "kubectl-mongodb": { "platforms": [ "darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64" ], "version": "1.3.0" } }, "helm-charts": { "mongodb-kubernetes": { "repository": "quay.io/mongodb/helm-charts", "version": "1.3.0" } } } ``` ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details
1 parent b29fb4a commit 64ca2a8

21 files changed

+862
-63
lines changed

build_info.json

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
{
2+
"images": {
3+
"mongodbOperator": {
4+
"patch": {
5+
"repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes",
6+
"platforms": [
7+
"linux/amd64"
8+
]
9+
},
10+
"staging": {
11+
"repository": "quay.io/mongodb/mongodb-kubernetes-stg",
12+
"platforms": [
13+
"linux/arm64",
14+
"linux/amd64"
15+
]
16+
},
17+
"release": {
18+
"repository": "quay.io/mongodb/mongodb-kubernetes",
19+
"platforms": [
20+
"linux/arm64",
21+
"linux/amd64"
22+
]
23+
}
24+
},
25+
"initDatabase": {
26+
"patch": {
27+
"repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-init-database",
28+
"platforms": [
29+
"linux/amd64"
30+
]
31+
},
32+
"staging": {
33+
"repository": "quay.io/mongodb/mongodb-kubernetes-init-database-stg",
34+
"platforms": [
35+
"linux/arm64",
36+
"linux/amd64"
37+
]
38+
},
39+
"release": {
40+
"repository": "quay.io/mongodb/mongodb-kubernetes-init-database",
41+
"platforms": [
42+
"linux/arm64",
43+
"linux/amd64"
44+
]
45+
}
46+
},
47+
"initAppDb": {
48+
"patch": {
49+
"repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-init-appdb",
50+
"platforms": [
51+
"linux/amd64"
52+
]
53+
},
54+
"staging": {
55+
"repository": "quay.io/mongodb/mongodb-kubernetes-init-appdb-stg",
56+
"platforms": [
57+
"linux/arm64",
58+
"linux/amd64"
59+
]
60+
},
61+
"release": {
62+
"repository": "quay.io/mongodb/mongodb-kubernetes-init-appdb",
63+
"platforms": [
64+
"linux/arm64",
65+
"linux/amd64"
66+
]
67+
}
68+
},
69+
"initOpsManager": {
70+
"patch": {
71+
"repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-init-ops-manager",
72+
"platforms": [
73+
"linux/amd64"
74+
]
75+
},
76+
"staging": {
77+
"repository": "quay.io/mongodb/mongodb-kubernetes-init-ops-manager-stg",
78+
"platforms": [
79+
"linux/arm64",
80+
"linux/amd64"
81+
]
82+
},
83+
"release": {
84+
"repository": "quay.io/mongodb/mongodb-kubernetes-init-ops-manager",
85+
"platforms": [
86+
"linux/arm64",
87+
"linux/amd64"
88+
]
89+
}
90+
},
91+
"database": {
92+
"patch": {
93+
"repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-database",
94+
"platforms": [
95+
"linux/amd64"
96+
]
97+
},
98+
"staging": {
99+
"repository": "quay.io/mongodb/mongodb-kubernetes-database-stg",
100+
"platforms": [
101+
"linux/arm64",
102+
"linux/amd64"
103+
]
104+
},
105+
"release": {
106+
"repository": "quay.io/mongodb/mongodb-kubernetes-database",
107+
"platforms": [
108+
"linux/arm64",
109+
"linux/amd64"
110+
]
111+
}
112+
},
113+
"readinessprobe": {
114+
"patch": {
115+
"repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-readinessprobe",
116+
"platforms": [
117+
"linux/amd64"
118+
]
119+
},
120+
"staging": {
121+
"repository": "quay.io/mongodb/mongodb-kubernetes-readinessprobe-stg",
122+
"platforms": [
123+
"linux/arm64",
124+
"linux/amd64"
125+
]
126+
},
127+
"release": {
128+
"version": "1.0.22",
129+
"repository": "quay.io/mongodb/mongodb-kubernetes-readinessprobe",
130+
"platforms": [
131+
"linux/arm64",
132+
"linux/amd64"
133+
]
134+
}
135+
},
136+
"operator-version-upgrade-post-start-hook": {
137+
"patch": {
138+
"repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-operator-version-upgrade-post-start-hook",
139+
"platforms": [
140+
"linux/amd64"
141+
]
142+
},
143+
"staging": {
144+
"repository": "quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook-stg",
145+
"platforms": [
146+
"linux/arm64",
147+
"linux/amd64"
148+
]
149+
},
150+
"release": {
151+
"version": "1.0.9",
152+
"repository": "quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook",
153+
"platforms": [
154+
"linux/arm64",
155+
"linux/amd64"
156+
]
157+
}
158+
}
159+
},
160+
"binaries": {
161+
"kubectl-mongodb": {
162+
"patch": {
163+
"s3-store": "s3://kubectl-mongodb/dev",
164+
"platforms": [
165+
"linux/amd64"
166+
]
167+
},
168+
"staging": {
169+
"s3-store": "s3://kubectl-mongodb/staging",
170+
"platforms": [
171+
"darwin/amd64",
172+
"darwin/arm64",
173+
"linux/amd64",
174+
"linux/arm64"
175+
]
176+
},
177+
"release": {
178+
"s3-store": "s3://kubectl-mongodb/prod",
179+
"platforms": [
180+
"darwin/amd64",
181+
"darwin/arm64",
182+
"linux/amd64",
183+
"linux/arm64"
184+
]
185+
}
186+
}
187+
},
188+
"helm-charts": {
189+
"mongodb-kubernetes": {
190+
"patch": {
191+
"repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/helm-charts"
192+
},
193+
"staging": {
194+
"repository": "quay.io/mongodb/helm-charts-stg"
195+
},
196+
"release": {
197+
"repository": "quay.io/mongodb/helm-charts"
198+
}
199+
}
200+
}
201+
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.black]
22
line-length = 120
3-
target-version = ['py39']
3+
target-version = ['py313']
44
include = '\.pyi?$'
55

66
[tool.isort]

scripts/release/build/__init__.py

Whitespace-only changes.

scripts/release/build/build_info.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import json
2+
from typing import Dict
3+
4+
from scripts.release.build.build_scenario import BuildScenario
5+
from scripts.release.constants import DEFAULT_REPOSITORY_PATH, DEFAULT_CHANGELOG_PATH, RELEASE_INITIAL_VERSION_ENV_VAR, \
6+
get_initial_version, get_initial_commit_sha
7+
8+
9+
class ImageInfo(dict):
10+
def __init__(self, repository: str, platforms: list[str], version: str):
11+
super().__init__()
12+
self.repository = repository
13+
self.platforms = platforms
14+
self.version = version
15+
16+
def to_json(self):
17+
return {"repository": self.repository, "platforms": self.platforms, "version": self.version}
18+
19+
20+
class BinaryInfo(dict):
21+
def __init__(self, s3_store: str, platforms: list[str], version: str):
22+
super().__init__()
23+
self.s3_store = s3_store
24+
self.platforms = platforms
25+
self.version = version
26+
27+
def to_json(self):
28+
return {"platforms": self.platforms, "version": self.version}
29+
30+
31+
class HelmChartInfo(dict):
32+
def __init__(self, repository: str, version: str):
33+
super().__init__()
34+
self.repository = repository
35+
self.version = version
36+
37+
def to_json(self):
38+
return {"repository": self.repository, "version": self.version}
39+
40+
41+
class BuildInfo(dict):
42+
def __init__(
43+
self, images: Dict[str, ImageInfo], binaries: Dict[str, BinaryInfo], helm_charts: Dict[str, HelmChartInfo]
44+
):
45+
super().__init__()
46+
self.images = images
47+
self.binaries = binaries
48+
self.helm_charts = helm_charts
49+
50+
def __dict__(self):
51+
return {
52+
"images": {name: images.__dict__ for name, images in self.images.items()},
53+
"binaries": {name: bin.__dict__ for name, bin in self.binaries.items()},
54+
"helm-charts": {name: chart.__dict__ for name, chart in self.helm_charts.items()},
55+
}
56+
57+
def to_json(self):
58+
return {
59+
"images": {name: images.to_json() for name, images in self.images.items()},
60+
"binaries": {name: bin.to_json() for name, bin in self.binaries.items()},
61+
"helm-charts": {name: chart.to_json() for name, chart in self.helm_charts.items()},
62+
}
63+
64+
65+
def load_build_info(scenario: BuildScenario,
66+
repository_path: str = DEFAULT_REPOSITORY_PATH,
67+
changelog_sub_path: str = DEFAULT_CHANGELOG_PATH,
68+
initial_commit_sha: str = None,
69+
initial_version: str = None) -> BuildInfo:
70+
f"""
71+
Load build information based on the specified scenario.
72+
73+
:param scenario: BuildScenario enum value indicating the build scenario (e.g., PATCH, STAGING, RELEASE).
74+
:param repository_path: Path to the Git repository. Default is the current directory `{DEFAULT_REPOSITORY_PATH}`.
75+
:param changelog_sub_path: Path to the changelog directory relative to the repository root. Default is '{DEFAULT_CHANGELOG_PATH}'.
76+
:param initial_commit_sha: SHA of the initial commit to start from if no previous version tag is found. If not provided, it will be determined based on `{RELEASE_INITIAL_VERSION_ENV_VAR} environment variable.
77+
:param initial_version: Initial version to use if no previous version tag is found. If not provided, it will be determined based on `{RELEASE_INITIAL_VERSION_ENV_VAR}` environment variable.
78+
:return: BuildInfo object containing images, binaries, and helm charts information for specified scenario.
79+
"""
80+
81+
if not initial_commit_sha:
82+
initial_commit_sha = get_initial_commit_sha()
83+
if not initial_version:
84+
initial_version = get_initial_version()
85+
86+
version = scenario.get_version(repository_path, changelog_sub_path, initial_commit_sha, initial_version)
87+
88+
with open("build_info.json", "r") as f:
89+
build_info = json.load(f)
90+
91+
images = {}
92+
for name, env_data in build_info["images"].items():
93+
data = env_data[scenario]
94+
# Only update the image_version if it is not already set in the build_info.json file
95+
image_version = data.get("version")
96+
if not image_version:
97+
image_version = version
98+
99+
images[name] = ImageInfo(repository=data["repository"], platforms=data["platforms"], version=image_version)
100+
101+
binaries = {}
102+
for name, env_data in build_info["binaries"].items():
103+
data = env_data[scenario]
104+
binaries[name] = BinaryInfo(s3_store=data["s3-store"], platforms=data["platforms"], version=version)
105+
106+
helm_charts = {}
107+
for name, env_data in build_info["helm-charts"].items():
108+
data = env_data[scenario]
109+
helm_charts[name] = HelmChartInfo(repository=data["repository"], version=version)
110+
111+
return BuildInfo(images=images, binaries=binaries, helm_charts=helm_charts)

0 commit comments

Comments
 (0)