Skip to content

Commit 5ed07ec

Browse files
Imagemagick enable delegate build and disabled using shared libraries (#889)
compiles to a single portable binary Create a base builder package with compile time dependencies. Create an imagemagick_builder to build imagemagick. The base builder can be extended for other builders. Add imagemagick runtime dependencies to discourse_dependencies image avoid -dev libs Statically compile as much as possible with --disable-shared and --enable-delegate-build flags. References: https://stackoverflow.com/questions/47031789/imagemagick-100-static-build-for-linux https://www.imagemagick.org/discourse-server/viewtopic.php?t=14259 Add fonts-urw-base35 for NimbusSans-Regular, needed for letter avatar generation Copy over the resulting magick bin, as well as etc and share files from the compilation. etc is needed for magick to run, share is not, but contains translations for errors which Discourse tests are dependent on reading from. Create symlinks for other magick tooling - imagemagick creates symlink tool names that Discourse uses. These *could* be dropped if Discourse decided to use `magick {toolname}` rather than `{toolname}`. Add nginx compile dependency - building nginx still needs libfreetype6 This was implicitly installed previously. Removing the imagemagick build from base broke the next nginx build. Add this dependency back in. This dependency can be removed once we build nginx separately as well.
1 parent e70c359 commit 5ed07ec

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

image/base/Dockerfile

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
# VERSION: release
33

44
ARG DEBIAN_RELEASE=bookworm
5+
FROM discourse/ruby:3.3.6-${DEBIAN_RELEASE}-slim AS builder
6+
RUN apt update && \
7+
DEBIAN_FRONTEND=noninteractive apt-get -y install wget \
8+
autoconf build-essential \
9+
git \
10+
cmake \
11+
gnupg \
12+
libpcre3-dev \
13+
libfreetype6-dev \
14+
libbrotli-dev
15+
16+
FROM builder AS imagemagick_builder
17+
ADD install-imagemagick /tmp/install-imagemagick
18+
RUN /tmp/install-imagemagick
19+
520
FROM discourse/ruby:3.3.6-${DEBIAN_RELEASE}-slim AS discourse_dependencies
621

722
ARG DEBIAN_RELEASE
@@ -36,7 +51,13 @@ RUN --mount=type=tmpfs,target=/var/log \
3651
libreadline-dev anacron wget \
3752
psmisc whois brotli libunwind-dev \
3853
libtcmalloc-minimal4 cmake \
39-
pngcrush pngquant ripgrep poppler-utils; \
54+
pngcrush pngquant ripgrep poppler-utils \
55+
# imagemagick runtime dependencies
56+
libheif1 libjbig0 libtiff6 libpng16-16 libfontconfig1 \
57+
libwebpdemux2 libwebpmux3 libxext6 librsvg2-2 libgomp1 \
58+
fonts-urw-base35 \
59+
# nginx compile dependencies \
60+
libfreetype6-dev && \
4061
# install these without recommends to avoid pulling in e.g.
4162
# X11 libraries, mailutils
4263
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends git rsyslog logrotate cron ssh-client less; \
@@ -70,8 +91,24 @@ RUN sed -i "s/^# $LANG/$LANG/" /etc/locale.gen; \
7091
RUN --mount=type=tmpfs,target=/root/.npm \
7192
npm install -g terser uglify-js pnpm
7293

73-
ADD install-imagemagick /tmp/install-imagemagick
74-
RUN /tmp/install-imagemagick
94+
# Copy binary and configuration files for magick
95+
COPY --from=imagemagick_builder /usr/local/bin/magick /usr/local/bin/magick
96+
COPY --from=imagemagick_builder /usr/local/etc/ImageMagick-7 /usr/local/etc/ImageMagick-7
97+
COPY --from=imagemagick_builder /usr/local/share/ImageMagick-7 /usr/local/share/ImageMagick-7
98+
# Create symlinks to imagemagick tools
99+
RUN ln -s /usr/local/bin/magick /usr/local/bin/animate &&\
100+
ln -s /usr/local/bin/magick /usr/local/bin/compare &&\
101+
ln -s /usr/local/bin/magick /usr/local/bin/composite &&\
102+
ln -s /usr/local/bin/magick /usr/local/bin/conjure &&\
103+
ln -s /usr/local/bin/magick /usr/local/bin/convert &&\
104+
ln -s /usr/local/bin/magick /usr/local/bin/display &&\
105+
ln -s /usr/local/bin/magick /usr/local/bin/identify &&\
106+
ln -s /usr/local/bin/magick /usr/local/bin/import &&\
107+
ln -s /usr/local/bin/magick /usr/local/bin/magick-script &&\
108+
ln -s /usr/local/bin/magick /usr/local/bin/mogrify &&\
109+
ln -s /usr/local/bin/magick /usr/local/bin/montage &&\
110+
ln -s /usr/local/bin/magick /usr/local/bin/stream &&\
111+
test $(magick -version | grep -o -e png -e tiff -e jpeg -e freetype -e heic -e webp | wc -l) -eq 6
75112

76113
ADD install-jemalloc /tmp/install-jemalloc
77114
RUN /tmp/install-jemalloc

image/base/install-imagemagick

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ tar zxf $WDIR/ImageMagick.tar.gz -C $WDIR
4242
cd $IMDIR
4343
PKG_CONF_LIBDIR=$PREFIX/lib LDFLAGS=-L$PREFIX/lib CFLAGS='-O2 -I$PREFIX/include' ./configure \
4444
--prefix=$PREFIX \
45+
--disable-shared \
46+
--enable-delegate-build \
4547
--enable-static \
4648
--enable-bounds-checking \
4749
--enable-hdri \

0 commit comments

Comments
 (0)