public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Quirin Gylstorff <Quirin.Gylstorff@siemens.com>
To: felix.moessbauer@siemens.com, isar-users@googlegroups.com
Subject: [RFC PATCH] imagetypes_container: Remove unnecessary packages
Date: Thu,  3 Aug 2023 14:21:47 +0200	[thread overview]
Message-ID: <20230803122147.596713-1-Quirin.Gylstorff@siemens.com> (raw)

From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

Remove unnecessary packages from the container image to save disk space.
This remove by default the following packages:
 - init
 - initramfs-tools
 - linux-image-<KERNEL_NAME>
 - systemd
 - systemd-sysv
 - udev

Additional Packages can be removed by adding them to the variable
`CONTAINER_IMAGE_REMOVE_PKGS`.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 meta/classes/imagetypes_container.bbclass | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/meta/classes/imagetypes_container.bbclass b/meta/classes/imagetypes_container.bbclass
index bd751280..6e0db186 100644
--- a/meta/classes/imagetypes_container.bbclass
+++ b/meta/classes/imagetypes_container.bbclass
@@ -11,6 +11,8 @@ USING_CONTAINER = "${@bb.utils.contains_any('IMAGE_BASETYPES', d.getVar('CONTAIN
 
 CONTAINER_IMAGE_NAME ?= "${PN}-${DISTRO}-${DISTRO_ARCH}"
 CONTAINER_IMAGE_TAG ?= "${PV}-${PR}"
+CONTAINER_IMAGE_REMOVE_PKGS ?= ""
+CONTAINER_IMAGE_REMOVE_PKGS += "init systemd-sysv systemd initramfs-tools udev ${KERNEL_IMAGE_PKG}"
 
 python() {
     if not d.getVar('USING_CONTAINER') == '1':
@@ -42,6 +44,21 @@ do_containerize() {
 
     # add root filesystem as the flesh of the skeleton
     sudo cp --reflink=auto -a "${rootfs}"/* "${oci_img_dir}_unpacked/rootfs/"
+
+    # cleanup image
+    if [ -n "${CONTAINER_IMAGE_REMOVE_PKGS}" ]; then
+        RMPKGS=$(sudo -E chroot "${oci_img_dir}_unpacked/rootfs/" \
+            dpkg-query \
+            -f '${Package}\n' \
+            -W ${CONTAINER_IMAGE_REMOVE_PKGS} 2>/dev/null || true)
+    fi
+    bbdebug 1 "Remove packages ${RMPKGS}"
+    if [ -n "${RMPKGS}" ]; then
+        sudo -E chroot "${oci_img_dir}_unpacked/rootfs/" \
+            dpkg --purge --force-depends ${RMPKGS} && \
+            apt-get autoremove
+    fi
+
     # clean-up temporary files
     sudo find "${oci_img_dir}_unpacked/rootfs/tmp" -mindepth 1 -delete
 
-- 
2.40.1


             reply	other threads:[~2023-08-03 12:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03 12:21 Quirin Gylstorff [this message]
2023-09-21 10:06 ` MOESSBAUER, Felix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230803122147.596713-1-Quirin.Gylstorff@siemens.com \
    --to=quirin.gylstorff@siemens.com \
    --cc=felix.moessbauer@siemens.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox