From f45996c192d3abfd6658b0e0ee24643de3de75fd Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 26 Sep 2019 15:38:21 +0200 Subject: [PATCH] Slim down the pre-built DIB IPA images * Move remove-extra-packages to post-install since finalise.d is running on the final image and the DIB documentation recommends avoiding unnecessary actions there. * Remove a few packages that used to be removed only for Fedora; do not try to remove those that aren't on the cloud image. * Do all uninstallations in pre-install phase, so that it doesn't try to remove dependencies of already installed packages. * Exclude more locale files from the image. * Exclude the content of /var/log. Change-Id: Idb7819b1d783f4f5f390cc7621019d3be2fa576f --- .../cleanup.d/99-ramdisk-create | 3 ++ .../environment.d/20-ipa-distro-family.bash | 6 +++ .../finalise.d/99-remove-extra-packages | 31 -------------- .../package-installs.yaml | 41 +++++++++++++++++++ .../80-ironic-python-agent-ramdisk | 4 -- .../post-install.d/99-remove-extra-packages | 19 +++++++++ 6 files changed, 69 insertions(+), 35 deletions(-) create mode 100644 dib/ironic-python-agent-ramdisk/environment.d/20-ipa-distro-family.bash delete mode 100755 dib/ironic-python-agent-ramdisk/finalise.d/99-remove-extra-packages create mode 100755 dib/ironic-python-agent-ramdisk/post-install.d/99-remove-extra-packages diff --git a/dib/ironic-python-agent-ramdisk/cleanup.d/99-ramdisk-create b/dib/ironic-python-agent-ramdisk/cleanup.d/99-ramdisk-create index 03c8363..a868d4d 100755 --- a/dib/ironic-python-agent-ramdisk/cleanup.d/99-ramdisk-create +++ b/dib/ironic-python-agent-ramdisk/cleanup.d/99-ramdisk-create @@ -33,15 +33,18 @@ sudo find . -xdev \ -path './tmp/*' -prune -o \ -path './boot/*' -prune -o \ -path './root/.cache' -prune -o \ + -path "*site-packages/babel/locale-data/*" -prune -o \ -path './usr/include/*' -prune -o \ -path './usr/lib/locale/*' -prune -o \ -path './usr/share/doc/*' -prune -o \ -path './usr/share/man/*' -prune -o \ -path './usr/share/info/*' -prune -o \ -path './usr/share/licenses/*' -prune -o \ + -path './usr/share/locale/*' -prune -o \ -path './usr/share/misc/m*' -prune -o \ -path './usr/src/kernels/*' -prune -o \ -path './var/cache/*' -prune -o \ + -path './var/log/*' -prune -o \ -name '*.pyc' -prune -o \ -name '*.pyo' -prune -o \ -print | sudo cpio -o -H newc | ${DIB_IPA_COMPRESS_CMD} > ${IMAGE_PATH}.initramfs diff --git a/dib/ironic-python-agent-ramdisk/environment.d/20-ipa-distro-family.bash b/dib/ironic-python-agent-ramdisk/environment.d/20-ipa-distro-family.bash new file mode 100644 index 0000000..95a1c15 --- /dev/null +++ b/dib/ironic-python-agent-ramdisk/environment.d/20-ipa-distro-family.bash @@ -0,0 +1,6 @@ +# TODO(dtantsur): verify if opensuse can be added here +if [[ $DISTRO_NAME =~ (fedora|centos|centos7|rhel|rhel7) ]]; then + export IPA_DISTRO_FAMILY=rh +else + export IPA_DISTRO_FAMILY=other +fi diff --git a/dib/ironic-python-agent-ramdisk/finalise.d/99-remove-extra-packages b/dib/ironic-python-agent-ramdisk/finalise.d/99-remove-extra-packages deleted file mode 100755 index 72b4210..0000000 --- a/dib/ironic-python-agent-ramdisk/finalise.d/99-remove-extra-packages +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then - set -x -fi -set -eu -set -o pipefail - -# TODO(lucasagomes): optimize the ramdisk for other OSs -if [ $DISTRO_NAME = 'fedora' ] ; then - - _remove_yum='' - if [ $DIB_RELEASE -ge 22 ]; then - # if we are on F22, we can remove yum if there, because it has - # been superseeded by dnf - _remove_yum='yum' - fi - - install-packages -e kernel-debug-devel gcc fedora-logos \ - rsync pykickstart \ - genisoimage tcpdump \ - man-db kbd-misc \ - plymouth cronie ${_remove_yum} - - ${YUM:-yum} clean all - - # Rebuilding the rpm database after removing packages will reduce - # its size - rpm --rebuilddb - -fi diff --git a/dib/ironic-python-agent-ramdisk/package-installs.yaml b/dib/ironic-python-agent-ramdisk/package-installs.yaml index f63487f..e940a08 100644 --- a/dib/ironic-python-agent-ramdisk/package-installs.yaml +++ b/dib/ironic-python-agent-ramdisk/package-installs.yaml @@ -18,3 +18,44 @@ kmod: psmisc: dosfstools: mdadm: + +# Unnecessary packages to remove. We run all removals in pre-install phase, to +# avoid breaking installs that happen in install phase. + +cloud-init: + phase: pre-install.d + uninstall: true +git: + phase: pre-install.d + uninstall: true +kbd: + phase: pre-install.d + uninstall: true +man-db: + phase: pre-install.d + uninstall: true +rsync: + phase: pre-install.d + uninstall: true + +# Distro-specific uninstalls +cronie: + phase: pre-install.d + uninstall: true + when: IPA_DISTRO_FAMILY = rh +kernel-debug-devel: + phase: pre-install.d + uninstall: true + when: IPA_DISTRO_FAMILY = rh +plymouth: + phase: pre-install.d + uninstall: true + when: IPA_DISTRO_FAMILY = rh +teamd: + phase: pre-install.d + uninstall: true + when: IPA_DISTRO_FAMILY = rh +yum: + phase: pre-install.d + uninstall: true + when: DISTRO_NAME = fedora diff --git a/dib/ironic-python-agent-ramdisk/post-install.d/80-ironic-python-agent-ramdisk b/dib/ironic-python-agent-ramdisk/post-install.d/80-ironic-python-agent-ramdisk index d87cd29..7e51d0a 100755 --- a/dib/ironic-python-agent-ramdisk/post-install.d/80-ironic-python-agent-ramdisk +++ b/dib/ironic-python-agent-ramdisk/post-install.d/80-ironic-python-agent-ramdisk @@ -8,10 +8,6 @@ set -o pipefail DIB_IPA_ENABLE_RESCUE=${DIB_IPA_ENABLE_RESCUE:-true} -install-packages -e cloud-init - -rm -rf /tmp/ironic-python-agent - if $DIB_IPA_ENABLE_RESCUE; then # Make sure rescue works mkdir -p /etc/ipa-rescue-config diff --git a/dib/ironic-python-agent-ramdisk/post-install.d/99-remove-extra-packages b/dib/ironic-python-agent-ramdisk/post-install.d/99-remove-extra-packages new file mode 100755 index 0000000..629b6c0 --- /dev/null +++ b/dib/ironic-python-agent-ramdisk/post-install.d/99-remove-extra-packages @@ -0,0 +1,19 @@ +#!/bin/bash + +if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then + set -x +fi +set -eu +set -o pipefail + +rm -rf /tmp/ironic-python-agent + +# TODO(dtantsur): implement the same for debian-based systems +case "$DISTRO_NAME" in + fedora|centos|centos7|rhel|rhel7) + ${YUM:-yum} clean all + # Rebuilding the rpm database after removing packages will reduce + # its size + rpm --rebuilddb + ;; +esac