stages/dnf: Improve dnf stage reproducibility
Normally, machine ID is generated randomly when dnf installs @Core group. Unfortunately this isn't helping us with reproducibility of images. This commit introduces the concept of fake machine ID. Before dnf command is run in dnf stage, we set the machine ID to a fake one. This ensures all the scriptlets requiring machine ID have predictable outputs. For example GRUB uses machine-id in file names inside /boot/loader/entries. With fixed machine ID the file names are always the same and totally predictable.
This commit is contained in:
parent
2ab9ba4e33
commit
cc73fa5d10
1 changed files with 19 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
|
@ -71,6 +72,17 @@ def main(tree, options):
|
|||
mount -o bind /sys {tree}/sys
|
||||
mount -o bind /proc {tree}/proc
|
||||
"""
|
||||
|
||||
machine_id_set_previously = os.path.exists(f"{tree}/etc/machine-id")
|
||||
if not machine_id_set_previously:
|
||||
# create a fake machine ID to improve reproducibility
|
||||
print("creating a fake machine id")
|
||||
script += f"""
|
||||
mkdir -p {tree}/etc
|
||||
echo "ffffffffffffffffffffffffffffffff" > {tree}/etc/machine-id
|
||||
chmod 0444 {tree}/etc/machine-id
|
||||
"""
|
||||
|
||||
try:
|
||||
subprocess.run(["/bin/sh", "-c", script], check=True)
|
||||
except subprocess.CalledProcessError as err:
|
||||
|
|
@ -110,6 +122,13 @@ def main(tree, options):
|
|||
os.rmdir(name, dir_fd=dirfd)
|
||||
os.close(fd)
|
||||
|
||||
# remove temporary machine ID if it was created by us
|
||||
if not machine_id_set_previously:
|
||||
print("deleting the fake machine id")
|
||||
machine_id_file = pathlib.Path(f"{tree}/etc/machine-id")
|
||||
machine_id_file.unlink()
|
||||
machine_id_file.touch()
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue