Skip to content

Commit 9153ea6

Browse files
committed
WIP: Consolidate layers
1 parent b2dab18 commit 9153ea6

File tree

4 files changed

+189
-136
lines changed

4 files changed

+189
-136
lines changed

image/base/install-imagemagick

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,9 @@ set -e
55
IMAGE_MAGICK_VERSION="7.1.0-62"
66
IMAGE_MAGICK_HASH="d282117bc6d0e91ad1ad685d096623b96ed8e229f911c891d83277b350ef884a"
77

8-
# We use debian, but GitHub CI is stuck on Ubuntu Bionic, so this must be compatible with both
9-
LIBJPEGTURBO=$(cat /etc/issue | grep -qi Debian && echo 'libjpeg62-turbo libjpeg62-turbo-dev' || echo 'libjpeg-turbo8 libjpeg-turbo8-dev')
10-
11-
# Ubuntu 22.04/22.10 doesn't have libwebp6
12-
LIBWEBP=$(cat /etc/issue | grep -qiE 'Debian GNU/Linux 12|Ubuntu 22' && echo 'libwebp7' || echo 'libwebp6')
13-
148
PREFIX=/usr/local
159
WDIR=/tmp/imagemagick
1610

17-
# Install build deps
18-
apt -y -q remove imagemagick
19-
apt -y -q install git make gcc pkg-config autoconf curl g++ yasm cmake \
20-
libde265-0 libde265-dev ${LIBJPEGTURBO} ${LIBWEBP} x265 libx265-dev libtool \
21-
libpng16-16 libpng-dev libwebp-dev libgomp1 \
22-
libwebpmux3 libwebpdemux2 ghostscript libxml2-dev libxml2-utils librsvg2-dev \
23-
libltdl7-dev libbz2-dev gsfonts libtiff-dev libfreetype6-dev libjpeg-dev libheif1 libheif-dev
24-
25-
# Ubuntu doesn't like backports
26-
if cat /etc/issue | grep -qiE 'Debian GNU/Linux 12|Ubuntu 22'; then
27-
apt -y install libaom-dev
28-
else
29-
# Use backports instead of compiling it
30-
apt -y -q install -t bullseye-backports libaom-dev
31-
fi
32-
3311
mkdir -p $WDIR
3412
cd $WDIR
3513

image/base/install-nginx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ gpg --verify nginx-$VERSION.tar.gz.asc nginx-$VERSION.tar.gz
1111
tar zxf nginx-$VERSION.tar.gz
1212
cd nginx-$VERSION
1313

14-
# nginx-common for boilerplate files etc.
15-
apt install -y nginx-common
16-
1714
cd /tmp
1815
# this is the reason we are compiling by hand...
1916
git clone https://github.com/google/ngx_brotli.git

image/base/install-oxipng

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ case "${dpkgArch##*-}" in
1111
*) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;;
1212
esac
1313

14-
# Install other deps
15-
apt -y -q install advancecomp jhead jpegoptim libjpeg-turbo-progs optipng
16-
1714
mkdir /oxipng-install
1815
cd /oxipng-install
1916

image/base/slim.Dockerfile

Lines changed: 189 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -8,126 +8,207 @@ ARG DEBIAN_RELEASE
88
ENV PG_MAJOR=13 \
99
RUBY_ALLOCATOR=/usr/lib/libjemalloc.so \
1010
LEFTHOOK=0 \
11-
DEBIAN_RELEASE=${DEBIAN_RELEASE}
11+
DEBIAN_RELEASE=${DEBIAN_RELEASE} \
12+
LC_ALL=en_US.UTF-8 \
13+
LANG=en_US.UTF-8 \
14+
LANGUAGE=en_US.UTF-8
1215

1316
#LABEL maintainer="Sam Saffron \"https://twitter.com/samsaffron\""
1417

15-
# Ensures that the gid and uid of the following users are consistent to avoid permission issues on directories in the
16-
# mounted volumes.
17-
RUN groupadd --gid 104 postgres &&\
18-
useradd --uid 101 --gid 104 --home /var/lib/postgresql --shell /bin/bash -c "PostgreSQL administrator,,," postgres &&\
19-
groupadd --gid 106 redis &&\
20-
useradd --uid 103 --gid 106 --home /var/lib/redis --shell /usr/sbin/nologin redis &&\
21-
groupadd --gid 1000 discourse &&\
22-
useradd --uid 1000 --gid 1000 -m --shell /bin/bash discourse
23-
24-
RUN echo 2.0.`date +%Y%m%d` > /VERSION
25-
RUN echo "deb http://deb.debian.org/debian ${DEBIAN_RELEASE}-backports main" > "/etc/apt/sources.list.d/${DEBIAN_RELEASE}-backports.list"
26-
RUN echo "debconf debconf/frontend select Teletype" | debconf-set-selections
27-
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install gnupg sudo curl fping
28-
RUN sh -c "fping proxy && echo 'Acquire { Retries \"0\"; HTTP { Proxy \"http://proxy:3128\";}; };' > /etc/apt/apt.conf.d/40proxy && apt-get update || true"
29-
RUN apt-mark hold initscripts
30-
RUN apt-get -y upgrade
31-
32-
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y locales locales-all
33-
ENV LC_ALL en_US.UTF-8
34-
ENV LANG en_US.UTF-8
35-
ENV LANGUAGE en_US.UTF-8
36-
37-
RUN install -d /usr/share/postgresql-common/pgdg &&\
38-
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc &&\
39-
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt ${DEBIAN_RELEASE}-pgdg main" > /etc/apt/sources.list.d/pgdg.list
40-
41-
RUN curl --silent --location https://deb.nodesource.com/setup_18.x | sudo bash -
42-
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
43-
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
44-
RUN apt-get -y update
45-
# install these without recommends to avoid pulling in e.g.
46-
# X11 libraries, mailutils
47-
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends git rsyslog logrotate cron ssh-client less
48-
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install autoconf build-essential ca-certificates rsync \
49-
libxslt-dev libcurl4-openssl-dev \
50-
libssl-dev libyaml-dev libtool \
51-
libpcre3 libpcre3-dev zlib1g zlib1g-dev \
52-
libxml2-dev gawk parallel \
53-
postgresql-${PG_MAJOR} postgresql-client \
54-
postgresql-contrib-${PG_MAJOR} libpq-dev postgresql-${PG_MAJOR}-pgvector \
55-
libreadline-dev anacron wget \
56-
psmisc whois brotli libunwind-dev \
57-
libtcmalloc-minimal4 cmake \
58-
pngcrush pngquant ripgrep poppler-utils
59-
RUN sed -i -e 's/start -q anacron/anacron -s/' /etc/cron.d/anacron
60-
RUN sed -i.bak 's/$ModLoad imklog/#$ModLoad imklog/' /etc/rsyslog.conf
61-
RUN sed -i.bak 's/module(load="imklog")/#module(load="imklog")/' /etc/rsyslog.conf
62-
RUN dpkg-divert --local --rename --add /sbin/initctl
63-
RUN sh -c "test -f /sbin/initctl || ln -s /bin/true /sbin/initctl"
64-
RUN cd / &&\
65-
DEBIAN_FRONTEND=noninteractive apt-get -y install runit socat &&\
66-
mkdir -p /etc/runit/1.d &&\
67-
apt-get clean &&\
68-
rm -f /etc/apt/apt.conf.d/40proxy &&\
69-
locale-gen en_US &&\
70-
DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs yarn &&\
71-
npm install -g terser uglify-js pnpm
72-
7318
ADD install-imagemagick /tmp/install-imagemagick
74-
RUN /tmp/install-imagemagick
75-
7619
ADD install-jemalloc /tmp/install-jemalloc
77-
RUN /tmp/install-jemalloc
78-
7920
# From https://nginx.org/en/pgp_keys.html
8021
ADD nginx_public_keys.key /tmp/nginx_public_keys.key
8122
ADD install-nginx /tmp/install-nginx
82-
83-
RUN gpg --import /tmp/nginx_public_keys.key &&\
84-
rm /tmp/nginx_public_keys.key &&\
85-
/tmp/install-nginx
86-
87-
ADD install-redis /tmp/install-redis
88-
RUN /tmp/install-redis
89-
9023
ADD install-oxipng /tmp/install-oxipng
91-
RUN /tmp/install-oxipng
92-
93-
RUN echo 'gem: --no-document' >> /usr/local/etc/gemrc &&\
94-
gem update --system
95-
96-
RUN gem install pups --force &&\
97-
mkdir -p /pups/bin/ &&\
98-
ln -s /usr/local/bin/pups /pups/bin/pups
99-
24+
ADD install-redis /tmp/install-redis
10025
# This tool allows us to disable huge page support for our current process
10126
# since the flag is preserved through forks and execs it can be used on any
10227
# process
10328
ADD thpoff.c /src/thpoff.c
104-
RUN gcc -o /usr/local/sbin/thpoff /src/thpoff.c && rm /src/thpoff.c
10529

