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 <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-07-02 22:45:06 +02:00 committed by Lars Karlitski
parent ffffb87dea
commit cebed27cd9
9 changed files with 10 additions and 96 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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}")

View file

@ -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)

View file

@ -1,10 +0,0 @@
{
"name": "base-targz",
"base": "1f663f817473ffa5b01241b17adbd71bc734962313f5d4eef230073c0ac5884e"
"assembler": {
"name": "io.weldr.targz",
"options": {
"filename": "base.tar.gz"
}
}
}

View file

@ -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)

View file

@ -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)

View file

@ -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)