Skip to content

Commit

Permalink
Add dockerfile for dendrite (#541)
Browse files Browse the repository at this point in the history
Adds a Dockerfile for Dendrite which prepares postgres and installs the needed dependencies for sytest and dendrite to run.
  • Loading branch information
anoadragon453 authored Apr 4, 2019
1 parent 4570163 commit 8fdb332
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docker/Dockerfile-dendrite
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM matrixdotorg/sytest:latest

RUN apt-get -qq install -y dos2unix

# PostgreSQL setup
ENV PGHOST=/var/run/postgresql
ENV PGDATA=$PGHOST/data
ENV PGUSER=postgres

# Turn off all the fsync stuff for postgres
RUN mkdir -p /etc/postgresql/9.6/main/conf.d/
RUN echo "fync=off" > /etc/postgresql/9.6/main/conf.d/fsync.conf
RUN echo "full_page_writes=off" >> /etc/postgresql/9.6/main/conf.d/fsync.conf

# Initialise the database files
RUN 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

# This is where we expect Dendrite to be binded to from the host
RUN mkdir -p /src

# The dockerfile context, when ran by the buildscript, will actually be the
# repo root, not the docker folder
ADD docker/dendrite_sytest.sh /dendrite_sytest.sh
RUN dos2unix /dendrite_sytest.sh
ENTRYPOINT ["/dendrite_sytest.sh"]
1 change: 1 addition & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ cd `dirname $0`
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
docker build ../ -f Dockerfile-dendrite -t matrixdotorg/sytest-dendrite
62 changes: 62 additions & 0 deletions docker/dendrite_sytest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#! /usr/bin/env bash

set -ex

# 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 "./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 Dendrite 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 || {
# 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
}

tar --strip-components=1 -xf sytest.tar.gz

fi

# 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
dos2unix ./install-deps.pl
./install-deps.pl

# Start the database
su -c '/usr/lib/postgresql/9.6/bin/pg_ctl -w -D /var/run/postgresql/data start' postgres

# Make the test databases
su -c "psql -c \"CREATE USER dendrite PASSWORD 'itsasecret'\" postgres"
su -c 'for i in account device mediaapi syncapi roomserver serverkey federationsender publicroomsapi appservice naffka sytest_template; do psql -c "CREATE DATABASE $i OWNER dendrite;"; done' postgres

# Write dendrite configuration
mkdir -p "server-0"
cat > "server-0/database.yaml" << EOF
args:
user: $PGUSER
database: $PGUSER
host: $PGHOST
type: pg
EOF

# Run the tests
dos2unix ./run-tests.pl
TEST_STATUS=0
./run-tests.pl -I Dendrite::Monolith -d /src/bin -W /src/testfile -O tap --all "$@" > results.tap || TEST_STATUS=$?

# Copy out the logs
mkdir -p /logs
cp results.tap /logs/results.tap
rsync --ignore-missing-args -av server-0 server-1 /logs --include "*/" --include="*.log.*" --include="*.log" --exclude="*"

# Write out JUnit for CircleCI
mkdir -p /logs/sytest
perl /tap-to-junit-xml.pl --puretap --input=/logs/results.tap --output=/logs/sytest/results.xml "SyTest"

exit $TEST_STATUS

0 comments on commit 8fdb332

Please sign in to comment.