stage api: pass options in a separate key
This avoids name clashes between osbuild and stage options.
This commit is contained in:
parent
2d487fe685
commit
92f3af94f6
12 changed files with 77 additions and 47 deletions
|
|
@ -4,9 +4,12 @@ import json
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
def main(tree, input_dir, output_dir, filename):
|
||||
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__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
args = json.load(sys.stdin)
|
||||
r = main(args["tree"], args["output_dir"], args["options"])
|
||||
sys.exit(r)
|
||||
|
|
|
|||
21
osbuild.py
21
osbuild.py
|
|
@ -104,10 +104,9 @@ class BuildRoot:
|
|||
|
||||
def run_stage(self, stage, tree, input_dir=None):
|
||||
name = stage["name"]
|
||||
options = {
|
||||
**stage.get("options", {}),
|
||||
args = {
|
||||
"tree": "/run/osbuild/tree",
|
||||
"input_dir": None
|
||||
"options": stage.get("options", {})
|
||||
}
|
||||
|
||||
robinds = [f"{libdir}/stages/{name}:/run/osbuild/{name}"]
|
||||
|
|
@ -116,10 +115,10 @@ class BuildRoot:
|
|||
binds = [f"{tree}:/run/osbuild/tree"]
|
||||
if input_dir:
|
||||
robinds.append(f"{input_dir}:/run/osbuild/input")
|
||||
options["input_dir"] = "/run/osbuild/input"
|
||||
args["input_dir"] = "/run/osbuild/input"
|
||||
|
||||
try:
|
||||
self.run([f"/run/osbuild/{name}"], binds=binds, readonly_binds=robinds, input=json.dumps(options), encoding="utf-8", check=True)
|
||||
self.run([f"/run/osbuild/{name}"], binds=binds, readonly_binds=robinds, input=json.dumps(args), encoding="utf-8", check=True)
|
||||
except subprocess.CalledProcessError as error:
|
||||
raise StageFailed(name, error.returncode)
|
||||
|
||||
|
|
@ -128,11 +127,9 @@ class BuildRoot:
|
|||
os.makedirs(output_dir)
|
||||
|
||||
name = assembler["name"]
|
||||
options = {
|
||||
**assembler.get("options", {}),
|
||||
args = {
|
||||
"tree": "/run/osbuild/tree",
|
||||
"input_dir": None,
|
||||
"output_dir": None
|
||||
"options": assembler.get("options", {}),
|
||||
}
|
||||
robinds = [
|
||||
f"{tree}:/run/osbuild/tree",
|
||||
|
|
@ -143,13 +140,13 @@ class BuildRoot:
|
|||
|
||||
if input_dir:
|
||||
robinds.append(f"{input_dir}:/run/osbuild/input")
|
||||
options["input_dir"] = "/run/osbuild/input"
|
||||
args["input_dir"] = "/run/osbuild/input"
|
||||
if output_dir:
|
||||
binds.append(f"{output_dir}:/run/osbuild/output")
|
||||
options["output_dir"] = "/run/osbuild/output"
|
||||
args["output_dir"] = "/run/osbuild/output"
|
||||
|
||||
try:
|
||||
self.run([f"/run/osbuild/{name}"], binds=binds, readonly_binds=robinds, input=json.dumps(options), encoding="utf-8", check=True)
|
||||
self.run([f"/run/osbuild/{name}"], binds=binds, readonly_binds=robinds, input=json.dumps(args), encoding="utf-8", check=True)
|
||||
except subprocess.CalledProcessError as error:
|
||||
raise StageFailed(name, error.returncode)
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,10 @@ product = """
|
|||
product_name = Fedora
|
||||
"""
|
||||
|
||||
def main(tree, input_dir, kickstart, skip_package_install=False):
|
||||
def main(tree, options):
|
||||
kickstart = options["kickstart"]
|
||||
skip_package_install = options.get("skip_package_install", False)
|
||||
|
||||
with open("/tmp/kickstart.ks", "w") as f:
|
||||
if skip_package_install:
|
||||
subprocess.run(["tar", "cvf", "/tmp/empty.tar", "--files-from", "/dev/null"])
|
||||
|
|
@ -113,5 +116,6 @@ def main(tree, input_dir, kickstart, skip_package_install=False):
|
|||
return returncode
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
args = json.load(sys.stdin)
|
||||
r = main(args["tree"], args["options"])
|
||||
sys.exit(r)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ import subprocess
|
|||
import sys
|
||||
|
||||
|
||||
def main(tree, input_dir, playbook):
|
||||
def main(tree, options):
|
||||
playbook = options["playbook"]
|
||||
|
||||
with open("/tmp/inventory", "w") as f:
|
||||
f.write(f"osbuild-tree ansible_connection=chroot ansible_host={tree} ansible_python_interpreter=/usr/bin/python3")
|
||||
|
||||
|
|
@ -26,5 +28,6 @@ def main(tree, input_dir, playbook):
|
|||
return r.returncode
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
args = json.load(sys.stdin)
|
||||
r = main(args["tree"], args["options"])
|
||||
sys.exit(r)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ import subprocess
|
|||
import sys
|
||||
|
||||
|
||||
def main(tree, input_dir, repos, packages, releasever):
|
||||
def main(tree, options):
|
||||
repos = options["repos"]
|
||||
packages = options["packages"]
|
||||
releasever = options["releasever"]
|
||||
|
||||
with open("/tmp/dnf.conf", "w") as conf:
|
||||
p = configparser.ConfigParser()
|
||||
p.read_dict(repos)
|
||||
|
|
@ -41,5 +45,6 @@ def main(tree, input_dir, repos, packages, releasever):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
args = json.load(sys.stdin)
|
||||
r = main(args["tree"], args["options"])
|
||||
sys.exit(r)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@
|
|||
import json
|
||||
import sys
|
||||
|
||||
def main(tree, input_dir, language, vc_keymap=None):
|
||||
def main(tree, options):
|
||||
language = options["language"]
|
||||
vc_keymap = options.get(vc_keymap)
|
||||
|
||||
with open(f"{tree}/etc/locale.conf", "w") as f:
|
||||
f.write(f'LANG="{language}"\n')
|
||||
|
||||
|
|
@ -13,6 +16,6 @@ def main(tree, input_dir, language, vc_keymap=None):
|
|||
f.write(f'FONT="eurlatgr"\n')
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
|
||||
args = json.load(sys.stdin)
|
||||
r = main(args["tree"], args["options"])
|
||||
sys.exit(r)
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
import json
|
||||
import sys
|
||||
|
||||
def main(tree, input_dir, **options):
|
||||
def main(tree, options):
|
||||
print("Not doing anything with these options:", json.dumps(options))
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
args = json.load(sys.stdin)
|
||||
r = main(args["tree"], args.get("options", {}))
|
||||
sys.exit(r)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,9 @@ def loop_device(image):
|
|||
finally:
|
||||
subprocess.run(["losetup", "-d", loop], check=True)
|
||||
|
||||
def main(tree, input_dir, target):
|
||||
def main(tree, options):
|
||||
target = options["target"])
|
||||
|
||||
size = tree_size(tree)
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=os.getcwd()) as workdir:
|
||||
|
|
@ -65,10 +67,12 @@ def main(tree, input_dir, target):
|
|||
subprocess.run(["qemu-img", "convert", "-O" "qcow2", "-c", image, target], check=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = json.load(sys.stdin)
|
||||
args = json.load(sys.stdin)
|
||||
|
||||
try:
|
||||
main(**options)
|
||||
r = main(args["tree"], args["options"])
|
||||
except CalledProcessError as e:
|
||||
print(e, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
r = 1
|
||||
|
||||
sys.exit(r)
|
||||
|
|
|
|||
|
|
@ -5,11 +5,12 @@ import json
|
|||
import os
|
||||
import sys
|
||||
|
||||
def main(tree, inut_dir):
|
||||
def main(tree):
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
os.unlink(f"{tree}/etc/machine-id")
|
||||
os.unlink(f"{tree}/var/lib/systemd/random-seed")
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
args = json.load(sys.stdin)
|
||||
r = main(args["options"])
|
||||
sys.exit(r)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import subprocess
|
|||
import sys
|
||||
|
||||
|
||||
def main(tree, input_dir, script):
|
||||
def main(tree, options):
|
||||
script = options["script"]
|
||||
|
||||
scriptfile = f"{tree}/osbuild-script"
|
||||
|
||||
with open(scriptfile, "w") as f:
|
||||
|
|
@ -20,5 +22,6 @@ def main(tree, input_dir, script):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
args = json.load(sys.stdin)
|
||||
r = main(args["tree"], args["options"])
|
||||
sys.exit(r)
|
||||
|
|
|
|||
|
|
@ -4,10 +4,13 @@ import json
|
|||
import os
|
||||
import subprocess
|
||||
|
||||
def main(tree, input_dir, enabled_services):
|
||||
def main(tree, options):
|
||||
enabled_services = options["enabled_services"]
|
||||
|
||||
for service in enabled_services:
|
||||
subprocess.run([f"{tree}/usr/bin/systemctl", "--root", tree, "enable", service], check=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
args = json.load(sys.stdin)
|
||||
r = main(args["tree"], args["options"])
|
||||
sys.exit(r)
|
||||
|
|
|
|||
|
|
@ -4,9 +4,12 @@ import json
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
def main(tree, input_dir, filename):
|
||||
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__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
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