runners: create fake machine id when needed
Create fake machine before executing the runner command to avoid the "Failed to resolve specifiers in '/var/log/journal/%m'" errors.
This commit is contained in:
parent
b3c6366135
commit
99af178c6d
7 changed files with 100 additions and 97 deletions
|
|
@ -1,8 +1,10 @@
|
||||||
import os.path
|
import os.path
|
||||||
|
import pathlib
|
||||||
import platform
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
|
||||||
def ldconfig(*dirs):
|
def ldconfig(*dirs):
|
||||||
|
|
@ -31,6 +33,29 @@ def sysusers():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def create_machine_id_if_needed(tree="", keep_empty=False):
|
||||||
|
"""Create a machine-id with a fake machine id if it does not exist.
|
||||||
|
The machine-id file will be delete at context exit unless specified
|
||||||
|
with 'keep_empty' variable. In that case an empty machine-id will
|
||||||
|
be kept.
|
||||||
|
"""
|
||||||
|
path = pathlib.Path(f"{tree}/etc/machine-id")
|
||||||
|
try:
|
||||||
|
if not path.exists():
|
||||||
|
path.parent.mkdir(mode=0o755, exist_ok=True)
|
||||||
|
with path.open(mode="w", encoding="utf8") as f:
|
||||||
|
# create a fake machine ID to improve reproducibility
|
||||||
|
f.write("ffffffffffffffffffffffffffffffff\n")
|
||||||
|
path.chmod(0o444)
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
path.unlink()
|
||||||
|
if keep_empty:
|
||||||
|
path.touch()
|
||||||
|
path.chmod(0o444)
|
||||||
|
|
||||||
|
|
||||||
def tmpfiles():
|
def tmpfiles():
|
||||||
# Allow systemd-tmpfiles to return non-0. Some packages want to create
|
# Allow systemd-tmpfiles to return non-0. Some packages want to create
|
||||||
# directories owned by users that are not set up with systemd-sysusers.
|
# directories owned by users that are not set up with systemd-sysusers.
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ if __name__ == "__main__":
|
||||||
with api.exception_handler():
|
with api.exception_handler():
|
||||||
runners.ldconfig()
|
runners.ldconfig()
|
||||||
runners.sysusers()
|
runners.sysusers()
|
||||||
|
with runners.create_machine_id_if_needed():
|
||||||
runners.tmpfiles()
|
runners.tmpfiles()
|
||||||
runners.nsswitch()
|
runners.nsswitch()
|
||||||
|
|
||||||
r = subprocess.run(sys.argv[1:], check=False)
|
r = subprocess.run(sys.argv[1:], check=False)
|
||||||
|
|
||||||
sys.exit(r.returncode)
|
sys.exit(r.returncode)
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ if __name__ == "__main__":
|
||||||
with api.exception_handler():
|
with api.exception_handler():
|
||||||
runners.ldconfig()
|
runners.ldconfig()
|
||||||
runners.sysusers()
|
runners.sysusers()
|
||||||
|
with runners.create_machine_id_if_needed():
|
||||||
runners.tmpfiles()
|
runners.tmpfiles()
|
||||||
runners.nsswitch()
|
runners.nsswitch()
|
||||||
|
|
||||||
r = subprocess.run(sys.argv[1:], check=False)
|
r = subprocess.run(sys.argv[1:], check=False)
|
||||||
|
|
||||||
sys.exit(r.returncode)
|
sys.exit(r.returncode)
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,10 @@ if __name__ == "__main__":
|
||||||
with api.exception_handler():
|
with api.exception_handler():
|
||||||
runners.ldconfig()
|
runners.ldconfig()
|
||||||
runners.sysusers()
|
runners.sysusers()
|
||||||
|
with runners.create_machine_id_if_needed():
|
||||||
runners.tmpfiles()
|
runners.tmpfiles()
|
||||||
runners.nsswitch()
|
runners.nsswitch()
|
||||||
runners.sequoia()
|
runners.sequoia()
|
||||||
|
|
||||||
r = subprocess.run(sys.argv[1:], check=False)
|
r = subprocess.run(sys.argv[1:], check=False)
|
||||||
|
|
||||||
sys.exit(r.returncode)
|
sys.exit(r.returncode)
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,11 @@ if __name__ == "__main__":
|
||||||
with api.exception_handler():
|
with api.exception_handler():
|
||||||
runners.ldconfig()
|
runners.ldconfig()
|
||||||
runners.sysusers()
|
runners.sysusers()
|
||||||
|
with runners.create_machine_id_if_needed():
|
||||||
runners.tmpfiles()
|
runners.tmpfiles()
|
||||||
runners.nsswitch()
|
runners.nsswitch()
|
||||||
os_release()
|
os_release()
|
||||||
runners.python_alternatives()
|
runners.python_alternatives()
|
||||||
|
|
||||||
r = subprocess.run(sys.argv[1:], check=False)
|
r = subprocess.run(sys.argv[1:], check=False)
|
||||||
|
|
||||||
sys.exit(r.returncode)
|
sys.exit(r.returncode)
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,11 @@ if __name__ == "__main__":
|
||||||
with api.exception_handler():
|
with api.exception_handler():
|
||||||
runners.ldconfig()
|
runners.ldconfig()
|
||||||
runners.sysusers()
|
runners.sysusers()
|
||||||
|
with runners.create_machine_id_if_needed():
|
||||||
runners.tmpfiles()
|
runners.tmpfiles()
|
||||||
runners.nsswitch()
|
runners.nsswitch()
|
||||||
runners.python_alternatives()
|
runners.python_alternatives()
|
||||||
|
|
||||||
env = runners.quirks()
|
env = runners.quirks()
|
||||||
|
|
||||||
r = subprocess.run(sys.argv[1:], env=env, check=False)
|
r = subprocess.run(sys.argv[1:], env=env, check=False)
|
||||||
|
|
||||||
sys.exit(r.returncode)
|
sys.exit(r.returncode)
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ This stage will return the following metadata via the osbuild API:
|
||||||
import contextlib
|
import contextlib
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pathlib
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
@ -43,6 +42,7 @@ from operator import itemgetter
|
||||||
|
|
||||||
from osbuild import api
|
from osbuild import api
|
||||||
from osbuild.util.mnt import mount
|
from osbuild.util.mnt import mount
|
||||||
|
from osbuild.util.runners import create_machine_id_if_needed
|
||||||
|
|
||||||
SCHEMA = """
|
SCHEMA = """
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
@ -263,21 +263,6 @@ def parse_input(inputs):
|
||||||
return path, files
|
return path, files
|
||||||
|
|
||||||
|
|
||||||
def create_machine_id_if_needed(tree):
|
|
||||||
"""Create a machine-id with a fake machine id if it does not exist"""
|
|
||||||
path = f"{tree}/etc/machine-id"
|
|
||||||
if os.path.exists(path):
|
|
||||||
return False
|
|
||||||
|
|
||||||
os.makedirs(f"{tree}/etc", exist_ok=True)
|
|
||||||
with open(path, "w", encoding="utf8") as f:
|
|
||||||
# create a fake machine ID to improve reproducibility
|
|
||||||
f.write("ffffffffffffffffffffffffffffffff\n")
|
|
||||||
os.fchmod(f.fileno(), 0o400)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
def main(tree, inputs, options):
|
def main(tree, inputs, options):
|
||||||
pkgpath, packages = parse_input(inputs)
|
pkgpath, packages = parse_input(inputs)
|
||||||
|
|
@ -322,8 +307,7 @@ def main(tree, inputs, options):
|
||||||
|
|
||||||
os.symlink("/proc/self/fd", f"{tree}/dev/fd")
|
os.symlink("/proc/self/fd", f"{tree}/dev/fd")
|
||||||
|
|
||||||
machine_id_created = create_machine_id_if_needed(tree)
|
with create_machine_id_if_needed(tree, keep_empty=True):
|
||||||
|
|
||||||
ostree_booted = None
|
ostree_booted = None
|
||||||
if options.get("ostree_booted", False):
|
if options.get("ostree_booted", False):
|
||||||
os.makedirs(f"{tree}/run", exist_ok=True)
|
os.makedirs(f"{tree}/run", exist_ok=True)
|
||||||
|
|
@ -379,13 +363,6 @@ def main(tree, inputs, options):
|
||||||
enable_dracut(masked_files)
|
enable_dracut(masked_files)
|
||||||
remove_unowned_etc_kernel(tree, rpm_args)
|
remove_unowned_etc_kernel(tree, rpm_args)
|
||||||
|
|
||||||
# remove temporary machine ID if it was created by us
|
|
||||||
if machine_id_created:
|
|
||||||
print("deleting the fake machine id")
|
|
||||||
machine_id_file = pathlib.Path(f"{tree}/etc/machine-id")
|
|
||||||
machine_id_file.unlink()
|
|
||||||
machine_id_file.touch(mode=0o444)
|
|
||||||
|
|
||||||
if ostree_booted:
|
if ostree_booted:
|
||||||
os.unlink(ostree_booted)
|
os.unlink(ostree_booted)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue