osbuild: make state handling generic
Rather than treating the dnf-cache specially, give each stage its own state directory that they can reuse. This should obviously be used with care by the stages in order to make the builds reproducible.
This commit is contained in:
parent
d7cf0ac006
commit
cdcfa1277e
10 changed files with 15 additions and 13 deletions
5
osbuild
5
osbuild
|
|
@ -47,9 +47,14 @@ def main(pipeline_path, from_archive, save):
|
|||
name = stage["name"]
|
||||
options = stage.get("options", {})
|
||||
options["tree"] = os.path.abspath(tree)
|
||||
options["state"] = f"{os.getcwd()}/state/{name}"
|
||||
|
||||
options_str = json.dumps(options, indent=2)
|
||||
|
||||
r = subprocess.run(["mkdir", "-p", f"{os.getcwd()}/state/{name}"])
|
||||
if r.returncode != 0:
|
||||
return
|
||||
|
||||
print()
|
||||
print(f"{RESET}{BOLD}{i}. {name}{RESET} {options_str}")
|
||||
print()
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import os
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
def main(tree, kickstart, skip_package_install=False):
|
||||
def main(tree, state, kickstart, 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"])
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import subprocess
|
|||
import sys
|
||||
|
||||
|
||||
def main(tree, playbook):
|
||||
def main(tree, state, 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")
|
||||
|
||||
|
|
|
|||
|
|
@ -7,15 +7,12 @@ import subprocess
|
|||
import sys
|
||||
|
||||
|
||||
def main(tree, repos, packages, releasever, cache=None):
|
||||
def main(tree, state, repos, packages, releasever):
|
||||
with open("/tmp/dnf.conf", "w") as conf:
|
||||
p = configparser.ConfigParser()
|
||||
p.read_dict(repos)
|
||||
p.write(conf)
|
||||
|
||||
if not cache:
|
||||
cache = f"/tmp/dnf-cache"
|
||||
|
||||
script = f"""
|
||||
set -e
|
||||
mkdir -p {tree}/dev {tree}/sys {tree}/proc
|
||||
|
|
@ -33,7 +30,7 @@ def main(tree, repos, packages, releasever, cache=None):
|
|||
"dnf", "-yv",
|
||||
"--installroot", tree,
|
||||
"--setopt", "reposdir=",
|
||||
"--setopt", f"cachedir={cache}",
|
||||
"--setopt", f"cachedir={state}/dnf-cache",
|
||||
"--setopt", "keepcache=True",
|
||||
"--setopt", "install_weak_deps=False",
|
||||
"--releasever", releasever,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
import json
|
||||
import sys
|
||||
|
||||
def main(tree, language, vc_keymap=None):
|
||||
def main(tree, state, language, vc_keymap=None):
|
||||
with open(f"{tree}/etc/locale.conf", "w") as f:
|
||||
f.write(f'LANG="{language}"\n')
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
import json
|
||||
import sys
|
||||
|
||||
def main(tree, **options):
|
||||
def main(tree, state, **options):
|
||||
print("Not doing anything with these options:", json.dumps(options))
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ def loop_device(image):
|
|||
finally:
|
||||
subprocess.run(["losetup", "-d", loop], check=True)
|
||||
|
||||
def main(tree, target):
|
||||
def main(tree, state, target):
|
||||
size = tree_size(tree)
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=os.getcwd()) as workdir:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import json
|
|||
import os
|
||||
import sys
|
||||
|
||||
def main(tree):
|
||||
def main(tree, state):
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
os.unlink(f"{tree}/etc/machine-id")
|
||||
os.unlink(f"{tree}/var/lib/systemd/random-seed")
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import subprocess
|
|||
import sys
|
||||
|
||||
|
||||
def main(tree, script):
|
||||
def main(tree, state, script):
|
||||
scriptfile = f"{tree}/osbuild-script"
|
||||
|
||||
with open(scriptfile, "w") as f:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import json
|
|||
import os
|
||||
import subprocess
|
||||
|
||||
def main(tree, enabled_services):
|
||||
def main(tree, state, enabled_services):
|
||||
for service in enabled_services:
|
||||
subprocess.run([f"{tree}/usr/bin/systemctl", "--root", tree, "enable", service], check=True)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue