Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 166fafd

Browse files
authored
synapse-workers docker: copy nginx and redis in from base images (#13447)
Part of my continuing quest to make the docker images build quicker: copy nginx and redis in from base docker images, rather than apt installing each time.
1 parent a910782 commit 166fafd

File tree

3 files changed

+60
-36
lines changed

3 files changed

+60
-36
lines changed

changelog.d/13447.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve rebuild speed for the "synapse-workers" docker image.

docker/Dockerfile-workers

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,62 @@
11
# syntax=docker/dockerfile:1
2-
# Inherit from the official Synapse docker image
3-
ARG SYNAPSE_VERSION=latest
4-
FROM matrixdotorg/synapse:$SYNAPSE_VERSION
5-
6-
# Install deps
7-
RUN \
8-
--mount=type=cache,target=/var/cache/apt,sharing=locked \
9-
--mount=type=cache,target=/var/lib/apt,sharing=locked \
10-
apt-get update -qq && \
11-
DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends \
12-
redis-server nginx-light
13-
14-
# Install supervisord with pip instead of apt, to avoid installing a second
15-
# copy of python.
16-
RUN --mount=type=cache,target=/root/.cache/pip \
17-
pip install supervisor~=4.2
18-
19-
# Disable the default nginx sites
20-
RUN rm /etc/nginx/sites-enabled/default
212

22-
# Copy Synapse worker, nginx and supervisord configuration template files
23-
COPY ./docker/conf-workers/* /conf/
24-
25-
# Copy a script to prefix log lines with the supervisor program name
26-
COPY ./docker/prefix-log /usr/local/bin/
27-
28-
# Expose nginx listener port
29-
EXPOSE 8080/tcp
3+
ARG SYNAPSE_VERSION=latest
304

31-
# A script to read environment variables and create the necessary
32-
# files to run the desired worker configuration. Will start supervisord.
33-
COPY ./docker/configure_workers_and_start.py /configure_workers_and_start.py
34-
ENTRYPOINT ["/configure_workers_and_start.py"]
5+
# first of all, we create a base image with an nginx which we can copy into the
6+
# target image. For repeated rebuilds, this is much faster than apt installing
7+
# each time.
8+
9+
FROM debian:bullseye-slim AS deps_base
10+
RUN \
11+
--mount=type=cache,target=/var/cache/apt,sharing=locked \
12+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
13+
apt-get update -qq && \
14+
DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends \
15+
redis-server nginx-light
16+
17+
# Similarly, a base to copy the redis server from.
18+
#
19+
# The redis docker image has fewer dynamic libraries than the debian package,
20+
# which makes it much easier to copy (but we need to make sure we use an image
21+
# based on the same debian version as the synapse image, to make sure we get
22+
# the expected version of libc.
23+
FROM redis:6-bullseye AS redis_base
24+
25+
# now build the final image, based on the the regular Synapse docker image
26+
FROM matrixdotorg/synapse:$SYNAPSE_VERSION
3527

36-
# Replace the healthcheck with one which checks *all* the workers. The script
37-
# is generated by configure_workers_and_start.py.
38-
HEALTHCHECK --start-period=5s --interval=15s --timeout=5s \
39-
CMD /bin/sh /healthcheck.sh
28+
# Install supervisord with pip instead of apt, to avoid installing a second
29+
# copy of python.
30+
RUN --mount=type=cache,target=/root/.cache/pip \
31+
pip install supervisor~=4.2
32+
RUN mkdir -p /etc/supervisor/conf.d
33+
34+
# Copy over redis and nginx
35+
COPY --from=redis_base /usr/local/bin/redis-server /usr/local/bin
36+
37+
COPY --from=deps_base /usr/sbin/nginx /usr/sbin
38+
COPY --from=deps_base /usr/share/nginx /usr/share/nginx
39+
COPY --from=deps_base /usr/lib/nginx /usr/lib/nginx
40+
COPY --from=deps_base /etc/nginx /etc/nginx
41+
RUN rm /etc/nginx/sites-enabled/default
42+
RUN mkdir /var/log/nginx /var/lib/nginx
43+
RUN chown www-data /var/log/nginx /var/lib/nginx
44+
45+
# Copy Synapse worker, nginx and supervisord configuration template files
46+
COPY ./docker/conf-workers/* /conf/
47+
48+
# Copy a script to prefix log lines with the supervisor program name
49+
COPY ./docker/prefix-log /usr/local/bin/
50+
51+
# Expose nginx listener port
52+
EXPOSE 8080/tcp
53+
54+
# A script to read environment variables and create the necessary
55+
# files to run the desired worker configuration. Will start supervisord.
56+
COPY ./docker/configure_workers_and_start.py /configure_workers_and_start.py
57+
ENTRYPOINT ["/configure_workers_and_start.py"]
58+
59+
# Replace the healthcheck with one which checks *all* the workers. The script
60+
# is generated by configure_workers_and_start.py.
61+
HEALTHCHECK --start-period=5s --interval=15s --timeout=5s \
62+
CMD /bin/sh /healthcheck.sh

docker/conf-workers/supervisord.conf.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ username=www-data
1919
autorestart=true
2020

2121
[program:redis]
22-
command=/usr/local/bin/prefix-log /usr/bin/redis-server /etc/redis/redis.conf --daemonize no
22+
command=/usr/local/bin/prefix-log /usr/local/bin/redis-server
2323
priority=1
2424
stdout_logfile=/dev/stdout
2525
stdout_logfile_maxbytes=0

0 commit comments

Comments
 (0)