Dockerfile-workers 2.6 KB

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