From 1a6d5bfa08b4ba618dcab68e4ed524c4db07da2b Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 20 Dec 2018 11:33:29 +0000 Subject: Debian packaging via dh_virtualenv (#4285) --- docker/Dockerfile-dhvirtualenv | 35 +++++++++++++++++++++++++++++++++++ docker/build_debian.sh | 41 +++++++++++++++++++++++++++++++++++++++++ docker/build_debian_packages.sh | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 docker/Dockerfile-dhvirtualenv create mode 100644 docker/build_debian.sh create mode 100755 docker/build_debian_packages.sh (limited to 'docker') diff --git a/docker/Dockerfile-dhvirtualenv b/docker/Dockerfile-dhvirtualenv new file mode 100644 index 0000000000..ea6b650af2 --- /dev/null +++ b/docker/Dockerfile-dhvirtualenv @@ -0,0 +1,35 @@ +# A dockerfile which builds a docker image for building a debian package for +# synapse. The distro to build for is passed as a docker build var. +# +# The default entrypoint expects the synapse source to be mounted as a +# (read-only) volume at /synapse/source, and an output directory at /debs. +# +# A pair of environment variables (TARGET_USERID and TARGET_GROUPID) can be +# passed to the docker container; if these are set, the build script will chown +# the build products accordingly, to avoid ending up with things owned by root +# in the host filesystem. + +# Get the distro we want to pull from as a dynamic build variable +ARG distro="" +FROM ${distro} + +# Install the build dependencies +RUN apt-get update -qq -o Acquire::Languages=none \ + && env DEBIAN_FRONTEND=noninteractive apt-get install \ + -yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io \ + build-essential \ + debhelper \ + devscripts \ + dh-systemd \ + dh-virtualenv \ + equivs \ + lsb-release \ + python3-dev \ + python3-pip \ + python3-setuptools \ + python3-venv \ + sqlite3 \ + wget + +WORKDIR /synapse/source +ENTRYPOINT ["bash","/synapse/source/docker/build_debian.sh"] diff --git a/docker/build_debian.sh b/docker/build_debian.sh new file mode 100644 index 0000000000..cea5067fe9 --- /dev/null +++ b/docker/build_debian.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# The script to build the Debian package, as ran inside the Docker image. + +set -ex + +DIST=`lsb_release -c -s` + +# We need to build a newer dh_virtualenv on older OSes like Xenial. +if [ "$DIST" = 'xenial' ]; then + mkdir -p /tmp/dhvenv + cd /tmp/dhvenv + wget https://github.com/spotify/dh-virtualenv/archive/1.1.tar.gz + tar xvf 1.1.tar.gz + cd dh-virtualenv-1.1/ + env DEBIAN_FRONTEND=noninteractive mk-build-deps -ri -t "apt-get -yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io" + dpkg-buildpackage -us -uc -b + cd /tmp/dhvenv + apt-get install -yqq ./dh-virtualenv_1.1-1_all.deb +fi + + +# we get a read-only copy of the source: make a writeable copy +cp -aT /synapse/source /synapse/build +cd /synapse/build + +# add an entry to the changelog for this distribution +dch -M -l "+$DIST" "build for $DIST" +dch -M -r "" --force-distribution --distribution "$DIST" + +dpkg-buildpackage -us -uc + +ls -l .. + +# copy the build results out, setting perms if necessary +shopt -s nullglob +for i in ../*.deb ../*.dsc ../*.tar.xz ../*.changes ../*.buildinfo; do + [ -z "$TARGET_USERID" ] || chown "$TARGET_USERID" "$i" + [ -z "$TARGET_GROUPID" ] || chgrp "$TARGET_GROUPID" "$i" + mv "$i" /debs +done diff --git a/docker/build_debian_packages.sh b/docker/build_debian_packages.sh new file mode 100755 index 0000000000..eafed4ac41 --- /dev/null +++ b/docker/build_debian_packages.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Build the Debian packages using Docker images. +# +# This script builds the Docker images and then executes them sequentially, each +# one building a Debian package for the targeted operating system. It is +# designed to be a "single command" to produce all the images. +# +# By default, builds for all known distributions, but a list of distributions +# can be passed on the commandline for debugging. + +set -ex + +cd `dirname $0` + +if [ $# -lt 1 ]; then + DISTS=(debian:stretch debian:sid ubuntu:xenial ubuntu:bionic ubuntu:cosmic) +else + DISTS=("$@") +fi + +# Make the dir where the debs will live. +# +# Note that we deliberately put this outside the source tree, otherwise we tend +# to get source packages which are full of debs. (We could hack around that +# with more magic in the build_debian.sh script, but that doesn't solve the +# problem for natively-run dpkg-buildpakage). + +mkdir -p ../../debs + +# Build each OS image; +for i in "${DISTS[@]}"; do + TAG=$(echo ${i} | cut -d ":" -f 2) + docker build --tag dh-venv-builder:${TAG} --build-arg distro=${i} -f Dockerfile-dhvirtualenv . + docker run -it --rm --volume=$(pwd)/../\:/synapse/source:ro --volume=$(pwd)/../../debs:/debs \ + -e TARGET_USERID=$(id -u) \ + -e TARGET_GROUPID=$(id -g) \ + dh-venv-builder:${TAG} +done -- cgit 1.4.1