public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: "MOESSBAUER, Felix" <felix.moessbauer@siemens.com>
To: "Gylstorff, Quirin" <quirin.gylstorff@siemens.com>,
	"isar-users@googlegroups.com" <isar-users@googlegroups.com>
Subject: Re: [RFC PATCH] imagetypes_container: Remove unnecessary packages
Date: Thu, 21 Sep 2023 10:06:56 +0000	[thread overview]
Message-ID: <6923583d12134e47a0243fffe364fadaf0d41d90.camel@siemens.com> (raw)
In-Reply-To: <20230803122147.596713-1-Quirin.Gylstorff@siemens.com>

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
>  


      reply	other threads:[~2023-09-21 10:07 UTC|newest]

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

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=6923583d12134e47a0243fffe364fadaf0d41d90.camel@siemens.com \
    --to=felix.moessbauer@siemens.com \
    --cc=isar-users@googlegroups.com \
    --cc=quirin.gylstorff@siemens.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