Skip to content

Commit 2b70c72

Browse files
DEV: Move extern gems to compile separately
Remove make, g++, and -dev packages from base image. Compile gems that need it separately, and copy after compile. Install make and g++ to install redis Reduce size of docker image by 250MB TODO: need to figure out a way of recompiling gems that require compilation. Otherwise the gems that require external compilation steps will not be able to install with bundle.
1 parent 9455516 commit 2b70c72

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

image/base/Dockerfile

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ RUN --mount=type=tmpfs,target=/var/log \
7272
echo "debconf debconf/frontend select Teletype" | debconf-set-selections; \
7373
apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get -y install gnupg sudo curl fping locales \
7474
ca-certificates rsync \
75-
cmake g++ pkg-config patch \
76-
libxslt-dev libcurl4-openssl-dev \
77-
libssl-dev libyaml-dev libtool \
78-
libpcre3 libpcre3-dev zlib1g zlib1g-dev \
79-
libxml2-dev gawk parallel \
80-
libreadline-dev anacron wget \
81-
psmisc whois brotli libunwind-dev \
82-
libtcmalloc-minimal4 cmake \
75+
pkg-config patch \
76+
libtool \
77+
libpcre3 zlib1g \
78+
gawk parallel \
79+
anacron wget \
80+
psmisc whois brotli \
81+
libtcmalloc-minimal4 \
8382
pngcrush pngquant ripgrep poppler-utils \
8483
# imagemagick runtime dependencies
8584
ghostscript libjbig0 libtiff6 libpng16-16 libfontconfig1 \
@@ -108,7 +107,7 @@ RUN --mount=type=tmpfs,target=/var/log \
108107
dpkg-divert --local --rename --add /sbin/initctl; \
109108
sh -c "test -f /sbin/initctl || ln -s /bin/true /sbin/initctl"; \
110109
apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get -y install runit socat \
111-
libpq-dev postgresql-client-${PG_MAJOR} \
110+
postgresql-client-${PG_MAJOR} \
112111
nodejs yarn &&\
113112
mkdir -p /etc/runit/1.d
114113

@@ -169,21 +168,51 @@ RUN install -dm 0755 -o discourse -g discourse /var/www/discourse &&\
169168
sudo -u discourse git clone --branch $DISCOURSE_BRANCH --filter=tree:0 https://github.com/discourse/discourse.git /var/www/discourse &&\
170169
gem install bundler --conservative -v $(awk '/BUNDLED WITH/ { getline; gsub(/ /,""); print $0 }' /var/www/discourse/Gemfile.lock)
171170

171+
FROM discourse_slim AS discourse_gem_builder
172+
RUN --mount=type=tmpfs,target=/var/log \
173+
apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get -y install \
174+
cmake g++ \
175+
libxslt-dev libcurl4-openssl-dev \
176+
libssl-dev libyaml-dev \
177+
libpcre3-dev zlib1g-dev \
178+
libxml2-dev \
179+
libreadline-dev \
180+
libunwind-dev \
181+
libpq-dev
182+
RUN cd /var/www/discourse &&\
183+
sudo -u discourse bundle config --local deployment true &&\
184+
sudo -u discourse bundle config --local path ./vendor/bundle &&\
185+
sudo -u discourse bundle config --local without test development &&\
186+
sudo -u discourse bundle install --jobs $(($(nproc) - 1)) &&\
187+
find /var/www/discourse/vendor/bundle -name cache -not -path '*/gems/*' -type d -exec rm -rf {} + &&\
188+
find /var/www/discourse/vendor/bundle -name tmp -type d -exec rm -rf {} + &&\
189+
# Delete compile time libv8 library
190+
find /var/www/discourse/vendor/bundle -wholename "*libv8-node*/vendor" -type d -exec rm -rf {} +
191+
172192
FROM discourse_slim AS discourse_web_only
173193
ENV RAILS_ENV=production
174194

175195
RUN cd /var/www/discourse &&\
176-
sudo -u discourse bundle config --local deployment true &&\
177-
sudo -u discourse bundle config --local path ./vendor/bundle &&\
178-
sudo -u discourse bundle config --local without test development &&\
179-
sudo -u discourse bundle install --jobs $(($(nproc) - 1)) &&\
180-
find /var/www/discourse/vendor/bundle -name cache -not -path '*/gems/*' -type d -exec rm -rf {} + &&\
181-
find /var/www/discourse/vendor/bundle -name tmp -type d -exec rm -rf {} +
196+
sudo -u discourse bundle config --local deployment true &&\
197+
sudo -u discourse bundle config --local path ./vendor/bundle &&\
198+
sudo -u discourse bundle config --local without test development
199+
COPY --from=discourse_gem_builder /var/www/discourse/vendor/bundle /var/www/discourse/vendor/bundle
182200

183201
RUN cd /var/www/discourse &&\
184202
sudo -u discourse /bin/bash -c 'if [ -f yarn.lock ]; then yarn install --frozen-lockfile && yarn cache clean; else pnpm install --frozen-lockfile; fi'
185203

186204
FROM discourse_web_only AS discourse_release
205+
206+
RUN --mount=type=tmpfs,target=/var/log \
207+
apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get -y install \
208+
cmake g++ \
209+
libxslt-dev libcurl4-openssl-dev \
210+
libssl-dev libyaml-dev \
211+
libpcre3-dev zlib1g-dev \
212+
libxml2-dev \
213+
libreadline-dev \
214+
libunwind-dev \
215+
libpq-dev
187216
RUN --mount=type=tmpfs,target=/var/log \
188217
apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get -y install \
189218
postgresql-${PG_MAJOR} postgresql-contrib-${PG_MAJOR} postgresql-${PG_MAJOR}-pgvector

image/discourse_dev/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ FROM discourse/base:$from_tag
1616
# Install Postgres and Redis
1717
RUN --mount=type=tmpfs,target=/var/log \
1818
apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get -y install \
19+
cmake g++ \
1920
postgresql-${PG_MAJOR} postgresql-contrib-${PG_MAJOR} postgresql-${PG_MAJOR}-pgvector
2021
RUN /tmp/install-redis
2122

image/discourse_test/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RUN sudo -E -u discourse -H git config --global user.email "[email protected]" &&\
1313
# Include postgres and redis on test images
1414
RUN --mount=type=tmpfs,target=/var/log \
1515
apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get -y install \
16+
cmake g++ \
1617
postgresql-${PG_MAJOR} postgresql-contrib-${PG_MAJOR} postgresql-${PG_MAJOR}-pgvector
1718
RUN /tmp/install-redis
1819

0 commit comments

Comments
 (0)