konflux-ci / rpm-lockfile-prototype

GNU General Public License v3.0
3 stars 10 forks source link

Fix extracting RPMDB from container images #29

Closed lubomir closed 2 months ago

lubomir commented 2 months ago

The original code did extract the database, but did not ensure that it is consumable by local DNF.

If the _dbpath configuration differed between local system and the container image, the dependency resolution would run as if the database was empty with nothing installed.

This patch fixes that by creating a symlink in such case.

jpopelka commented 2 months ago

Now, when I run it in a different project a got a traceback:

[jpopelka@fedora]-[~/git/osci/konflux/rhel-containers/rteval (rhel-10.0-beta =)]
8>>>rpm-lockfile-prototype --debug -f Dockerfile rpms.in.yaml
INFO:root:Running solver for x86_64
INFO:root:$ skopeo --override-arch=amd64 copy docker://registry.stage.redhat.io/ubi10-beta/ubi@sha256:e6fd69ecc415806ee09cf56768d89ba9057d7a54f4a9523c44fc97ff3f4e7edf dir:/tmp/tmpys0ky3vh
Getting image source signatures
Copying blob 4b6bd6ff1598 done   | 
Copying blob 1d911a9113d3 done   | 
Copying config ae1cb4f6ca done   | 
Writing manifest to image destination
INFO:root:Extracting rpmdb from layer 4b6bd6ff15985b2dfc3aee03a9ef8b811bf93dd55d01420e3151bd07268a2ee4
INFO:root:Extracting rpmdb from layer 1d911a9113d3bcf5616f4c5f342bbc1e498db4a09b1a6fb8d592d9e175863b7c
DEBUG:root:Creating rpmdb symlink usr/lib/sysimage/rpm -> None
Traceback (most recent call last):
  File "/home/jpopelka/.local/bin/rpm-lockfile-prototype", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/jpopelka/git/osci/konflux/rpm-lockfile-prototype/rpm_lockfile/__init__.py", line 451, in main
    process_arch(
  File "/home/jpopelka/git/osci/konflux/rpm-lockfile-prototype/rpm_lockfile/__init__.py", line 291, in process_arch
    with rpmdb(arch) as root_dir:
  File "/usr/lib64/python3.12/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/home/jpopelka/git/osci/konflux/rpm-lockfile-prototype/rpm_lockfile/__init__.py", line 254, in worker
    func(root_dir, arch)
  File "/home/jpopelka/git/osci/konflux/rpm-lockfile-prototype/rpm_lockfile/__init__.py", line 270, in <lambda>
    lambda root_dir, arch: setup_rpmdb(root_dir, baseimage, arch)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jpopelka/git/osci/konflux/rpm-lockfile-prototype/rpm_lockfile/__init__.py", line 139, in setup_rpmdb
    os.makedirs(os.path.dirname(os.path.join(cache_dir, RPMDB_PATH)))
  File "<frozen os>", line 225, in makedirs
FileExistsError: [Errno 17] File exists: '/tmp/tmpusp_lois/usr/lib/sysimage'
jpopelka commented 2 months ago

This seems to work in both repos I've tried it in:

diff --git a/rpm_lockfile/__init__.py b/rpm_lockfile/__init__.py
index 4606a57..3af8c6a 100644
--- a/rpm_lockfile/__init__.py
+++ b/rpm_lockfile/__init__.py
@@ -129,7 +129,7 @@ def setup_rpmdb(cache_dir, baseimage, arch):
             # ...and extract them to the destination cache.
             archive.extractall(path=cache_dir, members=to_extract, filter="data")

-        if dbpath != RPMDB_PATH:
+        if dbpath not in (RPMDB_PATH, None):