From 7da012a92be7a65504c105a29d9e7b5a179a4354 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Fri, 5 Jun 2020 14:48:37 -0700 Subject: [PATCH] composer-cli: Add new start-ostree command This is used to start an ostree build, it is only supported on ostree-composer, and requires the ostree ref and parent. It may also include --size and optionally be uploaded. Resolves: rhbz#1844649 --- src/composer/cli/compose.py | 83 +++++++++++++++++++++++++++++++++++++ src/composer/cli/help.py | 4 ++ 2 files changed, 87 insertions(+) diff --git a/src/composer/cli/compose.py b/src/composer/cli/compose.py index 22713994..bfabcb5a 100644 --- a/src/composer/cli/compose.py +++ b/src/composer/cli/compose.py @@ -75,6 +75,7 @@ def compose_cmd_v1(opts): "results": compose_results, "logs": compose_logs, "image": compose_image, + "start-ostree": compose_ostree, } return run_command(opts, cmd_map) @@ -375,6 +376,88 @@ def compose_start_v1(socket_path, api_version, args, show_json=False, testmode=0 return rc +def compose_ostree(socket_path, api_version, args, show_json=False, testmode=0): + """Start a new compose using the selected blueprint and type + + :param socket_path: Path to the Unix socket to use for API communication + :type socket_path: str + :param api_version: Version of the API to talk to. eg. "0" + :type api_version: str + :param args: List of remaining arguments from the cmdline + :type args: list of str + :param show_json: Set to True to show the JSON output instead of the human readable output + :type show_json: bool + :param testmode: Set to 1 to simulate a failed compose, set to 2 to simulate a finished one. + :type testmode: int + :param api: Details about the API server, "version" and "backend" + :type api: dict + + compose start [--size XXX] [ | ] + """ + # Get the optional size before checking other parameters + try: + args, size = get_size(args) + except (RuntimeError, ValueError) as e: + log.error(str(e)) + return 1 + + if len(args) == 0: + log.error("start-ostree is missing the blueprint name, output type, and ostree details") + return 1 + if len(args) == 1: + log.error("start-ostree is missing the output type") + return 1 + if len(args) == 2: + log.error("start-ostree is missing the ostree reference") + return 1 + if len(args) == 3: + log.error("start-ostree is missing the ostree parent") + return 1 + if len(args) == 5: + log.error("start-ostree is missing the provider and profile details") + return 1 + + config = { + "blueprint_name": args[0], + "compose_type": args[1], + "branch": "master", + "ostree": {"ref": args[2], "parent": args[3]}, + } + if size > 0: + config["size"] = size + + if len(args) == 6: + config["upload"] = {"image_name": args[4]} + # profile TOML file (maybe) + try: + config["upload"].update(toml.load(open(args[5]))) + except toml.TomlError as e: + log.error(str(e)) + return 1 + elif len(args) == 7: + config["upload"] = { + "image_name": args[4], + "provider": args[5], + "profile": args[6] + } + + if testmode: + test_url = "?test=%d" % testmode + else: + test_url = "" + api_route = client.api_url(api_version, "/compose" + test_url) + result = client.post_url_json(socket_path, api_route, json.dumps(config)) + (rc, exit_now) = handle_api_result(result, show_json) + if exit_now: + return rc + + print("Compose %s added to the queue" % result["build_id"]) + + if "upload_id" in result and result["upload_id"]: + print ("Upload %s added to the upload queue" % result["upload_id"]) + + return rc + def compose_log(socket_path, api_version, args, show_json=False, testmode=0): """Show the last part of the compose log diff --git a/src/composer/cli/help.py b/src/composer/cli/help.py index 332308b7..e055118e 100644 --- a/src/composer/cli/help.py +++ b/src/composer/cli/help.py @@ -20,6 +20,10 @@ compose start [--size XXXX] [ [ | ] + Start an ostree compose using the selected blueprint and output type. Optionally start an upload. This command + is only supported by osbuild-composer, and requires the ostree REF and PARENT. --size is in MiB. + compose types List the supported output types.