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. # install the OS build deps
  19. RUN apt-get update && apt-get install -y \
  20. build-essential \
  21. libffi-dev \
  22. libjpeg-dev \
  23. libpq-dev \
  24. libssl-dev \
  25. libwebp-dev \
  26. libxml++2.6-dev \
  27. libxslt1-dev \
  28. openssl \
  29. rustc \
  30. zlib1g-dev \
  31. && rm -rf /var/lib/apt/lists/*
  32. # Copy just what we need to pip install
  33. COPY scripts /synapse/scripts/
  34. COPY MANIFEST.in README.rst setup.py synctl /synapse/
  35. COPY synapse/__init__.py /synapse/synapse/__init__.py
  36. COPY synapse/python_dependencies.py /synapse/synapse/python_dependencies.py
  37. # To speed up rebuilds, install all of the dependencies before we copy over
  38. # the whole synapse project so that we this layer in the Docker cache can be
  39. # used while you develop on the source
  40. #
  41. # This is aiming at installing the `install_requires` and `extras_require` from `setup.py`
  42. RUN pip install --prefix="/install" --no-warn-script-location \
  43. /synapse[all]
  44. # Copy over the rest of the project
  45. COPY synapse /synapse/synapse/
  46. # Install the synapse package itself and all of its children packages.
  47. #
  48. # This is aiming at installing only the `packages=find_packages(...)` from `setup.py
  49. RUN pip install --prefix="/install" --no-deps --no-warn-script-location /synapse
  50. ###
  51. ### Stage 1: runtime
  52. ###
  53. FROM docker.io/python:${PYTHON_VERSION}-slim
  54. LABEL org.opencontainers.image.url='https://matrix.org/docs/projects/server/synapse'
  55. LABEL org.opencontainers.image.documentation='https://github.com/matrix-org/synapse/blob/master/docker/README.md'
  56. LABEL org.opencontainers.image.source='https://github.com/matrix-org/synapse.git'
  57. LABEL org.opencontainers.image.licenses='Apache-2.0'
  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 --start-period=5s --interval=15s --timeout=5s \
  76. CMD curl -fSs http://localhost:8008/health || exit 1