BuildRoot: require the root directory to be passed in

Rather than hard-coding this to /, let the caller provide the
directory path to use.

In the past, we needed to give special treatment to /, as it had
to be bind-mounted before being used by nspawn, to work around a
check they had, refusing to use the host root in the container.

We no longer pass the directory directly to nspawn, but rather
mount the subdirs we want ourselves, so that no longer applies.

The callers pass in /, so the behavior is unchanged.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-07-25 00:46:08 +02:00
parent 834823f131
commit 5eaa553563

View file

@ -70,12 +70,12 @@ class TmpFs:
class BuildRoot: class BuildRoot:
def __init__(self, path="/run/osbuild"): def __init__(self, root, path="/run/osbuild"):
self.root = tempfile.mkdtemp(prefix="osbuild-buildroot-", dir=path) self.root = tempfile.mkdtemp(prefix="osbuild-buildroot-", dir=path)
self.api = tempfile.mkdtemp(prefix="osbuild-api-", dir=path) self.api = tempfile.mkdtemp(prefix="osbuild-api-", dir=path)
self.mounts = [] self.mounts = []
for p in ["usr", "bin", "sbin", "lib", "lib64"]: for p in ["usr", "bin", "sbin", "lib", "lib64"]:
source = os.path.join("/", p) source = os.path.join(root, p)
target = os.path.join(self.root, p) target = os.path.join(self.root, p)
if not os.path.isdir(source) or os.path.islink(source): if not os.path.isdir(source) or os.path.islink(source):
continue # only bind-mount real dirs continue # only bind-mount real dirs
@ -155,8 +155,8 @@ class Stage:
self.name = name self.name = name
self.options = options self.options = options
def run(self, tree, interactive=False, check=True, libdir=None): def run(self, tree, build_tree, interactive=False, check=True, libdir=None):
with BuildRoot() as buildroot: with BuildRoot(build_tree) as buildroot:
if interactive: if interactive:
print_header(f"{self.name}: {self.id}", self.options) print_header(f"{self.name}: {self.id}", self.options)
@ -190,8 +190,8 @@ class Assembler:
self.name = name self.name = name
self.options = options self.options = options
def run(self, tree, output_dir=None, interactive=False, check=True, libdir=None): def run(self, tree, build_tree, output_dir=None, interactive=False, check=True, libdir=None):
with BuildRoot() as buildroot: with BuildRoot(build_tree) as buildroot:
if interactive: if interactive:
print_header(f"Assembling: {self.name}", self.options) print_header(f"Assembling: {self.name}", self.options)
@ -256,14 +256,23 @@ class Pipeline:
subprocess.run(["cp", "-a", f"{objects}/{self.base}/.", tree], check=True) subprocess.run(["cp", "-a", f"{objects}/{self.base}/.", tree], check=True)
for stage in self.stages: for stage in self.stages:
r = stage.run(tree, interactive, check, libdir=libdir) r = stage.run(tree,
"/",
interactive=interactive,
check=check,
libdir=libdir)
results["stages"].append(r) results["stages"].append(r)
if r["returncode"] != 0: if r["returncode"] != 0:
results["returncode"] = r["returncode"] results["returncode"] = r["returncode"]
return results return results
if self.assembler: if self.assembler:
r = self.assembler.run(tree, output_dir, interactive, check, libdir=libdir) r = self.assembler.run(tree,
"/",
output_dir=output_dir,
interactive=interactive,
check=check,
libdir=libdir)
results["assembler"] = r results["assembler"] = r
if r["returncode"] != 0: if r["returncode"] != 0:
results["returncode"] = r["returncode"] results["returncode"] = r["returncode"]