Skip to content

Commit

Permalink
Build mozjpeg ourselves
Browse files Browse the repository at this point in the history
  • Loading branch information
timkelty committed Aug 13, 2021
1 parent 1bbea29 commit e40abfd
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 48 deletions.
45 changes: 33 additions & 12 deletions 7.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,46 @@ RUN set -ex \
redis \
&& docker-php-ext-enable \
imagick \
redis \
&& RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u)" \
&& apk add --no-cache --virtual .runtime-deps $RUNTIME_DEPS \
&& apk del --no-network .build-deps

This comment has been minimized.

Copy link
@jawys

jawys Aug 20, 2021

Contributor

I have to report that the corresponding image layer went from 165MB to 695MB and I assume it happened in this change by moving the apk del out from here.
Would it be possible to put this cleanup step back in?

This comment has been minimized.

Copy link
@timkelty

timkelty Aug 20, 2021

Author Collaborator

Yikes, good catch. Will investigate: #41

redis

# https://github.com/craftcms/docker/issues/16
COPY --from=iconv-build /usr/lib/preloadable_libiconv.so /usr/lib/preloadable_libiconv.so

# mozjpeg is not available in alpine
COPY --from=bugoman/mozjpeg /opt/mozjpeg /opt/mozjpeg
# https://github.com/docker-library/php/issues/1121
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so

# Mozjpeg
WORKDIR /tmp
ARG 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

RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran
RUN ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg

# https://github.com/docker-library/php/issues/1121
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
RUN RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u)" \
&& apk add --no-cache --virtual .runtime-deps $RUNTIME_DEPS \
&& apk del --no-network .build-deps \
&& rm -rf /tmp/*

# copy custom.ini settings
COPY craft-cms.ini /usr/local/etc/php/conf.d/
Expand Down
45 changes: 33 additions & 12 deletions 7.4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,46 @@ RUN set -ex \
redis \
&& docker-php-ext-enable \
imagick \
redis \
&& RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u)" \
&& apk add --no-cache --virtual .runtime-deps $RUNTIME_DEPS \
&& apk del --no-network .build-deps
redis

# https://github.com/craftcms/docker/issues/16
COPY --from=iconv-build /usr/lib/preloadable_libiconv.so /usr/lib/preloadable_libiconv.so

# mozjpeg is not available in alpine
COPY --from=bugoman/mozjpeg /opt/mozjpeg /opt/mozjpeg
# https://github.com/docker-library/php/issues/1121
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so

# Mozjpeg
WORKDIR /tmp
ARG 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

RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran
RUN ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg

# https://github.com/docker-library/php/issues/1121
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
RUN RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u)" \
&& apk add --no-cache --virtual .runtime-deps $RUNTIME_DEPS \
&& apk del --no-network .build-deps \
&& rm -rf /tmp/*

# copy custom.ini settings
COPY craft-cms.ini /usr/local/etc/php/conf.d/
Expand Down
45 changes: 33 additions & 12 deletions 8.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,46 @@ RUN set -ex \
redis \
&& docker-php-ext-enable \
imagick \
redis \
&& RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u)" \
&& apk add --no-cache --virtual .runtime-deps $RUNTIME_DEPS \
&& apk del --no-network .build-deps
redis

# https://github.com/craftcms/docker/issues/16
COPY --from=iconv-build /usr/lib/preloadable_libiconv.so /usr/lib/preloadable_libiconv.so

# mozjpeg is not available in alpine
COPY --from=bugoman/mozjpeg /opt/mozjpeg /opt/mozjpeg
# https://github.com/docker-library/php/issues/1121
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so

# Mozjpeg
WORKDIR /tmp
ARG 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

RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran
RUN ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg

# https://github.com/docker-library/php/issues/1121
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
RUN RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u)" \
&& apk add --no-cache --virtual .runtime-deps $RUNTIME_DEPS \
&& apk del --no-network .build-deps \
&& rm -rf /tmp/*

# copy custom.ini settings
COPY craft-cms.ini /usr/local/etc/php/conf.d/
Expand Down
45 changes: 33 additions & 12 deletions 8.1-rc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,46 @@ RUN set -ex \
redis \
&& docker-php-ext-enable \
imagick \
redis \
&& RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u)" \
&& apk add --no-cache --virtual .runtime-deps $RUNTIME_DEPS \
&& apk del --no-network .build-deps
redis

# https://github.com/craftcms/docker/issues/16
COPY --from=iconv-build /usr/lib/preloadable_libiconv.so /usr/lib/preloadable_libiconv.so

# mozjpeg is not available in alpine
COPY --from=bugoman/mozjpeg /opt/mozjpeg /opt/mozjpeg
# https://github.com/docker-library/php/issues/1121
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so

# Mozjpeg
WORKDIR /tmp
ARG 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

RUN ln -s /opt/mozjpeg/bin/jpegtran /usr/local/bin/mozjpegtran
RUN ln -s /opt/mozjpeg/bin/cjpeg /usr/local/bin/mozcjpeg

# https://github.com/docker-library/php/issues/1121
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
RUN RUNTIME_DEPS="$(scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u)" \
&& apk add --no-cache --virtual .runtime-deps $RUNTIME_DEPS \
&& apk del --no-network .build-deps \
&& rm -rf /tmp/*

# copy custom.ini settings
COPY craft-cms.ini /usr/local/etc/php/conf.d/
Expand Down

0 comments on commit e40abfd

Please sign in to comment.