trim.sh: Remove build-only dependencies with --depclean
authorW. Trevor King <wking@tremily.us>
Thu, 31 Jul 2014 03:15:23 +0000 (20:15 -0700)
committerW. Trevor King <wking@tremily.us>
Thu, 31 Jul 2014 03:15:23 +0000 (20:15 -0700)
Use '--with-bdeps=n' to tell Portage to ignore build-time dependencies
(e.g. an ebuild's DEPEND).  Only the runtime dependencies (an ebuild's
RDEPEND and PDEPEND) are taken into acount when selecting packages
required by @world.  That lets us keep what we need to run the target
application, but remove all the build tooling (including GCC), leaving
a functional, lightweight image.

trim.sh

diff --git a/trim.sh b/trim.sh
index 1091a6983471d28d50079468de4e91b9f306725b..3a68a5454b94ba6a79fcee9512ffdca096b7918a 100755 (executable)
--- a/trim.sh
+++ b/trim.sh
@@ -49,14 +49,12 @@ trim()
        #sys-apps/openrc     (/sbin/rc)
        #sys-apps/net-tools  (/bin/hostname)
        #sys-devel/gettext   (/usr/bin/envsubst)
-       # unmerge GCC to break the GCC <-> libc dependency loop
        docker run -t --name "${CONTAINER}" \
                -v "${PWD}/empty-system.py:/tmp/empty-system.py" \
                "${IMAGE}" /bin/bash -c "
                        /tmp/empty-system.py &&
                        emerge --noreplace app-shells/bash sys-apps/net-tools sys-apps/openrc sys-devel/gettext &&
-                       emerge --unmerge sys-devel/gcc &&
-                       emerge -v --depclean &&
+                       emerge -v --with-bdeps=n --depclean &&
                        rm -rf /usr/portage" ||
                die "failed to create ${CONTAINER}"
        docker export "${CONTAINER}" | docker import - "${IMG}" ||