public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [RFC PATCH] imagetypes_container: Remove unnecessary packages
@ 2023-08-03 12:21 Quirin Gylstorff
  2023-09-21 10:06 ` MOESSBAUER, Felix
  0 siblings, 1 reply; 2+ messages in thread
From: Quirin Gylstorff @ 2023-08-03 12:21 UTC (permalink / raw)
  To: felix.moessbauer, isar-users

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [RFC PATCH] imagetypes_container: Remove unnecessary packages
  2023-08-03 12:21 [RFC PATCH] imagetypes_container: Remove unnecessary packages Quirin Gylstorff
@ 2023-09-21 10:06 ` MOESSBAUER, Felix
  0 siblings, 0 replies; 2+ messages in thread
From: MOESSBAUER, Felix @ 2023-09-21 10:06 UTC (permalink / raw)
  To: Gylstorff, Quirin, isar-users

On Thu, 2023-08-03 at 14:21 +0200, Quirin Gylstorff wrote:
> 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`.

Any news on this? This would be very useful.

Felix

> 
> 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
>  


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-21 10:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-03 12:21 [RFC PATCH] imagetypes_container: Remove unnecessary packages Quirin Gylstorff
2023-09-21 10:06 ` MOESSBAUER, Felix

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox