Dockerfile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.9 .
  15. #
  16. ARG PYTHON_VERSION=3.8
  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 scripts /synapse/scripts/
  46. COPY MANIFEST.in README.rst setup.py synctl /synapse/
  47. COPY synapse/__init__.py /synapse/synapse/__init__.py
  48. COPY synapse/python_dependencies.py /synapse/synapse/python_dependencies.py
  49. # To speed up rebuilds, install all of the dependencies before we copy over
  50. # the whole synapse project so that we this layer in the Docker cache can be
  51. # used while you develop on the source
  52. #
  53. # This is aiming at installing the `install_requires` and `extras_require` from `setup.py`
  54. RUN --mount=type=cache,target=/root/.cache/pip \
  55. pip install --prefix="/install" --no-warn-script-location \
  56. /synapse[all]
  57. # Copy over the rest of the project
  58. COPY synapse /synapse/synapse/
  59. # Install the synapse package itself and all of its children packages.
  60. #
  61. # This is aiming at installing only the `packages=find_packages(...)` from `setup.py
  62. RUN pip install --prefix="/install" --no-deps --no-warn-script-location /synapse
  63. ###
  64. ### Stage 1: runtime
  65. ###
  66. FROM docker.io/python:${PYTHON_VERSION}-slim
  67. LABEL org.opencontainers.image.url='https://matrix.org/docs/projects/server/synapse'
  68. LABEL org.opencontainers.image.documentation='https://github.com/matrix-org/synapse/blob/master/docker/README.md'
  69. LABEL org.opencontainers.image.source='https://github.com/matrix-org/synapse.git'
  70. LABEL org.opencontainers.image.licenses='Apache-2.0'
  71. RUN \
  72. --mount=type=cache,target=/var/cache/apt,sharing=locked \
  73. --mount=type=cache,target=/var/lib/apt,sharing=locked \
  74. apt-get update && apt-get install -y \
  75. curl \
  76. gosu \
  77. libjpeg62-turbo \
  78. libpq5 \
  79. libwebp6 \
  80. xmlsec1 \
  81. libjemalloc2 \
  82. libssl-dev \
  83. openssl \
  84. && rm -rf /var/lib/apt/lists/*
  85. COPY --from=builder /install /usr/local
  86. COPY ./docker/start.py /start.py
  87. COPY ./docker/conf /conf
  88. VOLUME ["/data"]
  89. EXPOSE 8008/tcp 8009/tcp 8448/tcp
  90. ENTRYPOINT ["/start.py"]
  91. HEALTHCHECK --start-period=5s --interval=15s --timeout=5s \
  92. CMD curl -fSs http://localhost:8008/health || exit 1