We've been using a generic `osbuild-run`, which sets up the build environment (and works around bugs) for all build roots. It is already getting unwieldy, because it tries to detect the OS for some things it configures. It's also about to cause problems for RHEL, which doesn't currently support a python3 shebang without having /etc around. This patch changes the `build` key in a pipeline to not be a pipeline itself, but an object with `runner` and `pipeline` keys. `pipeline` is the build pipeline, as before. `runner` is the name of the runner to use. Runners are programs in the `runners` subdirectory. Three runners are included in this patch. They're copies of osbuild-run for now (except some additions for rhel82). The idea is that each of them only contains the minimal setup code necessary for an OS, and that we can review what's needed when updating a build root. Also modify the `--build-pipeline` command line switch to accept such a build object (instead of a pipeline) and rename it accordingly, to `--build-env`. Correspondingly, `OSBUILD_TEST_BUILD_PIPELINE` → `OSBUILD_TEST_BUILD_ENV`.
67 lines
2.2 KiB
Python
Executable file
67 lines
2.2 KiB
Python
Executable file
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
import osbuild
|
|
|
|
|
|
RESET = "\033[0m"
|
|
BOLD = "\033[1m"
|
|
RED = "\033[31m"
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Build operating system images")
|
|
parser.add_argument("pipeline_path", metavar="PIPELINE",
|
|
help="json file containing the pipeline that should be built, or a '-' to read from stdin")
|
|
parser.add_argument("--build-env", metavar="ENV", type=os.path.abspath,
|
|
help="json file containing a description of the build environment")
|
|
parser.add_argument("--store", metavar="DIRECTORY", type=os.path.abspath,
|
|
default=".osbuild",
|
|
help="the directory where intermediary os trees are stored")
|
|
parser.add_argument("-l", "--libdir", metavar="DIRECTORY", type=os.path.abspath,
|
|
help="the directory containing stages, assemblers, and the osbuild library")
|
|
parser.add_argument("--json", action="store_true",
|
|
help="output results in JSON format")
|
|
args = parser.parse_args()
|
|
|
|
if args.pipeline_path == "-":
|
|
f = sys.stdin
|
|
else:
|
|
f = open(args.pipeline_path)
|
|
pipeline = osbuild.load(json.load(f))
|
|
f.close()
|
|
|
|
if args.build_env:
|
|
with open(args.build_env) as f:
|
|
build_pipeline, runner = osbuild.load_build(json.load(f))
|
|
pipeline.prepend_build_env(build_pipeline, runner)
|
|
|
|
try:
|
|
pipeline.run(args.store, interactive=not args.json, libdir=args.libdir)
|
|
except KeyboardInterrupt:
|
|
print()
|
|
print(f"{RESET}{BOLD}{RED}Aborted{RESET}")
|
|
return 130
|
|
except (osbuild.StageFailed, osbuild.AssemblerFailed) as error:
|
|
print()
|
|
print(f"{RESET}{BOLD}{RED}{error.name} failed with code {error.returncode}{RESET}")
|
|
if args.json:
|
|
print(error.output)
|
|
return 1
|
|
|
|
if args.json:
|
|
json.dump({
|
|
"tree_id": pipeline.tree_id,
|
|
"output_id": pipeline.output_id,
|
|
}, sys.stdout)
|
|
sys.stdout.write("\n")
|
|
else:
|
|
print("tree id:", pipeline.tree_id)
|
|
print("output id:", pipeline.output_id)
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|