From 1c076e4663109e0cc5ad585ff88e5f13db46ebf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Horv=C3=A1t?= Date: Fri, 25 Apr 2025 16:55:23 +0200 Subject: [PATCH 1/2] Dockerfile: Removed container size by removing dnf history --- almalinux/Dockerfile | 45 +++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/almalinux/Dockerfile b/almalinux/Dockerfile index 17444b1..4f30d88 100644 --- a/almalinux/Dockerfile +++ b/almalinux/Dockerfile @@ -9,7 +9,10 @@ # ARG LINUX_VERSION=9.3 ARG BUILDPLATFORM=linux/amd64 -FROM --platform=$BUILDPLATFORM almalinux:${LINUX_VERSION} +FROM --platform=$BUILDPLATFORM almalinux:${LINUX_VERSION} AS packages + +RUN echo "tsflags=nodocs" >> /etc/dnf/dnf.conf && \ + echo "clean_requirements_on_remove=true" >> /etc/dnf/dnf.conf RUN dnf upgrade --refresh -y && \ dnf install -y \ @@ -20,12 +23,6 @@ RUN dnf upgrade --refresh -y && \ glibc-langpack-en \ gcc -RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 - -ENV LANG=en_US.UTF-8 -ENV LANGUAGE=en_US:en -ENV LC_ALL=en_US.UTF-8 - # EPEL: Extra Packages for Enterprise Linux 9 # `epel-release` is not recent/complete enough, as some packages below are missing RUN dnf config-manager --set-enabled crb && \ @@ -60,23 +57,33 @@ RUN dnf install -y \ iotop iftop \ tcpdump bind-utils -# Symlink Python -RUN ln -sfn /usr/bin/python3 /usr/bin/python -# `python3-packaging` is installed by `yum` and it causes issues with `pip` installations -RUN yum remove python3-packaging -y -RUN pip3 install --upgrade pip pipenv wheel +# `python3-packaging` is installed by `dnf` and it causes issues with `pip` installations +RUN dnf remove python3-packaging -y # Install Node.js RUN curl -fsSL https://rpm.nodesource.com/setup_22.x | bash - && \ dnf -y install nodejs -# Reduce image size: clean up caches, remove RPM db files -RUN dnf clean all && \ - rm -rf \ - /var/cache/dnf \ - /var/lib/rpm/__db* \ - /var/lib/rpm/rpmdb.sqlite \ - /var/lib/rpm/Packages +# Remove unrequired packages +RUN dnf autoremove -y + +FROM --platform=$BUILDPLATFORM almalinux:${LINUX_VERSION} + +ENV LANG=en_US.UTF-8 +ENV LANGUAGE=en_US:en +ENV LC_ALL=en_US.UTF-8 + +# Copy binaries from base image avoiding large dnf cache history +COPY --from=packages /usr/ /usr/ +COPY --from=packages /etc/ /etc/ +# Without the RPM database new packages cannot be installed +COPY --from=packages /var/lib/rpm/rpmdb.sqlite /var/lib/rpm/rpmdb.sqlite + +RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 + +# Symlink Python +RUN ln -sfn /usr/bin/python3 /usr/bin/python +RUN pip3 install --no-cache-dir --upgrade pip pipenv wheel # Create working directory ENV WORKING_DIR=/opt/invenio From baebfe5cc5f331254a4178e081845bede4ca50df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Horv=C3=A1t?= Date: Tue, 29 Apr 2025 10:54:30 +0200 Subject: [PATCH 2/2] Dockerfile: Use latest 9.5-minimal image instead of 9.3 --- almalinux/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/almalinux/Dockerfile b/almalinux/Dockerfile index 4f30d88..b098d56 100644 --- a/almalinux/Dockerfile +++ b/almalinux/Dockerfile @@ -7,10 +7,13 @@ # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. # -ARG LINUX_VERSION=9.3 +ARG LINUX_VERSION=9.5-minimal ARG BUILDPLATFORM=linux/amd64 FROM --platform=$BUILDPLATFORM almalinux:${LINUX_VERSION} AS packages +RUN microdnf upgrade --refresh -y && \ + microdnf install -y dnf + RUN echo "tsflags=nodocs" >> /etc/dnf/dnf.conf && \ echo "clean_requirements_on_remove=true" >> /etc/dnf/dnf.conf