Remove buildDeps after php extensions have been installed
authorJ0WI <redacted>
Sun, 29 Apr 2018 21:10:45 +0000 (23:10 +0200)
committerJ0WI <redacted>
Sun, 29 Apr 2018 21:10:45 +0000 (23:10 +0200)
php-apache/Dockerfile
php-fpm/Dockerfile

index 29a7ee157c35800279613768e3f95cb1ca757b77..7d1f8f4ef4b2796566ea2261ce57ed23958c7fd3 100644 (file)
@@ -4,6 +4,8 @@ LABEL maintainer="Thomas Bruederli <thomas@roundcube.net>"
 RUN set -ex; \
        apt-get update; \
        \
+       savedAptMark="$(apt-mark showmanual)"; \
+       \
        apt-get install -y --no-install-recommends \
                libfreetype6-dev \
                libicu-dev \
@@ -30,6 +32,18 @@ RUN set -ex; \
                zip \
        ; \
        \
+# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
+       apt-mark auto '.*' > /dev/null; \
+       apt-mark manual $savedAptMark; \
+       ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
+               | awk '/=>/ { print $3 }' \
+               | sort -u \
+               | xargs -r dpkg-query -S \
+               | cut -d: -f1 \
+               | sort -u \
+               | xargs -rt apt-mark manual; \
+       \
+       apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
        rm -rf /var/lib/apt/lists/*
 
 # enable mod_rewrite
index f68cb9e837d54af7074c29c2c83dfb82440e9bdc..dd1a4af646cf002c30b8723596662a26f9d8dc18 100644 (file)
@@ -4,6 +4,8 @@ LABEL maintainer="Thomas Bruederli <thomas@roundcube.net>"
 RUN set -ex; \
        apt-get update; \
        \
+       savedAptMark="$(apt-mark showmanual)"; \
+       \
        apt-get install -y --no-install-recommends \
                libfreetype6-dev \
                libicu-dev \
@@ -30,6 +32,18 @@ RUN set -ex; \
                zip \
        ; \
        \
+# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
+       apt-mark auto '.*' > /dev/null; \
+       apt-mark manual $savedAptMark; \
+       ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
+               | awk '/=>/ { print $3 }' \
+               | sort -u \
+               | xargs -r dpkg-query -S \
+               | cut -d: -f1 \
+               | sort -u \
+               | xargs -rt apt-mark manual; \
+       \
+       apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
        rm -rf /var/lib/apt/lists/*
 
 # expose these volumes
git clone https://git.99rst.org/PROJECT