Dockerfile-dhvirtualenv 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. RUN mkdir /dh-virtualenv
  34. RUN wget -q -O /dh-virtualenv.tar.gz https://github.com/spotify/dh-virtualenv/archive/refs/tags/1.2.2.tar.gz
  35. RUN tar -xv --strip-components=1 -C /dh-virtualenv -f /dh-virtualenv.tar.gz
  36. # install its build deps. We do another apt-cache-update here, because we might
  37. # be using a stale cache from docker build.
  38. RUN apt-get update -qq -o Acquire::Languages=none \
  39. && cd /dh-virtualenv \
  40. && env DEBIAN_FRONTEND=noninteractive mk-build-deps -ri -t "apt-get -y --no-install-recommends"
  41. # Build it. Note that building the docs doesn't work due to differences in
  42. # Sphinx APIs across versions/distros.
  43. RUN cd /dh-virtualenv && DEB_BUILD_OPTIONS=nodoc dpkg-buildpackage -us -uc -b
  44. ###
  45. ### Stage 1
  46. ###
  47. FROM ${distro}
  48. # Get the distro we want to pull from as a dynamic build variable
  49. # (We need to define it in each build stage)
  50. ARG distro=""
  51. ENV distro ${distro}
  52. # Python < 3.7 assumes LANG="C" means ASCII-only and throws on printing unicode
  53. # http://bugs.python.org/issue19846
  54. ENV LANG C.UTF-8
  55. # Install the build dependencies
  56. #
  57. # NB: keep this list in sync with the list of build-deps in debian/control
  58. # TODO: it would be nice to do that automatically.
  59. RUN apt-get update -qq -o Acquire::Languages=none \
  60. && env DEBIAN_FRONTEND=noninteractive apt-get install \
  61. -yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io \
  62. build-essential \
  63. curl \
  64. debhelper \
  65. devscripts \
  66. libsystemd-dev \
  67. lsb-release \
  68. pkg-config \
  69. python3-dev \
  70. python3-pip \
  71. python3-setuptools \
  72. python3-venv \
  73. sqlite3 \
  74. libpq-dev \
  75. xmlsec1
  76. # Install rust and ensure it's in the PATH
  77. ENV RUSTUP_HOME=/rust
  78. ENV CARGO_HOME=/cargo
  79. ENV PATH=/cargo/bin:/rust/bin:$PATH
  80. RUN mkdir /rust /cargo
  81. RUN curl -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --default-toolchain stable
  82. COPY --from=builder /dh-virtualenv_1.2.2-1_all.deb /
  83. # install dhvirtualenv. Update the apt cache again first, in case we got a
  84. # cached cache from docker the first time.
  85. RUN apt-get update -qq -o Acquire::Languages=none \
  86. && apt-get install -yq /dh-virtualenv_1.2.2-1_all.deb
  87. WORKDIR /synapse/source
  88. ENTRYPOINT ["bash","/synapse/source/docker/build_debian.sh"]