2021-03-31 13:58:12 +03:00
|
|
|
#!/usr/bin/env bash
|
2020-09-29 15:47:47 +03:00
|
|
|
# This script is designed for developers who want to test their code
|
|
|
|
# against Complement.
|
|
|
|
#
|
|
|
|
# It makes a Synapse image which represents the current checkout,
|
2021-03-31 13:58:12 +03:00
|
|
|
# builds a synapse-complement image on top, then runs tests with it.
|
|
|
|
#
|
2022-02-23 13:06:18 +03:00
|
|
|
# By default the script will fetch the latest Complement main branch and
|
2021-03-31 13:58:12 +03:00
|
|
|
# run tests with that. This can be overridden to use a custom Complement
|
|
|
|
# checkout by setting the COMPLEMENT_DIR environment variable to the
|
2022-01-20 16:04:58 +03:00
|
|
|
# filepath of a local Complement checkout or by setting the COMPLEMENT_REF
|
|
|
|
# environment variable to pull a different branch or commit.
|
2021-03-31 13:58:12 +03:00
|
|
|
#
|
2021-05-24 22:32:45 +03:00
|
|
|
# By default Synapse is run in monolith mode. This can be overridden by
|
|
|
|
# setting the WORKERS environment variable.
|
|
|
|
#
|
2021-03-31 13:58:12 +03:00
|
|
|
# A regular expression of test method names can be supplied as the first
|
|
|
|
# argument to the script. Complement will then only run those tests. If
|
|
|
|
# no regex is supplied, all tests are run. For example;
|
|
|
|
#
|
|
|
|
# ./complement.sh "TestOutboundFederation(Profile|Send)"
|
|
|
|
#
|
|
|
|
|
|
|
|
# Exit if a line returns a non-zero exit code
|
|
|
|
set -e
|
2020-09-29 15:47:47 +03:00
|
|
|
|
2022-01-12 13:37:57 +03:00
|
|
|
# enable buildkit for the docker builds
|
|
|
|
export DOCKER_BUILDKIT=1
|
|
|
|
|
2021-03-31 13:58:12 +03:00
|
|
|
# Change to the repository root
|
2021-11-17 17:04:50 +03:00
|
|
|
cd "$(dirname $0)/.."
|
2020-09-29 15:47:47 +03:00
|
|
|
|
2021-03-31 13:58:12 +03:00
|
|
|
# Check for a user-specified Complement checkout
|
|
|
|
if [[ -z "$COMPLEMENT_DIR" ]]; then
|
2022-02-23 13:06:18 +03:00
|
|
|
COMPLEMENT_REF=${COMPLEMENT_REF:-main}
|
2022-01-20 16:04:58 +03:00
|
|
|
echo "COMPLEMENT_DIR not set. Fetching Complement checkout from ${COMPLEMENT_REF}..."
|
|
|
|
wget -Nq https://github.com/matrix-org/complement/archive/${COMPLEMENT_REF}.tar.gz
|
|
|
|
tar -xzf ${COMPLEMENT_REF}.tar.gz
|
|
|
|
COMPLEMENT_DIR=complement-${COMPLEMENT_REF}
|
|
|
|
echo "Checkout available at 'complement-${COMPLEMENT_REF}'"
|
2021-03-31 13:58:12 +03:00
|
|
|
fi
|
|
|
|
|
2021-08-25 17:18:23 +03:00
|
|
|
# Build the base Synapse image from the local checkout
|
|
|
|
docker build -t matrixdotorg/synapse -f "docker/Dockerfile" .
|
|
|
|
|
2021-05-24 22:32:45 +03:00
|
|
|
# If we're using workers, modify the docker files slightly.
|
|
|
|
if [[ -n "$WORKERS" ]]; then
|
2021-08-25 17:18:23 +03:00
|
|
|
# Build the workers docker image (from the base Synapse image).
|
|
|
|
docker build -t matrixdotorg/synapse-workers -f "docker/Dockerfile-workers" .
|
|
|
|
|
2021-05-24 22:32:45 +03:00
|
|
|
export COMPLEMENT_BASE_IMAGE=complement-synapse-workers
|
|
|
|
COMPLEMENT_DOCKERFILE=SynapseWorkers.Dockerfile
|
2022-04-11 13:39:28 +03:00
|
|
|
|
2021-05-24 22:32:45 +03:00
|
|
|
# And provide some more configuration to complement.
|
2022-04-11 16:38:58 +03:00
|
|
|
export COMPLEMENT_SPAWN_HS_TIMEOUT_SECS=60
|
2021-05-24 22:32:45 +03:00
|
|
|
else
|
|
|
|
export COMPLEMENT_BASE_IMAGE=complement-synapse
|
2022-04-11 13:39:28 +03:00
|
|
|
COMPLEMENT_DOCKERFILE=Dockerfile
|
2021-05-24 22:32:45 +03:00
|
|
|
fi
|
|
|
|
|
2021-08-25 17:18:23 +03:00
|
|
|
# Build the Complement image from the Synapse image we just built.
|
2022-04-11 13:39:28 +03:00
|
|
|
docker build -t $COMPLEMENT_BASE_IMAGE -f "docker/complement/$COMPLEMENT_DOCKERFILE" "docker/complement"
|
2020-09-29 15:47:47 +03:00
|
|
|
|
2021-03-31 13:58:12 +03:00
|
|
|
# Run the tests!
|
2022-01-12 13:37:57 +03:00
|
|
|
echo "Images built; running complement"
|
2022-04-11 13:39:28 +03:00
|
|
|
cd "$COMPLEMENT_DIR"
|
|
|
|
go test -v -tags synapse_blacklist,msc2716,msc3030 -count=1 "$@" ./tests/...
|