106-
# clean up for docker squash
107-
RUN rm -fr /usr/share/man &&\
108-
rm -fr /usr/share/doc &&\
109-
rm -fr /usr/share/vim/vim74/doc &&\
110-
rm -fr /usr/share/vim/vim74/lang &&\
111-
rm -fr /usr/share/vim/vim74/spell/en* &&\
112-
rm -fr /usr/share/vim/vim74/tutor &&\
113-
rm -fr /usr/local/share/doc &&\
114-
rm -fr /usr/local/share/ri &&\
115-
rm -fr /var/lib/apt/lists/* &&\
116-
rm -fr /root/.gem &&\
117-
rm -fr /root/.npm &&\
118-
rm -fr /tmp/*
119-
120-
# this can probably be done, but I worry that people changing PG locales will have issues
121-
# cd /usr/share/locale && rm -fr `ls -d */ | grep -v en`
122-
123-
# this is required for aarch64 which uses buildx
124-
# see https://github.com/docker/buildx/issues/150
125-
RUN rm -f /etc/service
126-
127-
COPY etc/ /etc
30+
RUN set -eux; \
31+
# Ensures that the gid and uid of the following users are consistent to avoid permission issues on directories in the
32+
# mounted volumes.
33+
groupadd --gid 104 postgres; \
34+
useradd --uid 101 --gid 104 --home /var/lib/postgresql --shell /bin/bash -c "PostgreSQL administrator,,," postgres; \
35+
groupadd --gid 106 redis; \
36+
useradd --uid 103 --gid 106 --home /var/lib/redis --shell /usr/sbin/nologin redis; \
37+
groupadd --gid 1000 discourse; \
38+
useradd --uid 1000 --gid 1000 -m --shell /bin/bash discourse; \
39+
\
40+
echo 2.0.`date +%Y%m%d` > /VERSION; \
41+
echo "deb http://deb.debian.org/debian ${DEBIAN_RELEASE}-backports main" > "/etc/apt/sources.list.d/${DEBIAN_RELEASE}-backports.list"; \
42+
echo "debconf debconf/frontend select Teletype" | debconf-set-selections; \
43+
apt-get update; \
44+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sudo curl; \
45+
install -d /usr/share/postgresql-common/pgdg; \
46+
curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc; \
47+
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt ${DEBIAN_RELEASE}-pgdg main" > /etc/apt/sources.list.d/pgdg.list; \
48+
curl --silent --location https://deb.nodesource.com/setup_18.x | sudo bash -; \
49+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -; \
50+
echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list; \
51+
apt-mark hold initscripts; \
52+
apt-get update; \
53+
apt-get -y upgrade; \
54+
\
55+
# Dependencies required to run Discourse
56+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
57+
locales \
58+
locales-all \
59+
git \
60+
rsyslog \
61+
logrotate \
62+
cron \
63+
ssh-client \
64+
less \
65+
ca-certificates \
66+
rsync \
67+
libxslt-dev \
68+
libcurl4-openssl-dev \
69+
libssl-dev \
70+
libyaml-dev \
71+
libtool \
72+
libpcre3 \
73+
libpcre3-dev \
74+
zlib1g \
75+
zlib1g-dev \
76+
libxml2-dev \
77+
gawk \
78+
parallel \
79+
postgresql-${PG_MAJOR} \
80+
postgresql-client \
81+
postgresql-contrib-${PG_MAJOR} \
82+
libpq-dev \
83+
postgresql-${PG_MAJOR}-pgvector \
84+
libreadline-dev \
85+
anacron \
86+
psmisc \
87+
whois \
88+
brotli \
89+
libunwind-dev \
90+
libtcmalloc-minimal4 \
91+
ripgrep \
92+
poppler-utils \
93+
runit \
94+
socat \
95+
nodejs \
96+
yarn \
97+
# START Nginx
98+
nginx-common \
99+
# END Nginx
100+
# START ImageMagick
101+
pngcrush \
102+
pngquant \
103+
libde265-0 \
104+
libde265-dev \
105+
libjpeg62-turbo \
106+
libjpeg62-turbo-dev \
107+
libwebp7 \
108+
x265 \
109+
libx265-dev \
110+
libtool \
111+
libpng16-16 \
112+
libpng-dev \
113+
libwebp-dev \
114+
libgomp1 \
115+
libwebpmux3 \
116+
libwebpdemux2 \
117+
ghostscript \
118+
libxml2-dev \
119+
libxml2-utils \
120+
librsvg2-dev \
121+
libltdl7-dev \
122+
libbz2-dev \
123+
gsfonts \
124+
libtiff-dev \
125+
libfreetype6-dev \
126+
libjpeg-dev \
127+
libheif1 \
128+
libheif-dev \
129+
libaom-dev \
130+
# END ImageMagick
131+
; \
132+
savedAptMark="$(apt-mark showmanual)"; \
133+
# Dependencies required to build packages. These packages are automatically removed
134+
# at the end of the RUN step.
135+
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
136+
wget \
137+
gcc \
138+
g++ \
139+
make \
140+
cmake \
141+
autoconf \
142+
automake \
143+
libtool \
144+
pkg-config \
145+
autoconf \
146+
yasm \
147+
; \
148+
sed -i -e 's/start -q anacron/anacron -s/' /etc/cron.d/anacron; \
149+
sed -i.bak 's/$ModLoad imklog/#$ModLoad imklog/' /etc/rsyslog.conf; \
150+
sed -i.bak 's/module(load="imklog")/#module(load="imklog")/' /etc/rsyslog.conf; \
151+
dpkg-divert --local --rename --add /sbin/initctl; \
152+
sh -c "test -f /sbin/initctl || ln -s /bin/true /sbin/initctl"; \
153+
mkdir -p /etc/runit/1.d; \
154+
rm -f /etc/apt/apt.conf.d/40proxy; \
155+
locale-gen en_US; \
156+
npm install -g terser uglify-js pnpm; \
157+
\
158+
# Installs ImageMagick
159+
/tmp/install-imagemagick; \
160+
# Installs JeMalloc
161+
/tmp/install-jemalloc; \
162+
\
163+
# Installs Nginx
164+
gpg --import /tmp/nginx_public_keys.key; \
165+
rm /tmp/nginx_public_keys.key; \
166+
/tmp/install-nginx; \
167+
# Installs Redis
168+
/tmp/install-redis; \
169+
# Installs Oxipng
170+
/tmp/install-oxipng; \
171+
echo 'gem: --no-document' >> /usr/local/etc/gemrc; \
172+
gem update --system; \
173+
gem install pups --force; \
174+
mkdir -p /pups/bin/; \
175+
ln -s /usr/local/bin/pups /pups/bin/pups; \
176+
gcc -o /usr/local/sbin/thpoff /src/thpoff.c && rm /src/thpoff.c; \
177+
\
178+
# Discourse specific bits
179+
install -dm 0755 -o discourse -g discourse /var/www/discourse; \
180+
sudo -u discourse git clone --filter=tree:0 https://github.com/discourse/discourse.git /var/www/discourse; \
181+
gem install bundler --conservative -v $(awk '/BUNDLED WITH/ { getline; gsub(/ /,""); print $0 }' /var/www/discourse/Gemfile.lock); \
182+
\
183+
# Clean up
184+
rm -fr /usr/share/man; \
185+
rm -fr /usr/share/doc; \
186+
rm -fr /usr/share/vim/vim74/doc; \
187+
rm -fr /usr/share/vim/vim74/lang; \
188+
rm -fr /usr/share/vim/vim74/spell/en*; \
189+
rm -fr /usr/share/vim/vim74/tutor; \
190+
rm -fr /usr/local/share/doc; \
191+
rm -fr /usr/local/share/ri; \
192+
rm -fr /var/lib/apt/lists/*; \
193+
rm -fr /root/.gem; \
194+
rm -fr /root/.npm; \
195+
rm -fr /tmp/*; \
196+
apt-mark auto '.*' > /dev/null; \
197+
apt-mark manual $savedAptMark > /dev/null; \
198+
find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
199+
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \
200+
| sort -u \
201+
| xargs -r dpkg-query --search \
202+
| cut -d: -f1 \
203+
| sort -u \
204+
| xargs -r apt-mark manual \
205+
; \
206+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
207+
apt-get clean; \
208+
\
209+
# this is required for aarch64 which uses buildx
210+
# see https://github.com/docker/buildx/issues/150
211+
rm -f /etc/service
212+
213+
COPY etc/ /etc
128214
COPY sbin/ /sbin
129-
130-
# Discourse specific bits
131-
RUN install -dm 0755 -o discourse -g discourse /var/www/discourse &&\
132-
sudo -u discourse git clone --filter=tree:0 https://github.com/discourse/discourse.git /var/www/discourse &&\
133-
gem install bundler --conservative -v $(awk '/BUNDLED WITH/ { getline; gsub(/ /,""); print $0 }' /var/www/discourse/Gemfile.lock)

0 commit comments

Comments
 (0)