Dockerfile 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Dockerfile to build the matrixdotorg/synapse docker images.
  2. #
  3. # To build the image, run `docker build` command from the root of the
  4. # synapse repository:
  5. #
  6. # docker build -f docker/Dockerfile .
  7. #
  8. # There is an optional PYTHON_VERSION build argument which sets the
  9. # version of python to build against: for example:
  10. #
  11. # docker build -f docker/Dockerfile --build-arg PYTHON_VERSION=3.6 .
  12. #
  13. ARG PYTHON_VERSION=3.8
  14. ###
  15. ### Stage 0: builder
  16. ###
  17. FROM docker.io/python:${PYTHON_VERSION}-slim as builder
  18. LABEL org.opencontainers.image.url='https://matrix.org/docs/projects/server/synapse'
  19. LABEL org.opencontainers.image.documentation='https://github.com/matrix-org/synapse/blob/master/docker/README.md'
  20. LABEL org.opencontainers.image.source='https://github.com/matrix-org/synapse.git'
  21. LABEL org.opencontainers.image.licenses='Apache-2.0'
  22. # install the OS build deps
  23. RUN apt-get update && apt-get install -y \
  24. build-essential \
  25. libffi-dev \
  26. libjpeg-dev \
  27. libpq-dev \
  28. libssl-dev \
  29. libwebp-dev \
  30. libxml++2.6-dev \
  31. libxslt1-dev \
  32. openssl \
  33. rustc \
  34. zlib1g-dev \
  35. && rm -rf /var/lib/apt/lists/*
  36. # Copy just what we need to pip install
  37. COPY scripts /synapse/scripts/
  38. COPY MANIFEST.in README.rst setup.py synctl /synapse/
  39. COPY synapse/__init__.py /synapse/synapse/__init__.py
  40. COPY synapse/python_dependencies.py /synapse/synapse/python_dependencies.py
  41. # To speed up rebuilds, install all of the dependencies before we copy over
  42. # the whole synapse project so that we this layer in the Docker cache can be
  43. # used while you develop on the source
  44. #
  45. # This is aiming at installing the `install_requires` and `extras_require` from `setup.py`
  46. RUN pip install --prefix="/install" --no-warn-script-location \
  47. /synapse[all]
  48. # Copy over the rest of the project
  49. COPY synapse /synapse/synapse/
  50. # Install the synapse package itself and all of its children packages.
  51. #
  52. # This is aiming at installing only the `packages=find_packages(...)` from `setup.py
  53. RUN pip install --prefix="/install" --no-deps --no-warn-script-location /synapse
  54. ###
  55. ### Stage 1: runtime
  56. ###
  57. FROM docker.io/python:${PYTHON_VERSION}-slim
  58. RUN apt-get update && apt-get install -y \
  59. curl \
  60. gosu \
  61. libjpeg62-turbo \
  62. libpq5 \
  63. libwebp6 \
  64. xmlsec1 \
  65. libjemalloc2 \
  66. libssl-dev \
  67. openssl \
  68. && rm -rf /var/lib/apt/lists/*
  69. COPY --from=builder /install /usr/local
  70. COPY ./docker/start.py /start.py
  71. COPY ./docker/conf /conf
  72. VOLUME ["/data"]
  73. EXPOSE 8008/tcp 8009/tcp 8448/tcp
  74. ENTRYPOINT ["/start.py"]
  75. HEALTHCHECK --interval=1m --timeout=5s \
  76. CMD curl -fSs http://localhost:8008/health || exit 1