From 9ef70b29698b768768fab79d0ba2a18cf4f6c57c Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 25 May 2024 11:38:14 -0500 Subject: [PATCH] Avoid clobbering RPMDB in final container Installing the RPMs in an alternate root and then copying the contents of that root to the final container rootfs overwrites the RPM database in the latter with the one from the former. This isn't necessarily a problem per se, but it makes troubleshooting difficult. To avoid this, we can install the RPMs directly in the final filesystem, which mutates the RPMDB without overwriting it. --- Containerfile | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Containerfile b/Containerfile index 02be00a..ecf6ab8 100644 --- a/Containerfile +++ b/Containerfile @@ -9,7 +9,7 @@ RUN --mount=type=cache,target=/var/cache \ RUN --mount=type=cache,target=/var/cache \ dnf install -y \ --downloadonly \ - --downloaddir=/var/cache/rpms \ + --downloaddir=/rpms \ --setopt=install_weak_deps=0 \ collectd \ collectd-chrony \ @@ -19,21 +19,22 @@ RUN --mount=type=cache,target=/var/cache \ collectd-write_prometheus \ && : -RUN --mount=type=cache,target=/var/cache \ - rpm -ivh -f --nodeps --root=/sysroot \ - /var/cache/rpms/collectd*.rpm \ - /var/cache/rpms/lm_sensors-libs-*.rpm \ - /var/cache/rpms/libmicrohttpd-*.rpm \ - /var/cache/rpms/libmnl-*.rpm \ - /var/cache/rpms/protobuf-c-*.rpm \ - && cd /sysroot \ - && rpm2cpio /var/cache/rpms/nut-client-*.rpm \ - | cpio -i './usr/lib*/libupsclient.so.6*' \ - && : - FROM registry.fedoraproject.org/fedora-minimal:40 -COPY --from=build /sysroot / +RUN --mount=type=cache,target=/var/cache \ + --mount=type=bind,from=build,source=/rpms,target=/rpms \ + microdnf install -y \ + --setopt=install_weak_deps=0 \ + cpio \ + && rpm -ivh -f --nodeps \ + /rpms/collectd*.rpm \ + /rpms/lm_sensors-libs-*.rpm \ + /rpms/libmicrohttpd-*.rpm \ + /rpms/libmnl-*.rpm \ + /rpms/protobuf-c-*.rpm \ + && rpm2cpio /rpms/nut-client-*.rpm \ + | cpio -i './usr/lib*/libupsclient.so.6*' \ + && : ENTRYPOINT ["/usr/sbin/collectd", "-f"]