From e727a84565ae2e5e1b361746b120df19a455f226 Mon Sep 17 00:00:00 2001 From: Roel van Hintum Date: Mon, 22 Apr 2024 16:09:55 +0200 Subject: [PATCH 1/5] Move gnu-libiconv since issue is resolved --- 8.1/Dockerfile | 11 +---------- 8.2/Dockerfile | 11 +---------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/8.1/Dockerfile b/8.1/Dockerfile index baf035d..a40cc84 100644 --- a/8.1/Dockerfile +++ b/8.1/Dockerfile @@ -1,10 +1,6 @@ ARG PHP_VERSION ARG PROJECT_TYPE -FROM alpine:3.13 AS iconv-build -RUN apk upgrade --no-cache \ - && apk add --no-cache gnu-libiconv - FROM php:${PHP_VERSION}-${PROJECT_TYPE}-alpine3.18 # setup general options for environment variables @@ -71,6 +67,7 @@ RUN set -ex \ libwebp-tools \ optipng \ pngquant \ + gnu-libiconv \ && docker-php-ext-configure gd \ --with-freetype \ --with-jpeg \ @@ -92,12 +89,6 @@ RUN set -ex \ imagick \ redis -# https://github.com/craftcms/docker/issues/16 -COPY --from=iconv-build /usr/lib/preloadable_libiconv.so /usr/lib/preloadable_libiconv.so - -# https://github.com/docker-library/php/issues/1121 -ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so - # MozJPEG WORKDIR /tmp ADD https://github.com/mozilla/mozjpeg/archive/v${MOZJPEG_VERSION}.tar.gz ./ diff --git a/8.2/Dockerfile b/8.2/Dockerfile index baf035d..a40cc84 100644 --- a/8.2/Dockerfile +++ b/8.2/Dockerfile @@ -1,10 +1,6 @@ ARG PHP_VERSION ARG PROJECT_TYPE -FROM alpine:3.13 AS iconv-build -RUN apk upgrade --no-cache \ - && apk add --no-cache gnu-libiconv - FROM php:${PHP_VERSION}-${PROJECT_TYPE}-alpine3.18 # setup general options for environment variables @@ -71,6 +67,7 @@ RUN set -ex \ libwebp-tools \ optipng \ pngquant \ + gnu-libiconv \ && docker-php-ext-configure gd \ --with-freetype \ --with-jpeg \ @@ -92,12 +89,6 @@ RUN set -ex \ imagick \ redis -# https://github.com/craftcms/docker/issues/16 -COPY --from=iconv-build /usr/lib/preloadable_libiconv.so /usr/lib/preloadable_libiconv.so - -# https://github.com/docker-library/php/issues/1121 -ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so - # MozJPEG WORKDIR /tmp ADD https://github.com/mozilla/mozjpeg/archive/v${MOZJPEG_VERSION}.tar.gz ./ From cb5ffd76f1c35752253f94d352c96cb886c31b59 Mon Sep 17 00:00:00 2001 From: Roel van Hintum Date: Mon, 22 Apr 2024 16:13:39 +0200 Subject: [PATCH 2/5] Move mozjpeg install to a separate stage --- 8.1/Dockerfile | 49 +++++++++++++++++++++++++------------------------ 8.2/Dockerfile | 49 +++++++++++++++++++++++++------------------------ 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/8.1/Dockerfile b/8.1/Dockerfile index a40cc84..f228b29 100644 --- a/8.1/Dockerfile +++ b/8.1/Dockerfile @@ -1,6 +1,27 @@ ARG PHP_VERSION ARG PROJECT_TYPE +FROM alpine:3.19 AS mozjpeg-build +ENV MOZJPEG_VERSION="3.3.1" + +ADD https://github.com/mozilla/mozjpeg/archive/v${MOZJPEG_VERSION}.tar.gz ./ +RUN set -ex \ + && apk upgrade --no-cache \ + && apk add --no-cache --virtual .build-deps \ + autoconf \ + automake \ + build-base \ + libtool \ + nasm \ + pkgconf \ + tar \ + && tar -xzf v${MOZJPEG_VERSION}.tar.gz \ + && cd ./mozjpeg-${MOZJPEG_VERSION} \ + && autoreconf -fiv \ + && ./configure --with-jpeg8 \ + && make \ + && make install + FROM php:${PHP_VERSION}-${PROJECT_TYPE}-alpine3.18 # setup general options for environment variables @@ -33,22 +54,10 @@ ENV PHP_OPCACHE_MAX_WASTED_PERCENTAGE=$PHP_OPCACHE_MAX_WASTED_PERCENTAGE_ARG ENV PHP_OPCACHE_INTERNED_STRINGS_BUFFER=$PHP_OPCACHE_INTERNED_STRINGS_BUFFER_ARG ENV PHP_OPCACHE_FAST_SHUTDOWN=$PHP_OPCACHE_FAST_SHUTDOWN_ARG -# MozJPEG -ENV MOZJPEG_VERSION="3.3.1" -ENV MOZJPEG_BUILD_DEPS \ - autoconf \ - automake \ - build-base \ - libtool \ - nasm \ - pkgconf \ - tar - RUN set -ex \ && apk upgrade --no-cache \ && apk add --no-cache --virtual .build-deps \ $PHPIZE_DEPS \ - $MOZJPEG_BUILD_DEPS \ freetype-dev \ icu-dev \ icu-data-full \ @@ -90,18 +99,10 @@ RUN set -ex \ redis # MozJPEG -WORKDIR /tmp -ADD https://github.com/mozilla/mozjpeg/archive/v${MOZJPEG_VERSION}.tar.gz ./ -RUN set -ex \ - && tar -xzf v${MOZJPEG_VERSION}.tar.gz \ - && cd ./mozjpeg-${MOZJPEG_VERSION} \ - && autoreconf -fiv \ - && ./configure --with-jpeg8 \ - && make \ - && make install - -RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran -RUN ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg +COPY --from=mozjpeg-build /opt/mozjpeg/bin/jpegtran /opt/mozjpeg/bin/jpegtran +COPY --from=mozjpeg-build /opt/mozjpeg/bin/cjpeg /opt/mozjpeg/bin/cjpeg +RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran \ + && ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg # Cleanup RUN RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \ diff --git a/8.2/Dockerfile b/8.2/Dockerfile index a40cc84..f228b29 100644 --- a/8.2/Dockerfile +++ b/8.2/Dockerfile @@ -1,6 +1,27 @@ ARG PHP_VERSION ARG PROJECT_TYPE +FROM alpine:3.19 AS mozjpeg-build +ENV MOZJPEG_VERSION="3.3.1" + +ADD https://github.com/mozilla/mozjpeg/archive/v${MOZJPEG_VERSION}.tar.gz ./ +RUN set -ex \ + && apk upgrade --no-cache \ + && apk add --no-cache --virtual .build-deps \ + autoconf \ + automake \ + build-base \ + libtool \ + nasm \ + pkgconf \ + tar \ + && tar -xzf v${MOZJPEG_VERSION}.tar.gz \ + && cd ./mozjpeg-${MOZJPEG_VERSION} \ + && autoreconf -fiv \ + && ./configure --with-jpeg8 \ + && make \ + && make install + FROM php:${PHP_VERSION}-${PROJECT_TYPE}-alpine3.18 # setup general options for environment variables @@ -33,22 +54,10 @@ ENV PHP_OPCACHE_MAX_WASTED_PERCENTAGE=$PHP_OPCACHE_MAX_WASTED_PERCENTAGE_ARG ENV PHP_OPCACHE_INTERNED_STRINGS_BUFFER=$PHP_OPCACHE_INTERNED_STRINGS_BUFFER_ARG ENV PHP_OPCACHE_FAST_SHUTDOWN=$PHP_OPCACHE_FAST_SHUTDOWN_ARG -# MozJPEG -ENV MOZJPEG_VERSION="3.3.1" -ENV MOZJPEG_BUILD_DEPS \ - autoconf \ - automake \ - build-base \ - libtool \ - nasm \ - pkgconf \ - tar - RUN set -ex \ && apk upgrade --no-cache \ && apk add --no-cache --virtual .build-deps \ $PHPIZE_DEPS \ - $MOZJPEG_BUILD_DEPS \ freetype-dev \ icu-dev \ icu-data-full \ @@ -90,18 +99,10 @@ RUN set -ex \ redis # MozJPEG -WORKDIR /tmp -ADD https://github.com/mozilla/mozjpeg/archive/v${MOZJPEG_VERSION}.tar.gz ./ -RUN set -ex \ - && tar -xzf v${MOZJPEG_VERSION}.tar.gz \ - && cd ./mozjpeg-${MOZJPEG_VERSION} \ - && autoreconf -fiv \ - && ./configure --with-jpeg8 \ - && make \ - && make install - -RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran -RUN ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg +COPY --from=mozjpeg-build /opt/mozjpeg/bin/jpegtran /opt/mozjpeg/bin/jpegtran +COPY --from=mozjpeg-build /opt/mozjpeg/bin/cjpeg /opt/mozjpeg/bin/cjpeg +RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran \ + && ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg # Cleanup RUN RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \ From d0947be4e6f6839b0e8a1ac83e7d71d9d7cf6bd8 Mon Sep 17 00:00:00 2001 From: Roel van Hintum Date: Mon, 22 Apr 2024 16:17:23 +0200 Subject: [PATCH 3/5] Less RUN commands, less layers --- nginx/Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 759633f..37bc24d 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -12,11 +12,11 @@ COPY craftcms/general.conf /etc/nginx/craftcms/ COPY craftcms/php_fastcgi.conf /etc/nginx/craftcms/ COPY craftcms/security.conf /etc/nginx/craftcms/ COPY ${NGINX_CONF} /etc/nginx/conf.d/default.conf -RUN touch /run/nginx.pid -RUN touch /run/supervisord.pid -RUN chown www-data /run/nginx.pid -RUN chown www-data /run/supervisord.pid -RUN chown -R www-data:www-data /var/lib/nginx/ +RUN touch /run/nginx.pid \ + && touch /run/supervisord.pid \ + && chown www-data /run/nginx.pid \ + && chown www-data /run/supervisord.pid \ + && chown -R www-data:www-data /var/lib/nginx/ USER www-data EXPOSE 8080 From 1908d79a0df9b6034f3ebda8dc7668b4fe8fdbf1 Mon Sep 17 00:00:00 2001 From: Roel van Hintum Date: Mon, 22 Apr 2024 16:22:22 +0200 Subject: [PATCH 4/5] Move cleanup to initial RUN command --- 8.1/Dockerfile | 20 +++++++++----------- 8.2/Dockerfile | 20 +++++++++----------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/8.1/Dockerfile b/8.1/Dockerfile index f228b29..e8a6593 100644 --- a/8.1/Dockerfile +++ b/8.1/Dockerfile @@ -1,7 +1,7 @@ ARG PHP_VERSION ARG PROJECT_TYPE -FROM alpine:3.19 AS mozjpeg-build +FROM alpine:3.18 AS mozjpeg-build ENV MOZJPEG_VERSION="3.3.1" ADD https://github.com/mozilla/mozjpeg/archive/v${MOZJPEG_VERSION}.tar.gz ./ @@ -96,16 +96,8 @@ RUN set -ex \ redis \ && docker-php-ext-enable \ imagick \ - redis - -# MozJPEG -COPY --from=mozjpeg-build /opt/mozjpeg/bin/jpegtran /opt/mozjpeg/bin/jpegtran -COPY --from=mozjpeg-build /opt/mozjpeg/bin/cjpeg /opt/mozjpeg/bin/cjpeg -RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran \ - && ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg - -# Cleanup -RUN RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \ + redis \ + && RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \ | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ | sort -u \ | xargs -r apk info --installed \ @@ -114,6 +106,12 @@ RUN RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \ && apk del --no-network .build-deps \ && rm -rf /tmp/* +# MozJPEG +COPY --from=mozjpeg-build /opt/mozjpeg/bin/jpegtran /opt/mozjpeg/bin/jpegtran +COPY --from=mozjpeg-build /opt/mozjpeg/bin/cjpeg /opt/mozjpeg/bin/cjpeg +RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran \ + && ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg + # copy custom.ini settings COPY craft-cms.ini /usr/local/etc/php/conf.d/ diff --git a/8.2/Dockerfile b/8.2/Dockerfile index f228b29..e8a6593 100644 --- a/8.2/Dockerfile +++ b/8.2/Dockerfile @@ -1,7 +1,7 @@ ARG PHP_VERSION ARG PROJECT_TYPE -FROM alpine:3.19 AS mozjpeg-build +FROM alpine:3.18 AS mozjpeg-build ENV MOZJPEG_VERSION="3.3.1" ADD https://github.com/mozilla/mozjpeg/archive/v${MOZJPEG_VERSION}.tar.gz ./ @@ -96,16 +96,8 @@ RUN set -ex \ redis \ && docker-php-ext-enable \ imagick \ - redis - -# MozJPEG -COPY --from=mozjpeg-build /opt/mozjpeg/bin/jpegtran /opt/mozjpeg/bin/jpegtran -COPY --from=mozjpeg-build /opt/mozjpeg/bin/cjpeg /opt/mozjpeg/bin/cjpeg -RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran \ - && ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg - -# Cleanup -RUN RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \ + redis \ + && RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \ | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ | sort -u \ | xargs -r apk info --installed \ @@ -114,6 +106,12 @@ RUN RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \ && apk del --no-network .build-deps \ && rm -rf /tmp/* +# MozJPEG +COPY --from=mozjpeg-build /opt/mozjpeg/bin/jpegtran /opt/mozjpeg/bin/jpegtran +COPY --from=mozjpeg-build /opt/mozjpeg/bin/cjpeg /opt/mozjpeg/bin/cjpeg +RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran \ + && ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg + # copy custom.ini settings COPY craft-cms.ini /usr/local/etc/php/conf.d/ From 231043847e0dcb4c19dffc0dd2a25299315a2015 Mon Sep 17 00:00:00 2001 From: Roel van Hintum Date: Tue, 23 Apr 2024 14:40:59 +0200 Subject: [PATCH 5/5] follow symlinks on chown --- nginx/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 37bc24d..9d7a84a 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -16,7 +16,7 @@ RUN touch /run/nginx.pid \ && touch /run/supervisord.pid \ && chown www-data /run/nginx.pid \ && chown www-data /run/supervisord.pid \ - && chown -R www-data:www-data /var/lib/nginx/ + && chown -RL www-data:www-data /var/lib/nginx/ USER www-data EXPOSE 8080