-
Notifications
You must be signed in to change notification settings - Fork 23
CLOUDP-295785 - script to create release_info.json #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
05029e9
wip: initial release_info.py function
MaciejKaras aeafcfb
wip: added tests + `get_version_for_environment` function
MaciejKaras 0994d18
Added CMD function to create release_info.json
MaciejKaras 2317dc5
Review fixes
MaciejKaras 285ba41
refactor of the code
MaciejKaras 790bbcd
add missing fixtures
MaciejKaras 50dce8b
test fixes
MaciejKaras 38a84a0
Test fixes
MaciejKaras cb41432
Test fixes
MaciejKaras 8a0f1d9
more changes
MaciejKaras eacace9
test fixes
MaciejKaras 2e55e29
fixes
MaciejKaras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| { | ||
| "images": { | ||
| "mongodbOperator": { | ||
| "dev": { | ||
| "repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes", | ||
| "platforms": [ | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "staging": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-stg", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "prod": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| } | ||
| }, | ||
| "initDatabase": { | ||
| "dev": { | ||
| "repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-init-database", | ||
| "platforms": [ | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "staging": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-init-database-stg", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "prod": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-init-database", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| } | ||
| }, | ||
| "initAppDb": { | ||
| "dev": { | ||
| "repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-init-appdb", | ||
| "platforms": [ | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "staging": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-init-appdb-stg", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "prod": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-init-appdb", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| } | ||
| }, | ||
| "initOpsManager": { | ||
| "dev": { | ||
| "repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-init-ops-manager", | ||
| "platforms": [ | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "staging": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-init-ops-manager-stg", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "prod": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-init-ops-manager", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| } | ||
| }, | ||
| "database": { | ||
| "dev": { | ||
| "repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-database", | ||
| "platforms": [ | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "staging": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-database-stg", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "prod": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-database", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| } | ||
| }, | ||
| "readinessprobe": { | ||
| "dev": { | ||
| "repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-readinessprobe", | ||
| "platforms": [ | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "staging": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-readinessprobe-stg", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "prod": { | ||
| "version": "1.0.22", | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-readinessprobe", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| } | ||
| }, | ||
| "operator-version-upgrade-post-start-hook": { | ||
| "dev": { | ||
| "repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/mongodb-kubernetes-operator-version-upgrade-post-start-hook", | ||
| "platforms": [ | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "staging": { | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook-stg", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "prod": { | ||
| "version": "1.0.9", | ||
| "repository": "quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook", | ||
| "platforms": [ | ||
| "linux/arm64", | ||
| "linux/amd64" | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "binaries": { | ||
| "kubectl-mongodb": { | ||
| "dev": { | ||
| "s3-store": "s3://kubectl-mongodb/dev", | ||
| "platforms": [ | ||
| "linux/amd64" | ||
| ] | ||
| }, | ||
| "staging": { | ||
| "s3-store": "s3://kubectl-mongodb/staging", | ||
| "platforms": [ | ||
| "darwin/amd64", | ||
| "darwin/arm64", | ||
| "linux/amd64", | ||
| "linux/arm64" | ||
| ] | ||
| }, | ||
| "prod": { | ||
| "s3-store": "s3://kubectl-mongodb/prod", | ||
| "platforms": [ | ||
| "darwin/amd64", | ||
| "darwin/arm64", | ||
| "linux/amd64", | ||
| "linux/arm64" | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "helm-charts": { | ||
| "mongodb-kubernetes": { | ||
| "dev": { | ||
| "repository": "268558157000.dkr.ecr.us-east-1.amazonaws.com/dev/helm-charts" | ||
| }, | ||
| "staging": { | ||
| "repository": "quay.io/mongodb/helm-charts-stg" | ||
| }, | ||
| "prod": { | ||
| "repository": "quay.io/mongodb/helm-charts" | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import argparse | ||
| import json | ||
| import pathlib | ||
| from typing import Dict | ||
|
|
||
| from scripts.release.version import ( | ||
| Environment, | ||
| ) | ||
|
|
||
|
|
||
| class ImageInfo(dict): | ||
| def __init__(self, repository: str, platforms: list[str], version: str): | ||
| super().__init__() | ||
| self.repository = repository | ||
| self.platforms = platforms | ||
| self.version = version | ||
|
|
||
| def to_json(self): | ||
| return {"repository": self.repository, "platforms": self.platforms, "version": self.version} | ||
|
|
||
|
|
||
| class BinaryInfo(dict): | ||
| def __init__(self, s3_store: str, platforms: list[str], version: str): | ||
| super().__init__() | ||
| self.s3_store = s3_store | ||
| self.platforms = platforms | ||
| self.version = version | ||
|
|
||
| def to_json(self): | ||
| return {"platforms": self.platforms, "version": self.version} | ||
|
|
||
viveksinghggits marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| class HelmChartInfo(dict): | ||
| def __init__(self, repository: str, version: str): | ||
| super().__init__() | ||
| self.repository = repository | ||
| self.version = version | ||
|
|
||
| def to_json(self): | ||
| return {"repository": self.repository, "version": self.version} | ||
|
|
||
|
|
||
| class BuildInfo(dict): | ||
| def __init__( | ||
| self, images: Dict[str, ImageInfo], binaries: Dict[str, BinaryInfo], helm_charts: Dict[str, HelmChartInfo] | ||
| ): | ||
| super().__init__() | ||
| self.images = images | ||
| self.binaries = binaries | ||
| self.helm_charts = helm_charts | ||
|
|
||
| def __dict__(self): | ||
| return { | ||
| "images": {name: images.__dict__ for name, images in self.images.items()}, | ||
| "binaries": {name: bin.__dict__ for name, bin in self.binaries.items()}, | ||
| "helm-charts": {name: chart.__dict__ for name, chart in self.helm_charts.items()}, | ||
| } | ||
|
|
||
| def to_json(self): | ||
| return { | ||
| "images": {name: images.to_json() for name, images in self.images.items()}, | ||
| "binaries": {name: bin.to_json() for name, bin in self.binaries.items()}, | ||
| "helm-charts": {name: chart.to_json() for name, chart in self.helm_charts.items()}, | ||
| } | ||
|
|
||
|
|
||
| def load_build_info(environment: Environment, version: str) -> BuildInfo: | ||
viveksinghggits marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| with open("build_info.json", "r") as f: | ||
| build_info = json.load(f) | ||
|
|
||
| images = {} | ||
| for name, env_data in build_info["images"].items(): | ||
| data = env_data[environment] | ||
| # Only update the image_version if it is not already set in the build_info.json file | ||
| image_version = data.get("version") | ||
| if not image_version: | ||
| image_version = version | ||
|
|
||
| images[name] = ImageInfo(repository=data["repository"], platforms=data["platforms"], version=image_version) | ||
|
|
||
| binaries = {} | ||
| for name, env_data in build_info["binaries"].items(): | ||
| data = env_data[environment] | ||
| binaries[name] = BinaryInfo(s3_store=data["s3-store"], platforms=data["platforms"], version=version) | ||
|
|
||
| helm_charts = {} | ||
| for name, env_data in build_info["helm-charts"].items(): | ||
| data = env_data[environment] | ||
| helm_charts[name] = HelmChartInfo(repository=data["repository"], version=version) | ||
|
|
||
| return BuildInfo(images=images, binaries=binaries, helm_charts=helm_charts) | ||
|
|
||
|
|
||
| def create_release_info_json(version: str) -> str: | ||
| build_info = load_build_info(Environment.PROD, version) | ||
|
|
||
| return json.dumps(build_info.to_json(), indent=2) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser( | ||
| description="Create relevant release artifacts information in JSON format.", | ||
| formatter_class=argparse.RawTextHelpFormatter, | ||
| ) | ||
| parser.add_argument( | ||
| "-v", | ||
| "--version", | ||
| metavar="", | ||
| action="store", | ||
| type=str, | ||
| help=f"Version to use for this release.", | ||
| ) | ||
| parser.add_argument( | ||
| "--output", | ||
| "-o", | ||
| metavar="", | ||
| type=pathlib.Path, | ||
| help="Path to save the release information file. If not provided, prints to stdout.", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| release_info = create_release_info_json(args.version) | ||
|
|
||
| if args.output is not None: | ||
| with open(args.output, "w") as file: | ||
| file.write(release_info) | ||
| else: | ||
| print(release_info) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.