From cebed27cd9d82cf8a4aad64bd84cf9c2116f5a99 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Tue, 2 Jul 2019 22:45:06 +0200 Subject: [PATCH] osbuild: drop the concept of an input_dir This removes the possibility of passing in arbitrary input data. We now restrict ourselves to explicitly specified files/directories or a base tree given by its pipeline id. This drops the tar/tree stages/assemblers, as the tree/untree ones are implicit in osbuild, and if we wish to also support compressed trees, then we should add that to osbuild core as an option. Signed-off-by: Tom Gundersen --- assemblers/io.weldr.qcow2 | 4 ++-- assemblers/io.weldr.targz | 15 --------------- assemblers/io.weldr.tree | 21 --------------------- osbuild | 4 +--- osbuild.py | 17 +++++------------ samples/base-targz.json | 10 ---------- stages/io.weldr.grub2 | 4 ++-- stages/io.weldr.untargz | 15 --------------- stages/io.weldr.untree | 16 ---------------- 9 files changed, 10 insertions(+), 96 deletions(-) delete mode 100755 assemblers/io.weldr.targz delete mode 100755 assemblers/io.weldr.tree delete mode 100644 samples/base-targz.json delete mode 100755 stages/io.weldr.untargz delete mode 100755 stages/io.weldr.untree diff --git a/assemblers/io.weldr.qcow2 b/assemblers/io.weldr.qcow2 index 1645a6d9..aea8096b 100755 --- a/assemblers/io.weldr.qcow2 +++ b/assemblers/io.weldr.qcow2 @@ -43,7 +43,7 @@ def loop_device(image, size, offset=0): finally: subprocess.run(["losetup", "-d", loop], check=True) -def main(tree, input_dir, output_dir, options): +def main(tree, output_dir, options): filename = options["filename"] partition_table_id = options["partition_table_id"] root_fs_uuid = options["root_fs_uuid"] @@ -78,5 +78,5 @@ def main(tree, input_dir, output_dir, options): if __name__ == '__main__': args = json.load(sys.stdin) - r = main(args["tree"], args["input_dir"], args["output_dir"], args["options"]) + r = main(args["tree"], args["output_dir"], args["options"]) sys.exit(r) diff --git a/assemblers/io.weldr.targz b/assemblers/io.weldr.targz deleted file mode 100755 index de6988a2..00000000 --- a/assemblers/io.weldr.targz +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/python3 - -import json -import subprocess -import sys - -def main(tree, output_dir, options): - filename = options["filename"] - - subprocess.run(["tar", "-czf", f"{output_dir}/{filename}", "-C", tree, "."], stdout=subprocess.DEVNULL, check=True) - -if __name__ == '__main__': - args = json.load(sys.stdin) - r = main(args["tree"], args["output_dir"], args["options"]) - sys.exit(r) diff --git a/assemblers/io.weldr.tree b/assemblers/io.weldr.tree deleted file mode 100755 index 8da6ec39..00000000 --- a/assemblers/io.weldr.tree +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/python3 - -import json -import os -import shutil -import subprocess -import sys - -def main(tree, output_dir, options): - output_tree = os.path.join(output_dir, options["tree"]) - - shutil.rmtree(output_tree, ignore_errors=True) - os.makedirs(output_tree, mode=0o755) - - # Copy the tree to the output directory - subprocess.run(["cp", "-a", f"{tree}/.", output_tree], check=True) - -if __name__ == '__main__': - args = json.load(sys.stdin) - r = main(args["tree"], args["output_dir"], args["options"]) - sys.exit(r) diff --git a/osbuild b/osbuild index 66931efe..bc29c1d6 100755 --- a/osbuild +++ b/osbuild @@ -21,8 +21,6 @@ if __name__ == "__main__": 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) requiredNamed.add_argument("-o", "--output", dest="output_dir", metavar="DIRECTORY", type=os.path.abspath, help="provide the empty DIRECTORY as output argument to the last stage", required=True) args = parser.parse_args() @@ -37,7 +35,7 @@ if __name__ == "__main__": print(f"{RESET}{BOLD}Pipeline: {pipeline.id}{RESET}") try: - pipeline.run(args.input_dir, args.output_dir, interactive=True) + pipeline.run(args.output_dir, interactive=True) except KeyboardInterrupt: print() print(f"{RESET}{BOLD}{RED}Aborted{RESET}") diff --git a/osbuild.py b/osbuild.py index 8b799e91..8f6c3b13 100644 --- a/osbuild.py +++ b/osbuild.py @@ -113,7 +113,7 @@ class BuildRoot: raise ValueError(f"{r} tries to bind to a different location") return resources - def run_stage(self, stage, tree, input_dir=None, interactive=False): + def run_stage(self, stage, tree, interactive=False): name = stage["name"] args = { "tree": "/run/osbuild/tree", @@ -125,10 +125,6 @@ class BuildRoot: binds = [f"{tree}:/run/osbuild/tree", "/dev:/dev"] - if input_dir: - robinds.append(f"{input_dir}:/run/osbuild/input") - args["input_dir"] = "/run/osbuild/input" - try: r = self.run([f"/run/osbuild/{name}"], binds=binds, @@ -146,7 +142,7 @@ class BuildRoot: "output": r.stdout } - def run_assembler(self, assembler, tree, input_dir=None, output_dir=None, interactive=False): + def run_assembler(self, assembler, tree, output_dir=None, interactive=False): if output_dir and not os.path.exists(output_dir): os.makedirs(output_dir) @@ -162,9 +158,6 @@ class BuildRoot: robinds.extend(self._get_system_resources_from_etc(assembler)) binds = ["/dev:/dev"] - if input_dir: - robinds.append(f"{input_dir}:/run/osbuild/input") - args["input_dir"] = "/run/osbuild/input" if output_dir: binds.append(f"{output_dir}:/run/osbuild/output") args["output_dir"] = "/run/osbuild/output" @@ -216,7 +209,7 @@ class Pipeline: os.makedirs(objects, exist_ok=True) - def run(self, input_dir, output_dir, interactive=False): + def run(self, output_dir, interactive=False): results = { "stages": [] } @@ -231,7 +224,7 @@ class Pipeline: options = stage.get("options", {}) if interactive: print_header(f"{i}. {name}", options, buildroot.machine_name) - r = buildroot.run_stage(stage, tree, input_dir, interactive) + r = buildroot.run_stage(stage, tree, interactive) results["stages"].append(r) if self.assembler: @@ -239,7 +232,7 @@ class Pipeline: options = self.assembler.get("options", {}) if interactive: print_header(f"Assembling: {name}", options, buildroot.machine_name) - r = buildroot.run_assembler(self.assembler, tree, input_dir, output_dir, interactive) + r = buildroot.run_assembler(self.assembler, tree, output_dir, interactive) results["assembler"] = r else: output_tree = os.path.join(self.objects, self.id) diff --git a/samples/base-targz.json b/samples/base-targz.json deleted file mode 100644 index 52f4a949..00000000 --- a/samples/base-targz.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "base-targz", - "base": "1f663f817473ffa5b01241b17adbd71bc734962313f5d4eef230073c0ac5884e" - "assembler": { - "name": "io.weldr.targz", - "options": { - "filename": "base.tar.gz" - } - } -} diff --git a/stages/io.weldr.grub2 b/stages/io.weldr.grub2 index 1c22e6d8..e01b5d7e 100755 --- a/stages/io.weldr.grub2 +++ b/stages/io.weldr.grub2 @@ -43,7 +43,7 @@ def loop_device(image): finally: subprocess.run(["losetup", "-d", loop], check=True) -def main(tree, input_dir, options): +def main(tree, options): partition_table_id = options["partition_table_id"] root_fs_uuid = options["root_fs_uuid"] @@ -71,5 +71,5 @@ def main(tree, input_dir, options): if __name__ == '__main__': args = json.load(sys.stdin) - r = main(args["tree"], args["input_dir"], args["options"]) + r = main(args["tree"], args["options"]) sys.exit(r) diff --git a/stages/io.weldr.untargz b/stages/io.weldr.untargz deleted file mode 100755 index c6ec9c37..00000000 --- a/stages/io.weldr.untargz +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/python3 - -import json -import subprocess -import sys - -def main(tree, input_dir, options): - filename = options["filename"] - - subprocess.run(["tar", "-xzf", f"{input_dir}/{filename}", "-C", tree], stdout=subprocess.DEVNULL, check=True) - -if __name__ == '__main__': - args = json.load(sys.stdin) - r = main(args["tree"], args["input_dir"], args["options"]) - sys.exit(r) diff --git a/stages/io.weldr.untree b/stages/io.weldr.untree deleted file mode 100755 index c53795cb..00000000 --- a/stages/io.weldr.untree +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/python3 - -import json -import os -import subprocess -import sys - -def main(tree, input_dir, options): - input_tree = os.path.join(input_dir, options["tree"]) - - subprocess.run(["cp", "-a", f"{input_tree}/.", tree], check=True) - -if __name__ == '__main__': - args = json.load(sys.stdin) - r = main(args["tree"], args["input_dir"], args["options"]) - sys.exit(r)