Dockerfile-workers 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/log/nginx /var/lib/nginx
  36. # Copy Synapse worker, nginx and supervisord configuration template files
  37. COPY ./docker/conf-workers/* /conf/
  38. # Copy a script to prefix log lines with the supervisor program name
  39. COPY ./docker/prefix-log /usr/local/bin/
  40. # Expose nginx listener port
  41. EXPOSE 8080/tcp
  42. # A script to read environment variables and create the necessary
  43. # files to run the desired worker configuration. Will start supervisord.
  44. COPY ./docker/configure_workers_and_start.py /configure_workers_and_start.py
  45. ENTRYPOINT ["/configure_workers_and_start.py"]
  46. # Replace the healthcheck with one which checks *all* the workers. The script
  47. # is generated by configure_workers_and_start.py.
  48. HEALTHCHECK --start-period=5s --interval=15s --timeout=5s \
  49. CMD /bin/sh /healthcheck.sh