Dockerfile 3.3 KB

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