Skip to content
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

feat: Add structured output of products and their versions in bake.py #45

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ All notable changes to this project will be documented in this file.
## Added

- Add `--target-containerfile` argument to override the default `Dockerfile` value ([#44]).
- Add `--list-products` argument to get a machine-readable (JSON) output of all products and their versions ([#45]).

[#44]: https://github.com/stackabletech/image-tools/pull/44
[#45]: https://github.com/stackabletech/image-tools/pull/45

## 0.0.13 - 2024-09-06

Expand Down
6 changes: 6 additions & 0 deletions src/image_tools/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def bake_args() -> Namespace:

parser.add_argument("--cache", help="Enable distributed build cache", action="store_true")

parser.add_argument(
"--list-products",
action="store_true",
help="Display structured output of products and their versions in JSON format",
)

parser.add_argument(
"--build-arg",
help="Override build arguments. Expecting an KEY=VALUE format. The key is case insensitive.",
Expand Down
12 changes: 12 additions & 0 deletions src/image_tools/bake.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
from .version import version


def print_product_versions_json(conf) -> None:
"""Prints a JSON structured output of products and their versions."""
products_info = {}
for product in conf.products:
products_info[product["name"]] = [version["product"] for version in product.get("versions", [])]

print(json.dumps(products_info, indent=2))


def build_image_args(conf_build_args: Dict[str, str], release_version: str):
"""
Returns a list of --build-arg command line arguments that are used by the
Expand Down Expand Up @@ -214,6 +223,9 @@ def main() -> int:
return 0

conf = load_configuration(args.configuration, args.build_arg)
if args.show_products:
print_product_versions_json(conf)
return 0

bakefile = generate_bakefile(args, conf)

Expand Down