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:
parent
ffffb87dea
commit
cebed27cd9
9 changed files with 10 additions and 96 deletions
|
|
@ -43,7 +43,7 @@ def loop_device(image, size, offset=0):
|
||||||
finally:
|
finally:
|
||||||
subprocess.run(["losetup", "-d", loop], check=True)
|
subprocess.run(["losetup", "-d", loop], check=True)
|
||||||
|
|
||||||
def main(tree, input_dir, output_dir, options):
|
def main(tree, output_dir, options):
|
||||||
filename = options["filename"]
|
filename = options["filename"]
|
||||||
partition_table_id = options["partition_table_id"]
|
partition_table_id = options["partition_table_id"]
|
||||||
root_fs_uuid = options["root_fs_uuid"]
|
root_fs_uuid = options["root_fs_uuid"]
|
||||||
|
|
@ -78,5 +78,5 @@ def main(tree, input_dir, output_dir, options):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = json.load(sys.stdin)
|
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)
|
sys.exit(r)
|
||||||
|
|
|
||||||
|
|
@ -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)
|
|
||||||
|
|
@ -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)
|
|
||||||
4
osbuild
4
osbuild
|
|
@ -21,8 +21,6 @@ if __name__ == "__main__":
|
||||||
default=".osbuild/objects",
|
default=".osbuild/objects",
|
||||||
help="the directory where intermediary os trees are stored")
|
help="the directory where intermediary os trees are stored")
|
||||||
requiredNamed = parser.add_argument_group('required named arguments')
|
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,
|
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)
|
help="provide the empty DIRECTORY as output argument to the last stage", required=True)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
@ -37,7 +35,7 @@ if __name__ == "__main__":
|
||||||
print(f"{RESET}{BOLD}Pipeline: {pipeline.id}{RESET}")
|
print(f"{RESET}{BOLD}Pipeline: {pipeline.id}{RESET}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pipeline.run(args.input_dir, args.output_dir, interactive=True)
|
pipeline.run(args.output_dir, interactive=True)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print()
|
print()
|
||||||
print(f"{RESET}{BOLD}{RED}Aborted{RESET}")
|
print(f"{RESET}{BOLD}{RED}Aborted{RESET}")
|
||||||
|
|
|
||||||
17
osbuild.py
17
osbuild.py
|
|
@ -113,7 +113,7 @@ class BuildRoot:
|
||||||
raise ValueError(f"{r} tries to bind to a different location")
|
raise ValueError(f"{r} tries to bind to a different location")
|
||||||
return resources
|
return resources
|
||||||
|
|
||||||
def run_stage(self, stage, tree, input_dir=None, interactive=False):
|
def run_stage(self, stage, tree, interactive=False):
|
||||||
name = stage["name"]
|
name = stage["name"]
|
||||||
args = {
|
args = {
|
||||||
"tree": "/run/osbuild/tree",
|
"tree": "/run/osbuild/tree",
|
||||||
|
|
@ -125,10 +125,6 @@ class BuildRoot:
|
||||||
|
|
||||||
binds = [f"{tree}:/run/osbuild/tree", "/dev:/dev"]
|
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:
|
try:
|
||||||
r = self.run([f"/run/osbuild/{name}"],
|
r = self.run([f"/run/osbuild/{name}"],
|
||||||
binds=binds,
|
binds=binds,
|
||||||
|
|
@ -146,7 +142,7 @@ class BuildRoot:
|
||||||
"output": r.stdout
|
"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):
|
if output_dir and not os.path.exists(output_dir):
|
||||||
os.makedirs(output_dir)
|
os.makedirs(output_dir)
|
||||||
|
|
||||||
|
|
@ -162,9 +158,6 @@ class BuildRoot:
|
||||||
robinds.extend(self._get_system_resources_from_etc(assembler))
|
robinds.extend(self._get_system_resources_from_etc(assembler))
|
||||||
binds = ["/dev:/dev"]
|
binds = ["/dev:/dev"]
|
||||||
|
|
||||||
if input_dir:
|
|
||||||
robinds.append(f"{input_dir}:/run/osbuild/input")
|
|
||||||
args["input_dir"] = "/run/osbuild/input"
|
|
||||||
if output_dir:
|
if output_dir:
|
||||||
binds.append(f"{output_dir}:/run/osbuild/output")
|
binds.append(f"{output_dir}:/run/osbuild/output")
|
||||||
args["output_dir"] = "/run/osbuild/output"
|
args["output_dir"] = "/run/osbuild/output"
|
||||||
|
|
@ -216,7 +209,7 @@ class Pipeline:
|
||||||
|
|
||||||
os.makedirs(objects, exist_ok=True)
|
os.makedirs(objects, exist_ok=True)
|
||||||
|
|
||||||
def run(self, input_dir, output_dir, interactive=False):
|
def run(self, output_dir, interactive=False):
|
||||||
results = {
|
results = {
|
||||||
"stages": []
|
"stages": []
|
||||||
}
|
}
|
||||||
|
|
@ -231,7 +224,7 @@ class Pipeline:
|
||||||
options = stage.get("options", {})
|
options = stage.get("options", {})
|
||||||
if interactive:
|
if interactive:
|
||||||
print_header(f"{i}. {name}", options, buildroot.machine_name)
|
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)
|
results["stages"].append(r)
|
||||||
|
|
||||||
if self.assembler:
|
if self.assembler:
|
||||||
|
|
@ -239,7 +232,7 @@ class Pipeline:
|
||||||
options = self.assembler.get("options", {})
|
options = self.assembler.get("options", {})
|
||||||
if interactive:
|
if interactive:
|
||||||
print_header(f"Assembling: {name}", options, buildroot.machine_name)
|
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
|
results["assembler"] = r
|
||||||
else:
|
else:
|
||||||
output_tree = os.path.join(self.objects, self.id)
|
output_tree = os.path.join(self.objects, self.id)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"name": "base-targz",
|
|
||||||
"base": "1f663f817473ffa5b01241b17adbd71bc734962313f5d4eef230073c0ac5884e"
|
|
||||||
"assembler": {
|
|
||||||
"name": "io.weldr.targz",
|
|
||||||
"options": {
|
|
||||||
"filename": "base.tar.gz"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -43,7 +43,7 @@ def loop_device(image):
|
||||||
finally:
|
finally:
|
||||||
subprocess.run(["losetup", "-d", loop], check=True)
|
subprocess.run(["losetup", "-d", loop], check=True)
|
||||||
|
|
||||||
def main(tree, input_dir, options):
|
def main(tree, options):
|
||||||
partition_table_id = options["partition_table_id"]
|
partition_table_id = options["partition_table_id"]
|
||||||
root_fs_uuid = options["root_fs_uuid"]
|
root_fs_uuid = options["root_fs_uuid"]
|
||||||
|
|
||||||
|
|
@ -71,5 +71,5 @@ def main(tree, input_dir, options):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = json.load(sys.stdin)
|
args = json.load(sys.stdin)
|
||||||
r = main(args["tree"], args["input_dir"], args["options"])
|
r = main(args["tree"], args["options"])
|
||||||
sys.exit(r)
|
sys.exit(r)
|
||||||
|
|
|
||||||
|
|
@ -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)
|
|
||||||
|
|
@ -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)
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue