From 28c6a561b78dacdc6dc9e00240ea4aa7043e4b52 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Oct 25 2023 22:23:42 +0000 Subject: Preserve hard links when building Docker images https://github.com/redhat-imaging/imagefactory/issues/412 https://bugzilla.redhat.com/show_bug.cgi?id=2245066 https://github.com/redhat-imaging/imagefactory/pull/455 --- diff --git a/imagefactory-Docker.py-Pass-the-use_ino-option-to-fix-hardlnks.patch b/imagefactory-Docker.py-Pass-the-use_ino-option-to-fix-hardlnks.patch new file mode 100644 index 0000000..5d6c9f3 --- /dev/null +++ b/imagefactory-Docker.py-Pass-the-use_ino-option-to-fix-hardlnks.patch @@ -0,0 +1,59 @@ +From f641455c06f18da52bf7fd9c5228d6e3c5ce1453 Mon Sep 17 00:00:00 2001 +From: "Owen W. Taylor" +Date: Fri, 20 Oct 2023 11:26:17 -0400 +Subject: [PATCH] Docker.py: Pass the use_ino option to fix hardlnks + +When use libguestfs to mount the intermediate image to create a tarball, +pass the "use_ino" option so that original inode numbers are preserved. +This fixes a problem where hardlinks were not properly preserved in the +output. + +This is a minimal-code-change fix - an edge case bug and better approach are +described in comments. + +Resolves #412 +--- + imagefactory_plugins/Docker/Docker.py | 22 +++++++++++++++++++++- + 1 file changed, 21 insertions(+), 1 deletion(-) + +diff --git a/imagefactory_plugins/Docker/Docker.py b/imagefactory_plugins/Docker/Docker.py +index 68e12c3926bb..960b0e43325c 100644 +--- a/imagefactory_plugins/Docker/Docker.py ++++ b/imagefactory_plugins/Docker/Docker.py +@@ -312,12 +312,32 @@ class Docker(object): + # we call a blocking function to activate the mount, which requires a thread + # We also need a temp dir to mount it to - do our best to clean up when things + # go wrong ++ # ++ # A better approach here would be to use: ++ # g.tar_out_opts("/", dest_filename, excludes=[excludes]) ++ # Though that would break compatibility with the tar_options parameter. ++ # + tempdir = None + fuse_thread = None + try: + tempdir = tempfile.mkdtemp(dir=storagedir) + self.log.debug("Mounting input image locally at (%s)" % (tempdir)) +- guestfs_handle.mount_local(tempdir) ++ ++ # The "use_ino" option causes FUSE to pass through the original inode ++ # numbers. Without it tar cannot properly detect hardlinks, possibly greatly ++ # increasing the size of the image. This does create an edge case. If there ++ # are: ++ # ++ # - Two separate groups of > 1 files hardlinked together ++ # - On different partitions ++ # - With the same inode number ++ # ++ # Then the groups will be incorrectly merged in the output image. This ++ # is unlikely to be encountered with typical container images, where almost ++ # all files are on a single partition. The correct fix is to use ++ # g.tar_out_opts() as described above. ++ ++ guestfs_handle.mount_local(tempdir, options="use_ino") + def _run_guestmount(g): + g.mount_local_run() + self.log.debug("Launching mount_local_run thread") +-- +2.41.0 + diff --git a/imagefactory.spec b/imagefactory.spec index 4935487..1e3b72d 100644 --- a/imagefactory.spec +++ b/imagefactory.spec @@ -1,6 +1,6 @@ Name: imagefactory Version: 1.1.16 -Release: 6%{?dist} +Release: 7%{?dist} Summary: System image generation tool License: ASL 2.0 URL: https://github.com/redhat-imaging/imagefactory @@ -11,6 +11,10 @@ Patch0: imagefactory-1.1.14-utf8-config-id.patch Patch1: container-github-pr434.patch # https://github.com/redhat-imaging/imagefactory/pull/438 Patch2: 0001-ApplicationConfiguration.py-drop-encoding-from-json..patch +# https://github.com/redhat-imaging/imagefactory/issues/412 +# https://bugzilla.redhat.com/show_bug.cgi?id=2245066 +# https://github.com/redhat-imaging/imagefactory/pull/455 +Patch3: imagefactory-Docker.py-Pass-the-use_ino-option-to-fix-hardlnks.patch BuildArch: noarch BuildRequires: python3 @@ -93,6 +97,9 @@ rm -f %{buildroot}/%{_initddir}/imagefactoryd %{_bindir}/imagefactoryd %changelog +* Thu Oct 26 2023 Debarshi Ray - 1.1.16-7 +- Preserve hard links when building Docker images + * Thu Jul 20 2023 Fedora Release Engineering - 1.1.16-6 - Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild