Skip to content

Commit 1a6d5bf

Browse files
committedDec 20, 2018
Debian packaging via dh_virtualenv (#4285)
1 parent fd4070a commit 1a6d5bf

36 files changed

+310
-509
lines changed
 

‎.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ demo/etc
55
tox.ini
66
.git/*
77
.tox/*
8+
debian/matrix-synapse/
9+
debian/matrix-synapse-*/

‎.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ homeserver*.db
1818
homeserver*.log
1919
homeserver*.log.*
2020
homeserver*.pid
21-
homeserver*.yaml
21+
/homeserver*.yaml
2222

2323
*.signing.key
2424
*.tls.crt
2525
*.tls.dh
2626
*.tls.key
2727

2828
.coverage
29+
.coverage.*
30+
!.coverage.rc
2931
htmlcov
3032

3133
demo/*/*.db
@@ -57,3 +59,7 @@ env/
5759

5860
.vscode/
5961
.ropeproject/
62+
63+
*.deb
64+
65+
/debs

‎MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ prune demo/etc
3636
prune docker
3737
prune .circleci
3838
prune .coveragerc
39+
prune debian
3940

4041
exclude jenkins*
4142
recursive-exclude jenkins *.sh

‎changelog.d/4212.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Debian packages utilising a virtualenv with bundled dependencies can now be built.

‎debian/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/matrix-synapse-py3.*.debhelper
2+
/matrix-synapse-py3.debhelper.log
3+
/matrix-synapse-py3.substvars
4+
/matrix-synapse-*/
5+
/files
6+
/debhelper-build-stamp
7+
/.debhelper

‎debian/NEWS

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
matrix-synapse-py3 (0.34.0) stable; urgency=medium
2+
3+
matrix-synapse-py3 is intended as a drop-in replacement for the existing
4+
matrix-synapse package. The replacement should be relatively seamless,
5+
however, please note the following important differences to matrix-synapse:
6+
7+
* Most importantly, the matrix-synapse service now runs under Python 3 rather
8+
than Python 2.7.
9+
10+
* Synapse is installed into its own virtualenv (in /opt/venvs/matrix-synapse)
11+
instead of using the system python libraries. (This may mean that you can
12+
remove a number of old dependencies with `apt-get autoremove`).
13+
14+
matrix-synapse-py3 will take over responsibility for the existing
15+
configuration files, including the matrix-synapse systemd service.
16+
17+
Beware, however, that `apt-get purge matrix-synapse` will *disable* the
18+
matrix-synapse service (so that it will not be started on reboot), even
19+
though that service is no longer being provided by the matrix-synapse
20+
package. It can be re-enabled with `systemctl enable matrix-synapse`.
21+
22+
-- Richard van der Hoff <richard@matrix.org> Wed, 19 Dec 2018 14:00:00 +0000

‎debian/build_virtualenv

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
#
3+
# runs dh_virtualenv to build the virtualenv in the build directory,
4+
# and then runs the trial tests against the installed synapse.
5+
6+
set -e
7+
8+
export DH_VIRTUALENV_INSTALL_ROOT=/opt/venvs
9+
SNAKE=/usr/bin/python3
10+
11+
# try to set the CFLAGS so any compiled C extensions are compiled with the most
12+
# generic as possible x64 instructions, so that compiling it on a new Intel chip
13+
# doesn't enable features not available on older ones or AMD.
14+
#
15+
# TODO: add similar things for non-amd64, or figure out a more generic way to
16+
# do this.
17+
18+
case `dpkg-architecture -q DEB_HOST_ARCH` in
19+
amd64)
20+
export CFLAGS=-march=x86-64
21+
;;
22+
esac
23+
24+
# Use --builtin-venv to use the better `venv` module from CPython 3.4+ rather
25+
# than the 2/3 compatible `virtualenv`.
26+
27+
dh_virtualenv \
28+
--install-suffix "matrix-synapse" \
29+
--builtin-venv \
30+
--setuptools \
31+
--python "$SNAKE" \
32+
--upgrade-pip \
33+
--preinstall="lxml" \
34+
--preinstall="mock" \
35+
--extra-pip-arg="--no-cache-dir" \
36+
--extra-pip-arg="--compile"
37+
38+
# we copy the tests to a temporary directory so that we can put them on the
39+
# PYTHONPATH without putting the uninstalled synapse on the pythonpath.
40+
tmpdir=`mktemp -d`
41+
trap "rm -r $tmpdir" EXIT
42+
43+
cp -r tests "$tmpdir"
44+
cd debian/matrix-synapse-py3
45+
46+
PYTHONPATH="$tmpdir" \
47+
./opt/venvs/matrix-synapse/bin/python \
48+
-B -m twisted.trial --reporter=text -j2 tests

