Dockerfile-dhvirtualenv 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 bionic and 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. # TODO: Upgrade to 1.2.2 once bionic is dropped (1.2.2 requires debhelper 12; bionic has only 11)
  34. RUN mkdir /dh-virtualenv
  35. RUN wget -q -O /dh-virtualenv.tar.gz https://github.com/spotify/dh-virtualenv/archive/ac6e1b1.tar.gz
  36. RUN tar -xv --strip-components=1 -C /dh-virtualenv -f /dh-virtualenv.tar.gz
  37. # install its build deps. We do another apt-cache-update here, because we might
  38. # be using a stale cache from docker build.
  39. RUN apt-get update -qq -o Acquire::Languages=none \
  40. && cd /dh-virtualenv \
  41. && env DEBIAN_FRONTEND=noninteractive mk-build-deps -ri -t "apt-get -y --no-install-recommends"
  42. # Build it. Note that building the docs doesn't work due to differences in
  43. # Sphinx APIs across versions/distros.
  44. RUN cd /dh-virtualenv && DEB_BUILD_OPTIONS=nodoc dpkg-buildpackage -us -uc -b
  45. ###
  46. ### Stage 1
  47. ###
  48. FROM ${distro}
  49. # Get the distro we want to pull from as a dynamic build variable
  50. # (We need to define it in each build stage)
  51. ARG distro=""
  52. ENV distro ${distro}
  53. # Python < 3.7 assumes LANG="C" means ASCII-only and throws on printing unicode
  54. # http://bugs.python.org/issue19846
  55. ENV LANG C.UTF-8
  56. # Install the build dependencies
  57. #
  58. # NB: keep this list in sync with the list of build-deps in debian/control
  59. # TODO: it would be nice to do that automatically.
  60. RUN apt-get update -qq -o Acquire::Languages=none \
  61. && env DEBIAN_FRONTEND=noninteractive apt-get install \
  62. -yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io \
  63. build-essential \
  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. COPY --from=builder /dh-virtualenv_1.2~dev-1_all.deb /
  77. # install dhvirtualenv. Update the apt cache again first, in case we got a
  78. # cached cache from docker the first time.
  79. RUN apt-get update -qq -o Acquire::Languages=none \
  80. && apt-get install -yq /dh-virtualenv_1.2~dev-1_all.deb
  81. WORKDIR /synapse/source
  82. ENTRYPOINT ["bash","/synapse/source/docker/build_debian.sh"]