|
1 | 1 | # 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 |
21 | 2 |
|
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 |
30 | 4 |
|
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 |
35 | 27 |
|
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 |
0 commit comments