Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
156 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.git/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
*~ | ||
.*.swp | ||
/.synapse-base | ||
/localhost-* | ||
/server-* | ||
/logs/ | ||
/media_store | ||
/.synapse-base | ||
/results.tap | ||
/server-* | ||
/synapse | ||
/var | ||
\#* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,31 @@ | ||
FROM ubuntu:14.04 | ||
FROM debian:stretch | ||
|
||
ENV PERL5LIB=$HOME/lib/perl5 | ||
ENV PERL_MB_OPT=--install_base=$HOME | ||
ENV PERL_MM_OPT=INSTALL_BASE=$HOME | ||
ENV DEBIAN_FRONTEND=noninteractive | ||
ENV DEBIAN_FRONTEND noninteractive | ||
|
||
ADD MyConfig.pm /root/.cpan/CPAN/MyConfig.pm | ||
# Install base dependencies that Python or Go would require | ||
RUN apt-get -qq update | ||
RUN apt-get -qq install -y build-essential perl wget postgresql postgresql-client libpq-dev libssl-dev libz-dev libffi-dev sqlite3 libjpeg-dev libxslt1-dev git locales | ||
|
||
RUN apt-get update \ | ||
&& apt-get upgrade -y \ | ||
&& apt-get install -y \ | ||
build-essential \ | ||
python2.7-dev \ | ||
libffi-dev \ | ||
python-pip \ | ||
python-setuptools \ | ||
sqlite3 \ | ||
libssl-dev \ | ||
python-virtualenv \ | ||
libjpeg-dev \ | ||
libxslt1-dev \ | ||
git \ | ||
postgresql \ | ||
libpq-dev \ | ||
&& cd /root \ | ||
&& git clone https://github.com/matrix-org/sytest \ | ||
&& git clone https://github.com/matrix-org/synapse \ | ||
&& pip install --upgrade setuptools \ | ||
&& mkdir -p /root/.cpan/CPAN \ | ||
&& cd /root/sytest \ | ||
&& ./install-deps.pl \ | ||
&& cd ../synapse \ | ||
&& git checkout develop \ | ||
&& python synapse/python_dependencies.py | xargs -n1 pip install \ | ||
&& pip install lxml \ | ||
&& python setup.py develop --user \ | ||
&& python setup.py test | ||
# Set up the locales, as the default Debian image only has C, and PostgreSQL needs the correct locales to make a UTF-8 database | ||
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ | ||
dpkg-reconfigure --frontend=noninteractive locales && \ | ||
update-locale LANG=en_US.UTF-8 | ||
|
||
WORKDIR /root/sytest | ||
# Set the locales in the environment | ||
ENV LANG en_US.UTF-8 | ||
ENV LANGUAGE en_US:en | ||
ENV LC_ALL en_US.UTF-8 | ||
|
||
# Copy in the sytest dependencies and install them | ||
# The dockerfile context, when run by the buildscript, will actually be the | ||
# repo root, not the docker folder | ||
ADD install-deps.pl ./install-deps.pl | ||
ADD cpanfile ./cpanfile | ||
RUN perl ./install-deps.pl | ||
RUN rm cpanfile install-deps.pl | ||
|
||
# /logs is where we should expect logs to end up | ||
RUN mkdir /logs | ||
# /test is where sytest will live | ||
RUN mkdir /test | ||
WORKDIR /test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM matrixdotorg/sytest:latest | ||
|
||
RUN apt-get -qq install -y python python-dev python-virtualenv | ||
|
||
ENV PYTHON=python2 | ||
|
||
# /src is where we expect Synapse to be | ||
RUN mkdir /src | ||
|
||
# The dockerfile context, when ran by the buildscript, will actually be the | ||
# repo root, not the docker folder | ||
ADD docker/synapse_sytest.sh /synapse_sytest.sh | ||
ENTRYPOINT /synapse_sytest.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM matrixdotorg/sytest:latest | ||
|
||
RUN apt-get -qq install -y python3 python3-dev python3-virtualenv | ||
|
||
ENV PYTHON=python3 | ||
|
||
# /src is where we expect Synapse to be | ||
RUN mkdir /src | ||
|
||
# The dockerfile context, when ran by the buildscript, will actually be the | ||
# repo root, not the docker folder | ||
ADD docker/synapse_sytest.sh /synapse_sytest.sh | ||
ENTRYPOINT /synapse_sytest.sh |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,33 @@ | ||
# SyTest Docker | ||
# SyTest Docker Images | ||
|
||
Herein lies a Dockerfile for building a functional SyTest test environment. | ||
SyTest and synapse are cloned from the HEAD of their develop branches. You can | ||
run the tests as follows: | ||
These Dockerfiles create containers for running SyTest in various configurations. SyTest is not included in these images, but its dependencies are. | ||
|
||
``` | ||
cd /path/to/sytest/docker | ||
docker build -t sytest . | ||
docker run --rm -it sytest bash | ||
``` | ||
Included currently is: | ||
|
||
And then at the shell prompt: | ||
|
||
``` | ||
./run-tests.pl | ||
``` | ||
- matrixdotorg/sytest, a base container with SyTest dependencies installed | ||
- matrixdotorg/sytest-synapsepy2, a container which will run SyTest against Synapse on Python 2.7 | ||
- matrixdotorg/sytest-synapsepy3, a container which will run SyTest against Synapse on Python 3.5 | ||
|
||
Or other commands as per [the main SyTest | ||
documentation](https://github.com/matrix-org/sytest#running). | ||
## Using the Synapse containers | ||
|
||
Alternatively: | ||
Once pulled from Docker Hub, the container can be run on a Synapse checkout: | ||
|
||
``` | ||
docker run --rm sytest <command> | ||
$ docker run --rm -it -v /path/to/synapse\:/src -v /path/to/where/you/want/logs\:/logs matrixdotorg/sytest-synapsepy2 | ||
``` | ||
|
||
Where `<command>` is `./run-tests.pl` or similar. | ||
This will run on the same branch in SyTest as the Synapse checkout, if possible, but will fall back to using develop. | ||
|
||
If you want to use an existing checkout of SyTest, mount it to `/test` inside the container by adding `-v /path/to/sytest\:/test` to the docker command. | ||
|
||
If you want to test against a PostgreSQL database, pass `-e POSTGRES=1` to the docker command. | ||
|
||
To use sytest and synapse from the host, so that you can iterate on test | ||
implementation and execute the tests in the container, you can do as follows: | ||
## Building the containers | ||
|
||
The containers are built by executing `build.sh`. You will then have to push them up to Docker Hub: | ||
|
||
``` | ||
docker run --rm -it -v /path/to/sytest:/src/sytest -v /path/to/synapse:/src/synapse sytest bash | ||
$ docker push matrixdotorg/sytest | ||
$ docker push matrixdotorg/sytest-synapsepy2 | ||
$ docker push matrixdotorg/sytest-synapsepy3 | ||
``` | ||
|
||
Then at the prompt, `cd /src/sytest` and then you can run `./run-tests.pl` and | ||
iterate developing a new test or modifying an existing test using your | ||
favourite editor on your host. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#! /usr/bin/env bash | ||
docker build ../ -f Dockerfile -t matrixdotorg/sytest | ||
docker build ../ -f Dockerfile-synapsepy2 -t matrixdotorg/sytest-synapsepy2 | ||
docker build ../ -f Dockerfile-synapsepy3 -t matrixdotorg/sytest-synapsepy3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#! /usr/bin/env bash | ||
|
||
set -x | ||
|
||
# Attempt to find a sytest to use. | ||
# If /test/run-tests.pl exists, it means that a SyTest checkout has been mounted into the Docker image. | ||
if [ -e "/test/run-tests.pl" ] | ||
then | ||
# If the user has mounted in a SyTest checkout, use that. We can tell this by files being in the directory. | ||
echo "Using local sytests..." | ||
else | ||
# Otherwise, try and find out what the branch that the Synapse checkout is using. Fall back to develop if it's not a branch. | ||
branch_name="$(git --git-dir=/src/.git symbolic-ref HEAD 2>/dev/null)" || branch_name="develop" | ||
|
||
# Try and fetch the branch | ||
echo "Trying to get same-named sytest branch..." | ||
wget -q https://github.com/matrix-org/sytest/archive/$branch_name.tar.gz -O sytest.tar.gz | ||
|
||
if [ $? -eq 0 ] | ||
then | ||
# The download succeeded, use that. | ||
echo "Using $branch_name!" | ||
else | ||
# Probably a 404, fall back to develop | ||
echo "Using develop instead..." | ||
wget -q https://github.com/matrix-org/sytest/archive/develop.tar.gz -O sytest.tar.gz | ||
fi | ||
|
||
tar --strip-components=1 -xf sytest.tar.gz | ||
|
||
fi | ||
|
||
# PostgreSQL setup | ||
if [ -n "$POSTGRES" ] | ||
then | ||
|
||
export PGDATA=/var/lib/postgresql/data | ||
export PGUSER=postgres | ||
export POSTGRES_DB_1=pg1 | ||
export POSTGRES_DB_2=pg2 | ||
|
||
# Initialise the database files and start the database | ||
su -c '/usr/lib/postgresql/9.6/bin/initdb -E "UTF-8" --lc-collate="en_US.UTF-8" --lc-ctype="en_US.UTF-8" --username=postgres' postgres | ||
su -c '/usr/lib/postgresql/9.6/bin/pg_ctl -w -D /var/lib/postgresql/data start' postgres | ||
|
||
# Use the Jenkins script to write out the configuration for a PostgreSQL using Synapse | ||
jenkins/prep_sytest_for_postgres.sh | ||
|
||
# Make the test databases for the two Synapse servers that will be spun up | ||
su -c 'psql -c "CREATE DATABASE pg1;"' postgres | ||
su -c 'psql -c "CREATE DATABASE pg2;"' postgres | ||
|
||
fi | ||
|
||
# Build the virtualenv, install extra deps that we will need for the tests | ||
$PYTHON -m virtualenv -p $PYTHON /venv/ | ||
/venv/bin/pip install -q --no-cache-dir -e /src/ | ||
/venv/bin/pip install -q --no-cache-dir lxml psycopg2 | ||
|
||
# Make sure all Perl deps are installed -- this is done in the docker build so will only install packages added since the last Docker build | ||
./install-deps.pl | ||
|
||
# Run the tests | ||
./run-tests.pl -I Synapse --python=/venv/bin/python -O tap --all > results.tap | ||
|
||
TEST_STATUS=$? | ||
|
||
# Copy out the logs | ||
cp results.tap /logs/results.tap | ||
cp server-0/homeserver.log /logs/homeserver-0.log | ||
cp server-1/homeserver.log /logs/homeserver-1.log | ||
|
||
exit $TEST_STATUS |