Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #94 Moving cleanup to dramatically reduce image size #95

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 29 additions & 39 deletions 8.1/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
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 alpine:3.18 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

Expand Down Expand Up @@ -37,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 \
Expand All @@ -71,6 +76,7 @@ RUN set -ex \
libwebp-tools \
optipng \
pngquant \
gnu-libiconv \
&& docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
Expand All @@ -90,30 +96,8 @@ RUN set -ex \
redis \
&& docker-php-ext-enable \
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 ./
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

# 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 \
Expand All @@ -122,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/

Expand Down
68 changes: 29 additions & 39 deletions 8.2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
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 alpine:3.18 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

Expand Down Expand Up @@ -37,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 \
Expand All @@ -71,6 +76,7 @@ RUN set -ex \
libwebp-tools \
optipng \
pngquant \
gnu-libiconv \
&& docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
Expand All @@ -90,30 +96,8 @@ RUN set -ex \
redis \
&& docker-php-ext-enable \
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 ./
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

# 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 \
Expand All @@ -122,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/

Expand Down
10 changes: 5 additions & 5 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
roelvanhintum marked this conversation as resolved.
Show resolved Hide resolved
USER www-data

EXPOSE 8080
Expand Down