Dockerfile 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # syntax=docker/dockerfile:1
  2. # This dockerfile builds on top of 'docker/Dockerfile-workers' in matrix-org/synapse
  3. # by including a built-in postgres instance, as well as setting up the homeserver so
  4. # that it is ready for testing via Complement.
  5. #
  6. # Instructions for building this image from those it depends on is detailed in this guide:
  7. # https://github.com/matrix-org/synapse/blob/develop/docker/README-testing.md#testing-with-postgresql-and-single-or-multi-process-synapse
  8. ARG SYNAPSE_VERSION=latest
  9. ARG FROM=matrixdotorg/synapse-workers:$SYNAPSE_VERSION
  10. FROM $FROM
  11. # First of all, we copy postgres server from the official postgres image,
  12. # since for repeated rebuilds, this is much faster than apt installing
  13. # postgres each time.
  14. # This trick only works because (a) the Synapse image happens to have all the
  15. # shared libraries that postgres wants, (b) we use a postgres image based on
  16. # the same debian version as Synapse's docker image (so the versions of the
  17. # shared libraries match).
  18. RUN adduser --system --uid 999 postgres --home /var/lib/postgresql
  19. COPY --from=postgres:13-bullseye /usr/lib/postgresql /usr/lib/postgresql
  20. COPY --from=postgres:13-bullseye /usr/share/postgresql /usr/share/postgresql
  21. RUN mkdir /var/run/postgresql && chown postgres /var/run/postgresql
  22. ENV PATH="${PATH}:/usr/lib/postgresql/13/bin"
  23. ENV PGDATA=/var/lib/postgresql/data
  24. # We also initialize the database at build time, rather than runtime, so that it's faster to spin up the image.
  25. RUN gosu postgres initdb --locale=C --encoding=UTF-8 --auth-host password
  26. # Configure a password and create a database for Synapse
  27. RUN echo "ALTER USER postgres PASSWORD 'somesecret'" | gosu postgres postgres --single
  28. RUN echo "CREATE DATABASE synapse" | gosu postgres postgres --single
  29. # Extend the shared homeserver config to disable rate-limiting,
  30. # set Complement's static shared secret, enable registration, amongst other
  31. # tweaks to get Synapse ready for testing.
  32. # To do this, we copy the old template out of the way and then include it
  33. # with Jinja2.
  34. RUN mv /conf/shared.yaml.j2 /conf/shared-orig.yaml.j2
  35. COPY conf/workers-shared-extra.yaml.j2 /conf/shared.yaml.j2
  36. WORKDIR /data
  37. COPY conf/postgres.supervisord.conf /etc/supervisor/conf.d/postgres.conf
  38. # Copy the entrypoint
  39. COPY conf/start_for_complement.sh /
  40. # Expose nginx's listener ports
  41. EXPOSE 8008 8448
  42. ENTRYPOINT ["/start_for_complement.sh"]
  43. # Update the healthcheck to have a shorter check interval
  44. HEALTHCHECK --start-period=5s --interval=1s --timeout=1s \
  45. CMD /bin/sh /healthcheck.sh