Skip to content

Commit cfba723

Browse files
committed
Remove unnecessary base dependencies that bloat layer size
This change reduces the layer for this `RUN` command from 1GB to 678MB as shown in the `docker history <image name>` output.
1 parent 12153f7 commit cfba723

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

image/base/Dockerfile

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ RUN gpg --import /tmp/nginx_public_keys.key &&\
2525
rm /tmp/nginx_public_keys.key &&\
2626
/tmp/install-nginx
2727

28+
FROM builder AS thpfoff_builder
29+
30+
# This tool allows us to disable huge page support for our current process
31+
# since the flag is preserved through forks and execs it can be used on any
32+
# process
33+
ADD thpoff.c /src/thpoff.c
34+
RUN gcc -o /usr/local/sbin/thpoff /src/thpoff.c && rm /src/thpoff.c
35+
2836
FROM discourse/ruby:3.3.6-${DEBIAN_RELEASE}-slim AS discourse_dependencies
2937

3038
ARG DEBIAN_RELEASE
@@ -51,14 +59,14 @@ RUN --mount=type=tmpfs,target=/var/log \
5159
echo "debconf debconf/frontend select Teletype" | debconf-set-selections; \
5260
apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get -y install gnupg sudo curl fping locales \
5361
ca-certificates rsync \
54-
cmake g++ pkg-config patch \
55-
libxslt-dev libcurl4-openssl-dev \
56-
libssl-dev libyaml-dev libtool \
62+
cmake g++ patch \
63+
libcurl4-openssl-dev \
64+
libssl-dev libyaml-dev \
5765
libpcre3 libpcre3-dev zlib1g zlib1g-dev \
58-
libxml2-dev gawk parallel \
66+
gawk \
5967
libreadline-dev anacron wget \
6068
psmisc whois brotli libunwind-dev \
61-
libtcmalloc-minimal4 cmake \
69+
libtcmalloc-minimal4 \
6270
pngcrush pngquant ripgrep poppler-utils \
6371
# imagemagick runtime dependencies
6472
libheif1 libjbig0 libtiff6 libpng16-16 libfontconfig1 \
@@ -133,11 +141,7 @@ RUN gem install pups --force &&\
133141
mkdir -p /pups/bin/ &&\
134142
ln -s /usr/local/bin/pups /pups/bin/pups
135143

136-
# This tool allows us to disable huge page support for our current process
137-
# since the flag is preserved through forks and execs it can be used on any
138-
# process
139-
ADD thpoff.c /src/thpoff.c
140-
RUN gcc -o /usr/local/sbin/thpoff /src/thpoff.c && rm /src/thpoff.c
144+
COPY --from=thpfoff_builder /usr/local/sbin/thpoff /usr/local/sbin/thpoff
141145

142146
# clean up for docker squash
143147
RUN rm -fr /usr/local/share/doc &&\
@@ -165,7 +169,7 @@ RUN install -dm 0755 -o discourse -g discourse /var/www/discourse &&\
165169
FROM discourse_slim AS discourse_release
166170
ENV RAILS_ENV=production
167171

168-
RUN cd /var/www/discourse &&\
172+
RUN apt cd /var/www/discourse &&\
169173
sudo -u discourse bundle config --local deployment true &&\
170174
sudo -u discourse bundle config --local path ./vendor/bundle &&\
171175
sudo -u discourse bundle config --local without test development &&\

0 commit comments

Comments
 (0)