1
0

Dockerfile-workers 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # syntax=docker/dockerfile:1
  2. ARG SYNAPSE_VERSION=latest
  3. # first of all, we create a base image with an nginx which we can copy into the
  4. # target image. For repeated rebuilds, this is much faster than apt installing
  5. # each time.
  6. FROM debian:bullseye-slim AS deps_base
  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. # Similarly, a base to copy the redis server from.
  14. #
  15. # The redis docker image has fewer dynamic libraries than the debian package,
  16. # which makes it much easier to copy (but we need to make sure we use an image
  17. # based on the same debian version as the synapse image, to make sure we get
  18. # the expected version of libc.
  19. FROM redis:6-bullseye AS redis_base
  20. # now build the final image, based on the the regular Synapse docker image
  21. FROM matrixdotorg/synapse:$SYNAPSE_VERSION
  22. # Install supervisord with pip instead of apt, to avoid installing a second
  23. # copy of python.
  24. RUN --mount=type=cache,target=/root/.cache/pip \
  25. pip install supervisor~=4.2
  26. RUN mkdir -p /etc/supervisor/conf.d
  27. # Copy over redis and nginx
  28. COPY --from=redis_base /usr/local/bin/redis-server /usr/local/bin
  29. COPY --from=deps_base /usr/sbin/nginx /usr/sbin
  30. COPY --from=deps_base /usr/share/nginx /usr/share/nginx
  31. COPY --from=deps_base /usr/lib/nginx /usr/lib/nginx
  32. COPY --from=deps_base /etc/nginx /etc/nginx
  33. RUN rm /etc/nginx/sites-enabled/default
  34. RUN mkdir /var/log/nginx /var/lib/nginx
  35. RUN chown www-data /var/lib/nginx
  36. # have nginx log to stderr/out
  37. RUN ln -sf /dev/stdout /var/log/nginx/access.log
  38. RUN ln -sf /dev/stderr /var/log/nginx/error.log
  39. # Copy Synapse worker, nginx and supervisord configuration template files
  40. COPY ./docker/conf-workers/* /conf/
  41. # Copy a script to prefix log lines with the supervisor program name
  42. COPY ./docker/prefix-log /usr/local/bin/
  43. # Expose nginx listener port
  44. EXPOSE 8080/tcp
  45. # A script to read environment variables and create the necessary
  46. # files to run the desired worker configuration. Will start supervisord.
  47. COPY ./docker/configure_workers_and_start.py /configure_workers_and_start.py
  48. ENTRYPOINT ["/configure_workers_and_start.py"]
  49. # Replace the healthcheck with one which checks *all* the workers. The script
  50. # is generated by configure_workers_and_start.py.
  51. HEALTHCHECK --start-period=5s --interval=15s --timeout=5s \
  52. CMD /bin/sh /healthcheck.sh