From eb0fba238bda58190035f8970cfbc0f02c52da5a Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sat, 16 Aug 2025 13:49:04 +0200 Subject: [PATCH 1/2] Compress binaries with UPX --- php-82/Dockerfile | 11 +++++++++++ php-83/Dockerfile | 11 +++++++++++ php-84/Dockerfile | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/php-82/Dockerfile b/php-82/Dockerfile index d55207eb..1fb2ec6a 100644 --- a/php-82/Dockerfile +++ b/php-82/Dockerfile @@ -177,6 +177,17 @@ RUN set -xe; \ cp php.ini-production ${INSTALL_DIR}/etc/php/php.ini +# Compress the PHP binary and the PHP-FPM binary with UPX to reduce their size +# --best: use the best compression method +RUN set -xe; \ + export UPX_ARCH=$(test "${IMAGE_VERSION_SUFFIX}" = "x86_64" && echo amd64 || echo arm64); \ + curl -L -o upx.tgz https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-${UPX_ARCH}_linux.tar.xz; \ + tar xf upx.tgz; \ + mv upx-*/upx /usr/local/bin/ +RUN upx --best ${INSTALL_DIR}/bin/php && \ + upx --best ${INSTALL_DIR}/sbin/php-fpm + + # Install extensions # We can install extensions manually or using `pecl` RUN pecl install APCu diff --git a/php-83/Dockerfile b/php-83/Dockerfile index 0f0452d4..2cd72335 100644 --- a/php-83/Dockerfile +++ b/php-83/Dockerfile @@ -177,6 +177,17 @@ RUN set -xe; \ cp php.ini-production ${INSTALL_DIR}/etc/php/php.ini +# Compress the PHP binary and the PHP-FPM binary with UPX to reduce their size +# --best: use the best compression method +RUN set -xe; \ + export UPX_ARCH=$(test "${IMAGE_VERSION_SUFFIX}" = "x86_64" && echo amd64 || echo arm64); \ + curl -L -o upx.tgz https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-${UPX_ARCH}_linux.tar.xz; \ + tar xf upx.tgz; \ + mv upx-*/upx /usr/local/bin/ +RUN upx --best ${INSTALL_DIR}/bin/php && \ + upx --best ${INSTALL_DIR}/sbin/php-fpm + + # Install extensions # We can install extensions manually or using `pecl` RUN pecl install APCu diff --git a/php-84/Dockerfile b/php-84/Dockerfile index 189c96d4..b9822c54 100644 --- a/php-84/Dockerfile +++ b/php-84/Dockerfile @@ -176,6 +176,17 @@ RUN set -xe; \ cp php.ini-production ${INSTALL_DIR}/etc/php/php.ini +# Compress the PHP binary and the PHP-FPM binary with UPX to reduce their size +# --best: use the best compression method +RUN set -xe; \ + export UPX_ARCH=$(test "${IMAGE_VERSION_SUFFIX}" = "x86_64" && echo amd64 || echo arm64); \ + curl -L -o upx.tgz https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-${UPX_ARCH}_linux.tar.xz; \ + tar xf upx.tgz; \ + mv upx-*/upx /usr/local/bin/ +RUN upx --best ${INSTALL_DIR}/bin/php && \ + upx --best ${INSTALL_DIR}/sbin/php-fpm + + # Install extensions # We can install extensions manually or using `pecl` RUN pecl install APCu From 55c81e0d63443a12e68d0816144b7a8e74bdff3f Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sat, 16 Aug 2025 15:35:55 +0200 Subject: [PATCH 2/2] Fix --- php-82/Dockerfile | 22 +++++++++++----------- php-83/Dockerfile | 22 +++++++++++----------- php-84/Dockerfile | 22 +++++++++++----------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/php-82/Dockerfile b/php-82/Dockerfile index 1fb2ec6a..bd252a61 100644 --- a/php-82/Dockerfile +++ b/php-82/Dockerfile @@ -177,17 +177,6 @@ RUN set -xe; \ cp php.ini-production ${INSTALL_DIR}/etc/php/php.ini -# Compress the PHP binary and the PHP-FPM binary with UPX to reduce their size -# --best: use the best compression method -RUN set -xe; \ - export UPX_ARCH=$(test "${IMAGE_VERSION_SUFFIX}" = "x86_64" && echo amd64 || echo arm64); \ - curl -L -o upx.tgz https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-${UPX_ARCH}_linux.tar.xz; \ - tar xf upx.tgz; \ - mv upx-*/upx /usr/local/bin/ -RUN upx --best ${INSTALL_DIR}/bin/php && \ - upx --best ${INSTALL_DIR}/sbin/php-fpm - - # Install extensions # We can install extensions manually or using `pecl` RUN pecl install APCu @@ -230,6 +219,17 @@ RUN find /bref-layer/bref/extensions -type f -exec strip --strip-all {} + RUN find /bref-layer/lib -type f -exec strip --strip-all {} + +# Compress the PHP binary and the PHP-FPM binary with UPX to reduce their size +# --best: use the best compression method +RUN set -xe; \ + export UPX_ARCH=$(test "${IMAGE_VERSION_SUFFIX}" = "x86_64" && echo amd64 || echo arm64); \ + curl -L -o upx.tgz https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-${UPX_ARCH}_linux.tar.xz; \ + tar xf upx.tgz; \ + mv upx-*/upx /usr/local/bin/ +RUN upx --best /bref-layer/bin/php && \ + upx --best /bref-layer/bin/php-fpm + + # ---------------------------------------------------------------------------- # Start from a clean image to copy only the files we need for the Lambda layer FROM public.ecr.aws/lambda/provided:al2023-${IMAGE_VERSION_SUFFIX} as function diff --git a/php-83/Dockerfile b/php-83/Dockerfile index 2cd72335..30b6c1e1 100644 --- a/php-83/Dockerfile +++ b/php-83/Dockerfile @@ -177,17 +177,6 @@ RUN set -xe; \ cp php.ini-production ${INSTALL_DIR}/etc/php/php.ini -# Compress the PHP binary and the PHP-FPM binary with UPX to reduce their size -# --best: use the best compression method -RUN set -xe; \ - export UPX_ARCH=$(test "${IMAGE_VERSION_SUFFIX}" = "x86_64" && echo amd64 || echo arm64); \ - curl -L -o upx.tgz https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-${UPX_ARCH}_linux.tar.xz; \ - tar xf upx.tgz; \ - mv upx-*/upx /usr/local/bin/ -RUN upx --best ${INSTALL_DIR}/bin/php && \ - upx --best ${INSTALL_DIR}/sbin/php-fpm - - # Install extensions # We can install extensions manually or using `pecl` RUN pecl install APCu @@ -230,6 +219,17 @@ RUN find /bref-layer/bref/extensions -type f -exec strip --strip-all {} + RUN find /bref-layer/lib -type f -exec strip --strip-all {} + +# Compress the PHP binary and the PHP-FPM binary with UPX to reduce their size +# --best: use the best compression method +RUN set -xe; \ + export UPX_ARCH=$(test "${IMAGE_VERSION_SUFFIX}" = "x86_64" && echo amd64 || echo arm64); \ + curl -L -o upx.tgz https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-${UPX_ARCH}_linux.tar.xz; \ + tar xf upx.tgz; \ + mv upx-*/upx /usr/local/bin/ +RUN upx --best /bref-layer/bin/php && \ + upx --best /bref-layer/bin/php-fpm + + # ---------------------------------------------------------------------------- # Start from a clean image to copy only the files we need for the Lambda layer FROM public.ecr.aws/lambda/provided:al2023-${IMAGE_VERSION_SUFFIX} as function diff --git a/php-84/Dockerfile b/php-84/Dockerfile index b9822c54..e08d4dc7 100644 --- a/php-84/Dockerfile +++ b/php-84/Dockerfile @@ -176,17 +176,6 @@ RUN set -xe; \ cp php.ini-production ${INSTALL_DIR}/etc/php/php.ini -# Compress the PHP binary and the PHP-FPM binary with UPX to reduce their size -# --best: use the best compression method -RUN set -xe; \ - export UPX_ARCH=$(test "${IMAGE_VERSION_SUFFIX}" = "x86_64" && echo amd64 || echo arm64); \ - curl -L -o upx.tgz https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-${UPX_ARCH}_linux.tar.xz; \ - tar xf upx.tgz; \ - mv upx-*/upx /usr/local/bin/ -RUN upx --best ${INSTALL_DIR}/bin/php && \ - upx --best ${INSTALL_DIR}/sbin/php-fpm - - # Install extensions # We can install extensions manually or using `pecl` RUN pecl install APCu @@ -229,6 +218,17 @@ RUN find /bref-layer/bref/extensions -type f -exec strip --strip-all {} + RUN find /bref-layer/lib -type f -exec strip --strip-all {} + +# Compress the PHP binary and the PHP-FPM binary with UPX to reduce their size +# --best: use the best compression method +RUN set -xe; \ + export UPX_ARCH=$(test "${IMAGE_VERSION_SUFFIX}" = "x86_64" && echo amd64 || echo arm64); \ + curl -L -o upx.tgz https://github.com/upx/upx/releases/download/v5.0.2/upx-5.0.2-${UPX_ARCH}_linux.tar.xz; \ + tar xf upx.tgz; \ + mv upx-*/upx /usr/local/bin/ +RUN upx --best /bref-layer/bin/php && \ + upx --best /bref-layer/bin/php-fpm + + # ---------------------------------------------------------------------------- # Start from a clean image to copy only the files we need for the Lambda layer FROM public.ecr.aws/lambda/provided:al2023-${IMAGE_VERSION_SUFFIX} as function