Dockerfile-dhvirtualenv 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # A dockerfile which builds a docker image for building a debian package for
  2. # synapse. The distro to build for is passed as a docker build var.
  3. #
  4. # The default entrypoint expects the synapse source to be mounted as a
  5. # (read-only) volume at /synapse/source, and an output directory at /debs.
  6. #
  7. # A pair of environment variables (TARGET_USERID and TARGET_GROUPID) can be
  8. # passed to the docker container; if these are set, the build script will chown
  9. # the build products accordingly, to avoid ending up with things owned by root
  10. # in the host filesystem.
  11. # Get the distro we want to pull from as a dynamic build variable
  12. ARG distro=""
  13. ###
  14. ### Stage 0: build a dh-virtualenv
  15. ###
  16. # This is only really needed on focal, since other distributions we
  17. # care about have a recent version of dh-virtualenv by default. Unfortunately,
  18. # it looks like focal is going to be with us for a while.
  19. #
  20. # (focal doesn't have a dh-virtualenv package at all. There is a PPA at
  21. # https://launchpad.net/~jyrki-pulliainen/+archive/ubuntu/dh-virtualenv, but
  22. # it's not obviously easier to use that than to build our own.)
  23. FROM ${distro} as builder
  24. RUN apt-get update -qq -o Acquire::Languages=none
  25. RUN env DEBIAN_FRONTEND=noninteractive apt-get install \
  26. -yqq --no-install-recommends \
  27. build-essential \
  28. ca-certificates \
  29. devscripts \
  30. equivs \
  31. wget
  32. # fetch and unpack the package
  33. # We are temporarily using a fork of dh-virtualenv due to an incompatibility with Python 3.11, which ships with
  34. # Debian sid. TODO: Switch back to upstream once https://github.com/spotify/dh-virtualenv/pull/354 has merged.
  35. RUN mkdir /dh-virtualenv
  36. RUN wget -q -O /dh-virtualenv.tar.gz https://github.com/matrix-org/dh-virtualenv/archive/refs/tags/matrixorg-2023010302.tar.gz
  37. RUN tar -xv --strip-components=1 -C /dh-virtualenv -f /dh-virtualenv.tar.gz
  38. # install its build deps. We do another apt-cache-update here, because we might
  39. # be using a stale cache from docker build.
  40. RUN apt-get update -qq -o Acquire::Languages=none \
  41. && cd /dh-virtualenv \
  42. && env DEBIAN_FRONTEND=noninteractive mk-build-deps -ri -t "apt-get -y --no-install-recommends"
  43. # Build it. Note that building the docs doesn't work due to differences in
  44. # Sphinx APIs across versions/distros.
  45. RUN cd /dh-virtualenv && DEB_BUILD_OPTIONS=nodoc dpkg-buildpackage -us -uc -b
  46. ###
  47. ### Stage 1
  48. ###
  49. FROM ${distro}
  50. # Get the distro we want to pull from as a dynamic build variable
  51. # (We need to define it in each build stage)
  52. ARG distro=""
  53. ENV distro ${distro}
  54. # Python < 3.7 assumes LANG="C" means ASCII-only and throws on printing unicode
  55. # http://bugs.python.org/issue19846
  56. ENV LANG C.UTF-8
  57. # Install the build dependencies
  58. #
  59. # NB: keep this list in sync with the list of build-deps in debian/control
  60. # TODO: it would be nice to do that automatically.
  61. RUN apt-get update -qq -o Acquire::Languages=none \
  62. && env DEBIAN_FRONTEND=noninteractive apt-get install \
  63. -yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io \
  64. build-essential \
  65. curl \
  66. debhelper \
  67. devscripts \
  68. libsystemd-dev \
  69. lsb-release \
  70. pkg-config \
  71. python3-dev \
  72. python3-pip \
  73. python3-setuptools \
  74. python3-venv \
  75. sqlite3 \
  76. libpq-dev \
  77. libicu-dev \
  78. pkg-config \
  79. xmlsec1
  80. # Install rust and ensure it's in the PATH
  81. ENV RUSTUP_HOME=/rust
  82. ENV CARGO_HOME=/cargo
  83. ENV PATH=/cargo/bin:/rust/bin:$PATH
  84. RUN mkdir /rust /cargo
  85. RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain stable --profile minimal
  86. COPY --from=builder /dh-virtualenv_1.2.2-1_all.deb /
  87. # install dhvirtualenv. Update the apt cache again first, in case we got a
  88. # cached cache from docker the first time.
  89. RUN apt-get update -qq -o Acquire::Languages=none \
  90. && apt-get install -yq /dh-virtualenv_1.2.2-1_all.deb
  91. WORKDIR /synapse/source
  92. ENTRYPOINT ["bash","/synapse/source/docker/build_debian.sh"]