diff --git a/osbuild b/osbuild index cbeb862b..66931efe 100755 --- a/osbuild +++ b/osbuild @@ -17,6 +17,9 @@ if __name__ == "__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") + parser.add_argument("--objects", metavar="DIRECTORY", type=os.path.abspath, + default=".osbuild/objects", + help="the directory where intermediary os trees are stored") requiredNamed = parser.add_argument_group('required named arguments') requiredNamed.add_argument("-i", "--input", dest="input_dir", metavar="DIRECTORY", type=os.path.abspath, help="provide the contents of DIRECTORY to the first stage", required=True) @@ -28,7 +31,7 @@ if __name__ == "__main__": with open(args.pipeline_path) as f: pipeline = json.load(f) - pipeline = osbuild.Pipeline(pipeline) + pipeline = osbuild.Pipeline(pipeline, args.objects) print() print(f"{RESET}{BOLD}Pipeline: {pipeline.id}{RESET}") diff --git a/osbuild.py b/osbuild.py index 63300819..7cf7190e 100644 --- a/osbuild.py +++ b/osbuild.py @@ -2,6 +2,7 @@ import hashlib import json import os +import shutil import subprocess import sys import tempfile @@ -203,13 +204,16 @@ def print_header(title, options, machine_name): print() class Pipeline: - def __init__(self, pipeline): + def __init__(self, pipeline, objects): m = hashlib.sha256() m.update(json.dumps(pipeline, sort_keys=True).encode()) self.id = m.hexdigest() self.stages = pipeline["stages"] self.assembler = pipeline.get("assembler") + self.objects = objects + + os.makedirs(objects, exist_ok=True) def run(self, input_dir, output_dir, interactive=False): results = { @@ -231,5 +235,12 @@ class Pipeline: print_header(f"Assembling: {name}", options, buildroot.machine_name) r = buildroot.run_assembler(self.assembler, tree, input_dir, output_dir, interactive) results["assembler"] = r + else: + output_tree = os.path.join(self.objects, self.id) + + shutil.rmtree(output_tree, ignore_errors=True) + os.makedirs(output_tree, mode=0o755) + + subprocess.run(["cp", "-a", f"{tree}/.", output_tree], check=True) self.results = results diff --git a/samples/base-qcow2.json b/samples/base-qcow2.json index c9e14d8e..f328531f 100644 --- a/samples/base-qcow2.json +++ b/samples/base-qcow2.json @@ -4,7 +4,7 @@ { "name": "io.weldr.untree", "options": { - "tree": "base-with-grub2" + "tree": "efc7b094c174d9f5fd66c863db7128415f5df0f073125716f5279554f13a659f" } } ], diff --git a/samples/base-targz.json b/samples/base-targz.json index f5cd5a0e..afddb1ff 100644 --- a/samples/base-targz.json +++ b/samples/base-targz.json @@ -4,7 +4,7 @@ { "name": "io.weldr.untree", "options": { - "tree": "base" + "tree": "1f663f817473ffa5b01241b17adbd71bc734962313f5d4eef230073c0ac5884e" } } ], diff --git a/samples/base-with-grub2.json b/samples/base-with-grub2.json index 8a4d371e..ac3461e4 100644 --- a/samples/base-with-grub2.json +++ b/samples/base-with-grub2.json @@ -4,7 +4,7 @@ { "name": "io.weldr.untree", "options": { - "tree": "base" + "tree": "1f663f817473ffa5b01241b17adbd71bc734962313f5d4eef230073c0ac5884e" } }, { @@ -15,11 +15,5 @@ "partition_table_id": "0xdeadbeef" } } - ], - "assembler": { - "name": "io.weldr.tree", - "options": { - "tree": "base-with-grub2" - } - } + ] } diff --git a/samples/base-with-locale.json b/samples/base-with-locale.json index d532d302..b64ba71f 100644 --- a/samples/base-with-locale.json +++ b/samples/base-with-locale.json @@ -2,9 +2,9 @@ "name": "base-with-locale", "stages": [ { - "name": "io.weldr.untargz", + "name": "io.weldr.untree", "options": { - "filename": "base.tar.gz" + "tree": "1f663f817473ffa5b01241b17adbd71bc734962313f5d4eef230073c0ac5884e" } }, { @@ -13,11 +13,5 @@ "language": "en_US" } } - ], - "assembler": { - "name": "io.weldr.tree", - "options": { - "tree": "base-with-locale" - } - } + ] } diff --git a/samples/base-with-selinux.json b/samples/base-with-selinux.json index 81dd0936..11fcc9ce 100644 --- a/samples/base-with-selinux.json +++ b/samples/base-with-selinux.json @@ -4,7 +4,7 @@ { "name": "io.weldr.untree", "options": { - "tree": "base" + "tree": "1f663f817473ffa5b01241b17adbd71bc734962313f5d4eef230073c0ac5884e" } }, { @@ -13,11 +13,5 @@ "file_contexts": "etc/selinux/targeted/contexts/files/file_contexts" } } - ], - "assembler": { - "name": "io.weldr.tree", - "options": { - "tree": "base-with-selinux" - } - } + ] } diff --git a/samples/base.json b/samples/base.json index aaa479f1..eb19c34b 100644 --- a/samples/base.json +++ b/samples/base.json @@ -20,12 +20,5 @@ ] } } - ], - "assembler": - { - "name": "io.weldr.tree", - "options": { - "tree": "base" - } - } + ] }