[v3] rootfs: clean package log files that are not owned by packages

Message ID 20211007150734.8380-1-venkata.pyla@toshiba-tsip.com
State Accepted, archived
Headers show
Series [v3] rootfs: clean package log files that are not owned by packages | expand

Commit Message

venkata.pyla@toshiba-tsip.com Oct. 7, 2021, 6:07 a.m. UTC
From: venkata pyla <venkata.pyla@toshiba-tsip.com>

/var/log/* files that are created during build stage and not owned
by any package are not neccessary to be present in rootfs image, as
these log files adds additional size to rootfs image, and also it
create problems for reproducible build functionality.

so this ROOTFS feature 'clean-log-files' should help to clean the log
files when it is enalbed, disable it if we need the log files for
debugging purpose.

ROOTFS_FEATURE += clean-log-files

Signed-off-by: venkata pyla <venkata.pyla@toshiba-tsip.com>
---
 meta/classes/image.bbclass  |  2 +-
 meta/classes/rootfs.bbclass | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

Comments

Anton Mikanovich Oct. 14, 2021, 9:54 p.m. UTC | #1
On 7.10.21 18:07, venkata.pyla@toshiba-tsip.com wrote:
> From: venkata pyla <venkata.pyla@toshiba-tsip.com>
>
> /var/log/* files that are created during build stage and not owned
> by any package are not neccessary to be present in rootfs image, as
> these log files adds additional size to rootfs image, and also it
> create problems for reproducible build functionality.
>
> so this ROOTFS feature 'clean-log-files' should help to clean the log
> files when it is enalbed, disable it if we need the log files for
> debugging purpose.
>
> ROOTFS_FEATURE += clean-log-files
>
> Signed-off-by: venkata pyla <venkata.pyla@toshiba-tsip.com>

Applied to next, thanks.

Patch

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index ec93cab..edabca3 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -63,7 +63,7 @@  image_do_mounts() {
 }
 
 ROOTFSDIR = "${IMAGE_ROOTFS}"
-ROOTFS_FEATURES += "clean-package-cache generate-manifest export-dpkg-status"
+ROOTFS_FEATURES += "clean-package-cache generate-manifest export-dpkg-status clean-log-files"
 ROOTFS_PACKAGES += "${IMAGE_PREINSTALL} ${IMAGE_INSTALL}"
 ROOTFS_MANIFEST_DEPLOY_DIR ?= "${DEPLOY_DIR_IMAGE}"
 ROOTFS_DPKGSTATUS_DEPLOY_DIR ?= "${DEPLOY_DIR_IMAGE}"
diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index f9151c5..20ccb00 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -12,6 +12,7 @@  ROOTFS_PACKAGES ?= ""
 # 'clean-package-cache' - delete package cache from rootfs
 # 'generate-manifest' - generate a package manifest of the rootfs into ${ROOTFS_MANIFEST_DEPLOY_DIR}
 # 'export-dpkg-status' - exports /var/lib/dpkg/status file to ${ROOTFS_DPKGSTATUS_DEPLOY_DIR}
+# 'clean-log-files' - delete log files that are not owned by packages
 ROOTFS_FEATURES ?= ""
 
 ROOTFS_APT_ARGS="install --yes -o Debug::pkgProblemResolver=yes"
@@ -213,6 +214,15 @@  rootfs_postprocess_clean_package_cache() {
     sudo rm -rf "${ROOTFSDIR}/var/lib/apt/lists/"*
 }
 
+ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'clean-log-files', 'rootfs_postprocess_clean_log_files', '', d)}"
+rootfs_postprocess_clean_log_files() {
+    # Delete log files that are not owned by packages
+    sudo -E chroot '${ROOTFSDIR}' \
+        /usr/bin/find /var/log/ -type f \
+        -exec sh -c '! dpkg -S {} > /dev/null 2>&1' ';' \
+        -exec rm -f {} ';'
+}
+
 ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'generate-manifest', 'rootfs_generate_manifest', '', d)}"
 rootfs_generate_manifest () {
     mkdir -p ${ROOTFS_MANIFEST_DEPLOY_DIR}