‎debian/changelog

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
matrix-synapse-py3 (0.34.0) stable; urgency=medium
2+
3+
* New synapse release 0.34.0.
4+
* Synapse is now installed into a Python 3 virtual environment with
5+
up-to-date dependencies.
6+
* The matrix-synapse service will now be restarted when the package is
7+
upgraded.
8+
(Fixes https://github.com/matrix-org/package-synapse-debian/issues/18)
9+
10+
-- Synapse packaging team <packages@matrix.org> Wed, 19 Dec 2018 14:00:00 +0000
11+
112
matrix-synapse (0.33.9-1matrix1) stretch; urgency=medium
213

314
[ Erik Johnston ]

‎debian/control

+26-66
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,37 @@
1-
Source: matrix-synapse
2-
Maintainer: Erik Johnston <erikj@matrix.org>
3-
Section: python
4-
Priority: optional
1+
Source: matrix-synapse-py3
2+
Section: contrib/python
3+
Priority: extra
4+
Maintainer: Synapse Packaging team <packages@matrix.org>
55
Build-Depends:
66
debhelper (>= 9),
7-
dh-python,
8-
dh-systemd (>= 1.5),
9-
po-debconf,
10-
python (>= 2.6.6-3),
11-
python-bcrypt,
12-
python-blist,
13-
python-canonicaljson (>=1.1.3),
14-
python-daemonize,
15-
python-frozendict (>= 0.4),
16-
python-lxml,
17-
python-mock,
18-
python-msgpack (>=0.3.0),
19-
python-nacl (>= 0.3.0),
20-
python-netaddr,
21-
python-openssl (>= 0.14),
22-
python-pil,
23-
python-psutil,
24-
python-pyasn1,
25-
python-pydenticon,
26-
python-pymacaroons-pynacl,
27-
python-pysaml2,
28-
python-service-identity (>= 1.0.0),
29-
python-setuptools (>= 0.6b3),
30-
python-signedjson (>= 1.0.0),
31-
python-sortedcontainers,
32-
python-syutil (>= 0.0.7),
33-
python-treq (>= 15.1.0),
34-
python-twisted (>= 17.1.0),
35-
python-unpaddedbase64 (>= 1.0.1),
36-
python-yaml,
37-
python-phonenumbers (>= 8.2.0),
38-
python-jsonschema (>=2.5.1),
39-
python-prometheus-client,
40-
python-attr
41-
Standards-Version: 3.9.8
42-
X-Python-Version: >= 2.7
7+
dh-systemd,
8+
dh-virtualenv (>= 1.0),
9+
lsb-release,
10+
python3-dev,
11+
python3,
12+
python3-setuptools,
13+
python3-pip,
14+
python3-venv,
15+
tar,
16+
Standards-Version: 3.9.5
17+
Homepage: https://github.com/matrix-org/synapse
4318

44-
Package: matrix-synapse
45-
Architecture: all
19+
Package: matrix-synapse-py3
20+
Architecture: amd64
21+
Conflicts: matrix-synapse
22+
Pre-Depends: dpkg (>= 1.16.1)
4623
Depends:
47-
${misc:Depends},
48-
${python:Depends},
4924
adduser,
5025
debconf,
51-
lsb-base (>= 3.0-6),
52-
python-attr (>= 16.0.0),
53-
python-twisted (>= 17.1.0),
54-
python-canonicaljson (>=1.1.3),
55-
python-prometheus-client (>=0.0.14),
26+
python3-distutils|libpython3-stdlib (<< 3.6),
27+
python3,
28+
${misc:Depends},
29+
# some of our scripts use perl, but none of them are important,
30+
# so we put perl:Depends in Suggests rather than Depends.
5631
Suggests:
57-
python-bleach (>= 1.4.2),
58-
python-jinja2 (>= 2.8),
59-
Recommends:
60-
python-psycopg2,
61-
python-lxml,
32+
sqlite3,
33+
${perl:Depends},
6234
Description: Open federated Instant Messaging and VoIP server
6335
Matrix is an ambitious new ecosystem for open federated Instant
6436
Messaging and VoIP. Synapse is a reference Matrix server
6537
implementation.
66-
.
67-
Everything in Matrix happens in a room. Rooms are distributed and do
68-
not exist on any single server. Rooms can be located using
69-
convenience aliases like #matrix:matrix.org or #test:localhost:8448.
70-
.
71-
Matrix user IDs look like @matthew:matrix.org (although in the future
72-
you will normally refer to yourself and others using a 3PID: email
73-
address, phone number, etc rather than manipulating Matrix user IDs)
74-
.
75-
The overall architecture is:
76-
client <------> homeserver <=============> homeserver <------> client
77-
https://a.org/_matrix https://b.net/_matrix

‎debian/copyright

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Upstream-Name: synapse
33
Source: https://github.com/matrix-org/synapse
44

55
Files: *
6-
Copyright: 2014-2017, OpenMarket Ltd
6+
Copyright: 2014-2017, OpenMarket Ltd, 2017-2018 New Vector Ltd
77
License: Apache-2.0
88

99
Files: synapse/config/saml2.py

‎debian/gbp.conf

-5
This file was deleted.

‎debian/homeserver.yaml

+3-7
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,9 @@ pid_file: "/var/run/matrix-synapse.pid"
7070
#
7171
# cpu_affinity: 0xFFFFFFFF
7272

73-
# Whether to serve a web client from the HTTP/HTTPS root resource.
74-
web_client: False
75-
76-
# The root directory to server for the above web client.
77-
# If left undefined, synapse will serve the matrix-angular-sdk web client.
78-
# Make sure matrix-angular-sdk is installed with pip if web_client is True
79-
# and web_client_location is undefined
73+
# The path to the web client which will be served at /_matrix/client/
74+
# if 'webclient' is configured under the 'listeners' configuration.
75+
#
8076
# web_client_location: "/path/to/web/root"
8177

8278
# The public-facing base URL for the client API (not including _matrix/...)

‎debian/matrix-synapse-py3.links

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
opt/venvs/matrix-synapse/bin/hash_password usr/bin/hash_password
2+
opt/venvs/matrix-synapse/bin/register_new_matrix_user usr/bin/register_new_matrix_user
3+
opt/venvs/matrix-synapse/bin/synapse_port_db usr/bin/synapse_port_db
4+
opt/venvs/matrix-synapse/bin/synctl usr/bin/synctl
File renamed without changes.

‎debian/matrix-synapse-py3.preinst

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh -e
2+
3+
# Attempt to undo some of the braindamage caused by
4+
# https://github.com/matrix-org/package-synapse-debian/issues/18.
5+
#
6+
# Due to reasons [1], the old python2 matrix-synapse package will not stop the
7+
# service when the package is uninstalled. Our maintainer scripts will do the
8+
# right thing in terms of ensuring the service is enabled and unmasked, but
9+
# then do a `systemctl start matrix-synapse`, which of course does nothing -
10+
# leaving the old (py2) service running.
11+
#
12+
# There should normally be no reason for the service to be running during our
13+
# preinst, so we assume that if it *is* running, it's due to that situation,
14+
# and stop it.
15+
#
16+
# [1] dh_systemd_start doesn't do anything because it sees that there is an
17+
# init.d script with the same name, so leaves it to dh_installinit.
18+
#
19+
# dh_installinit doesn't do anything because somebody gave it a --no-start
20+
# for unknown reasons.
21+
22+
if [ -x /bin/systemctl ]; then
23+
if /bin/systemctl --quiet is-active -- matrix-synapse; then
24+
echo >&2 "stopping existing matrix-synapse service"
25+
/bin/systemctl stop matrix-synapse || true
26+
fi
27+
fi
28+
29+
#DEBHELPER#
30+
31+
exit 0

‎debian/matrix-synapse-py3.triggers

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Register interest in Python interpreter changes and
2+
# don't make the Python package dependent on the virtualenv package
3+
# processing (noawait)
4+
interest-noawait /usr/bin/python3.5
5+
interest-noawait /usr/bin/python3.6
6+
interest-noawait /usr/bin/python3.7
7+
8+
# Also provide a symbolic trigger for all dh-virtualenv packages
9+
interest dh-virtualenv-interpreter-update

‎debian/matrix-synapse.init

-184
This file was deleted.

‎debian/matrix-synapse.service

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Type=simple
66
User=matrix-synapse
77
WorkingDirectory=/var/lib/matrix-synapse
88
EnvironmentFile=/etc/default/matrix-synapse
9-
ExecStartPre=/usr/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse/conf.d/ --generate-keys
10-
ExecStart=/usr/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse/conf.d/
9+
ExecStartPre=/opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse/conf.d/ --generate-keys
10+
ExecStart=/opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse/conf.d/
1111
Restart=always
1212
RestartSec=3
1313

‎debian/patches/0001-tox.patch

-19
This file was deleted.

‎debian/patches/0002-change_instructions.patch

-34
This file was deleted.

‎debian/patches/0004-webclient-instructions.patch

-27
This file was deleted.

‎debian/patches/0006-Don-t-require-strict-nacl-0.3.0-requirement.patch

-21
This file was deleted.

‎debian/patches/bcrypt.patch

-30
This file was deleted.

‎debian/patches/no_install_with_pip

-43
This file was deleted.

‎debian/patches/remove-webclient.patch

-31
This file was deleted.

‎debian/patches/series

-7
This file was deleted.

‎debian/pydist-overrides

-5
This file was deleted.

‎debian/rules

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
#!/usr/bin/make -f
2+
#
3+
# Build Debian package using https://github.com/spotify/dh-virtualenv
4+
#
25

3-
# This file was automatically generated by stdeb 0.8.2 at
4-
# Fri, 12 Jun 2015 14:32:03 +0100
5-
export PYBUILD_NAME=matrix-synapse
6-
%:
7-
dh $@ --with python2 --with systemd --buildsystem=pybuild --no-guessing-deps
6+
override_dh_systemd_enable:
7+
dh_systemd_enable --name=matrix-synapse
88

9-
override_dh_auto_install:
10-
python setup.py install --root=debian/matrix-synapse --install-layout=deb
9+
override_dh_installinit:
10+
dh_installinit --name=matrix-synapse
1111

12-
override_dh_auto_build:
12+
override_dh_strip:
1313

14-
override_dh_installinit:
15-
dh_installinit --no-start
14+
override_dh_shlibdeps:
1615

17-
override_dh_auto_test:
18-
PYTHONPATH=. trial tests
16+
override_dh_virtualenv:
17+
./debian/build_virtualenv
18+
19+
# We are restricted to compat level 9 (because xenial), so have to
20+
# enable the systemd bits manually.
21+
%:
22+
dh $@ --with python-virtualenv --with systemd

‎debian/source/format

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0 (quilt)
1+
3.0 (native)

‎debian/watch

-11
This file was deleted.

‎docker/Dockerfile-dhvirtualenv

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
12+
# Get the distro we want to pull from as a dynamic build variable
13+
ARG distro=""
14+
FROM ${distro}
15+
16+
# Install the build dependencies
17+
RUN apt-get update -qq -o Acquire::Languages=none \
18+
&& env DEBIAN_FRONTEND=noninteractive apt-get install \
19+
-yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io \
20+
build-essential \
21+
debhelper \
22+
devscripts \
23+
dh-systemd \
24+
dh-virtualenv \
25+
equivs \
26+
lsb-release \
27+
python3-dev \
28+
python3-pip \
29+
python3-setuptools \
30+
python3-venv \
31+
sqlite3 \
32+
wget
33+
34+
WORKDIR /synapse/source
35+
ENTRYPOINT ["bash","/synapse/source/docker/build_debian.sh"]

‎docker/build_debian.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# The script to build the Debian package, as ran inside the Docker image.
4+
5+
set -ex
6+
7+
DIST=`lsb_release -c -s`
8+
9+
# We need to build a newer dh_virtualenv on older OSes like Xenial.
10+
if [ "$DIST" = 'xenial' ]; then
11+
mkdir -p /tmp/dhvenv
12+
cd /tmp/dhvenv
13+
wget https://github.com/spotify/dh-virtualenv/archive/1.1.tar.gz
14+
tar xvf 1.1.tar.gz
15+
cd dh-virtualenv-1.1/
16+
env DEBIAN_FRONTEND=noninteractive mk-build-deps -ri -t "apt-get -yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io"
17+
dpkg-buildpackage -us -uc -b
18+
cd /tmp/dhvenv
19+
apt-get install -yqq ./dh-virtualenv_1.1-1_all.deb
20+
fi
21+
22+
23+
# we get a read-only copy of the source: make a writeable copy
24+
cp -aT /synapse/source /synapse/build
25+
cd /synapse/build
26+
27+
# add an entry to the changelog for this distribution
28+
dch -M -l "+$DIST" "build for $DIST"
29+
dch -M -r "" --force-distribution --distribution "$DIST"
30+
31+
dpkg-buildpackage -us -uc
32+
33+
ls -l ..
34+
35+
# copy the build results out, setting perms if necessary
36+
shopt -s nullglob
37+
for i in ../*.deb ../*.dsc ../*.tar.xz ../*.changes ../*.buildinfo; do
38+
[ -z "$TARGET_USERID" ] || chown "$TARGET_USERID" "$i"
39+
[ -z "$TARGET_GROUPID" ] || chgrp "$TARGET_GROUPID" "$i"
40+
mv "$i" /debs
41+
done

‎docker/build_debian_packages.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Build the Debian packages using Docker images.
4+
#
5+
# This script builds the Docker images and then executes them sequentially, each
6+
# one building a Debian package for the targeted operating system. It is
7+
# designed to be a "single command" to produce all the images.
8+
#
9+
# By default, builds for all known distributions, but a list of distributions
10+
# can be passed on the commandline for debugging.
11+
12+
set -ex
13+
14+
cd `dirname $0`
15+
16+
if [ $# -lt 1 ]; then
17+
DISTS=(debian:stretch debian:sid ubuntu:xenial ubuntu:bionic ubuntu:cosmic)
18+
else
19+
DISTS=("$@")
20+
fi
21+
22+
# Make the dir where the debs will live.
23+
#
24+
# Note that we deliberately put this outside the source tree, otherwise we tend
25+
# to get source packages which are full of debs. (We could hack around that
26+
# with more magic in the build_debian.sh script, but that doesn't solve the
27+
# problem for natively-run dpkg-buildpakage).
28+
29+
mkdir -p ../../debs
30+
31+
# Build each OS image;
32+
for i in "${DISTS[@]}"; do
33+
TAG=$(echo ${i} | cut -d ":" -f 2)
34+
docker build --tag dh-venv-builder:${TAG} --build-arg distro=${i} -f Dockerfile-dhvirtualenv .
35+
docker run -it --rm --volume=$(pwd)/../\:/synapse/source:ro --volume=$(pwd)/../../debs:/debs \
36+
-e TARGET_USERID=$(id -u) \
37+
-e TARGET_GROUPID=$(id -g) \
38+
dh-venv-builder:${TAG}
39+
done

‎synapse/python_dependencies.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
},
7979
"postgres": {
8080
"psycopg2>=2.6": ["psycopg2"]
81-
}
81+
},
8282
}
8383

8484

‎synapse/storage/e2e_room_keys.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def delete_e2e_room_keys(
182182

183183
keyvalues = {
184184
"user_id": user_id,
185-
"version": version,
185+
"version": int(version),
186186
}
187187
if room_id:
188188
keyvalues['room_id'] = room_id

‎tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ setenv =
119119

120120

121121
[testenv:packaging]
122+
skip_install=True
122123
deps =
123124
check-manifest
124125
commands =

0 commit comments

Comments
 (0)
Please sign in to comment.