osbuild.py: run each stage/assembler in a fresh buildroot
Rather than making the buildroot shared for a pipeline, run each stage/assembler in a fresh one. This avoids state to leak between the stages/assemblers. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
7105bc91c7
commit
f5b1c80fb2
1 changed files with 35 additions and 33 deletions
68
osbuild.py
68
osbuild.py
|
|
@ -153,21 +153,22 @@ class Stage:
|
||||||
self.options = options
|
self.options = options
|
||||||
self.resources = resources
|
self.resources = resources
|
||||||
|
|
||||||
def run(self, buildroot, tree, interactive=False):
|
def run(self, tree, interactive=False):
|
||||||
if interactive:
|
with BuildRoot() as buildroot:
|
||||||
print_header(f"{self.name}", self.options, buildroot.machine_name)
|
if interactive:
|
||||||
|
print_header(f"{self.name}", self.options, buildroot.machine_name)
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
"tree": "/run/osbuild/tree",
|
"tree": "/run/osbuild/tree",
|
||||||
"options": self.options,
|
"options": self.options,
|
||||||
}
|
}
|
||||||
|
|
||||||
robinds = [f"{libdir}/stages/{self.name}:/run/osbuild/{self.name}"]
|
robinds = [f"{libdir}/stages/{self.name}:/run/osbuild/{self.name}"]
|
||||||
robinds.extend(_get_system_resources_from_etc(self.resources))
|
robinds.extend(_get_system_resources_from_etc(self.resources))
|
||||||
|
|
||||||
binds = [f"{tree}:/run/osbuild/tree", "/dev:/dev"]
|
binds = [f"{tree}:/run/osbuild/tree", "/dev:/dev"]
|
||||||
|
|
||||||
return buildroot.run(self.name, args, binds, robinds, interactive)
|
return buildroot.run(self.name, args, binds, robinds, interactive)
|
||||||
|
|
||||||
|
|
||||||
class Assembler:
|
class Assembler:
|
||||||
|
|
@ -176,29 +177,30 @@ class Assembler:
|
||||||
self.options = options
|
self.options = options
|
||||||
self.resources = resources
|
self.resources = resources
|
||||||
|
|
||||||
def run(self, buildroot, tree, output_dir=None, interactive=False):
|
def run(self, tree, output_dir=None, interactive=False):
|
||||||
if interactive:
|
with BuildRoot() as buildroot:
|
||||||
print_header(f"Assembling: {self.name}", self.options, buildroot.machine_name)
|
if interactive:
|
||||||
|
print_header(f"Assembling: {self.name}", self.options, buildroot.machine_name)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
"tree": "/run/osbuild/tree",
|
"tree": "/run/osbuild/tree",
|
||||||
"options": self.options,
|
"options": self.options,
|
||||||
}
|
}
|
||||||
robinds = [
|
robinds = [
|
||||||
f"{tree}:/run/osbuild/tree",
|
f"{tree}:/run/osbuild/tree",
|
||||||
f"{libdir}/assemblers/{self.name}:/run/osbuild/{self.name}"
|
f"{libdir}/assemblers/{self.name}:/run/osbuild/{self.name}"
|
||||||
]
|
]
|
||||||
robinds.extend(_get_system_resources_from_etc(self.resources))
|
robinds.extend(_get_system_resources_from_etc(self.resources))
|
||||||
binds = ["/dev:/dev"]
|
binds = ["/dev:/dev"]
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
return buildroot.run(self.name, args, binds, robinds, interactive)
|
return buildroot.run(self.name, args, binds, robinds, interactive)
|
||||||
|
|
||||||
|
|
||||||
class Pipeline:
|
class Pipeline:
|
||||||
|
|
@ -218,7 +220,7 @@ class Pipeline:
|
||||||
results = {
|
results = {
|
||||||
"stages": []
|
"stages": []
|
||||||
}
|
}
|
||||||
with BuildRoot() as buildroot, tmpfs() as tree:
|
with tmpfs() as tree:
|
||||||
if self.base:
|
if self.base:
|
||||||
input_tree = os.path.join(self.objects, self.base)
|
input_tree = os.path.join(self.objects, self.base)
|
||||||
subprocess.run(["cp", "-a", f"{input_tree}/.", tree], check=True)
|
subprocess.run(["cp", "-a", f"{input_tree}/.", tree], check=True)
|
||||||
|
|
@ -228,7 +230,7 @@ class Pipeline:
|
||||||
options = stage.get("options", {})
|
options = stage.get("options", {})
|
||||||
resources = stage.get("systemResourcesFromEtc", [])
|
resources = stage.get("systemResourcesFromEtc", [])
|
||||||
stage = Stage(name, options, resources)
|
stage = Stage(name, options, resources)
|
||||||
r = stage.run(buildroot, tree, interactive)
|
r = stage.run(tree, interactive)
|
||||||
results["stages"].append(r)
|
results["stages"].append(r)
|
||||||
|
|
||||||
if self.assembler:
|
if self.assembler:
|
||||||
|
|
@ -236,7 +238,7 @@ class Pipeline:
|
||||||
options = self.assembler.get("options", {})
|
options = self.assembler.get("options", {})
|
||||||
resources = self.assembler.get("systemResourcesFromEtc", [])
|
resources = self.assembler.get("systemResourcesFromEtc", [])
|
||||||
assembler = Assembler(name, options, resources)
|
assembler = Assembler(name, options, resources)
|
||||||
r = assembler.run(buildroot, tree, output_dir, interactive)
|
r = assembler.run(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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue