2020-05-19 20:48:10 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2022-08-09 11:27:21 +02:00
|
|
|
SKIP_MIGRATE=false
|
|
|
|
SKIP_RECREATE_DATABASE=false
|
|
|
|
SKIP_SETUP_DEV=false
|
|
|
|
|
|
|
|
HELP_TEXT=$(cat << EOF
|
|
|
|
use --skip-all-setup to only run Cypress
|
|
|
|
use --skip-recreate-db to skip dropping and creating databases
|
|
|
|
use --skip-migrate-db to skip running DB migrations
|
|
|
|
use --skip-setup-dev to skip running django setup_dev command
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
|
|
|
|
for var in "$@"
|
|
|
|
do
|
|
|
|
if [ "$var" == "--help" ]; then
|
|
|
|
echo "$HELP_TEXT"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if [ "$var" == "-h" ]; then
|
|
|
|
echo "$HELP_TEXT"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$var" == "--skip-all-setup" ]; then
|
|
|
|
SKIP_RECREATE_DATABASE=true
|
|
|
|
SKIP_MIGRATE=true
|
|
|
|
SKIP_SETUP_DEV=true
|
|
|
|
echo "skipping all setup"
|
|
|
|
fi
|
|
|
|
if [ "$var" == "--skip-recreate-db" ]; then
|
|
|
|
SKIP_RECREATE_DATABASE=true
|
|
|
|
echo "skipping dropping and recreating databases"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$var" == "--skip-migrate-db" ]; then
|
|
|
|
SKIP_MIGRATE=true
|
|
|
|
echo "skipping migrating databases"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$var" == "--skip-setup-dev" ]; then
|
|
|
|
SKIP_SETUP_DEV=true
|
|
|
|
echo "skipping django setup dev command"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-01-03 15:26:54 +01:00
|
|
|
export DEBUG=1
|
2022-05-27 14:31:17 +02:00
|
|
|
export NO_RESTART_LOOP=1
|
2022-01-03 15:26:54 +01:00
|
|
|
export CYPRESS_BASE_URL=http://localhost:8080
|
|
|
|
export OPT_OUT_CAPTURE=1
|
|
|
|
export SECURE_COOKIES=0
|
|
|
|
export SKIP_SERVICE_VERSION_REQUIREMENTS=1
|
2022-07-22 11:25:59 +02:00
|
|
|
export KAFKA_URL=kafka://kafka:9092
|
2022-01-03 15:26:54 +01:00
|
|
|
export CLICKHOUSE_DATABASE=posthog_test
|
|
|
|
export TEST=1 # Plugin server and kafka revert to 'default' Clickhouse database if TEST is not set
|
|
|
|
export CLICKHOUSE_SECURE=0
|
|
|
|
export E2E_TESTING=1
|
|
|
|
export SECRET_KEY=e2e_test
|
|
|
|
export EMAIL_HOST=email.test.posthog.net
|
2022-05-27 14:31:17 +02:00
|
|
|
export SITE_URL=http://localhost:8080
|
2022-01-03 15:26:54 +01:00
|
|
|
export REDIS_URL=redis://localhost/
|
|
|
|
DATABASE="posthog_e2e_test"
|
2021-12-21 17:08:14 +01:00
|
|
|
export PGHOST="${PGHOST:=localhost}"
|
|
|
|
export PGUSER="${PGUSER:=posthog}"
|
|
|
|
export PGPASSWORD="${PGPASSWORD:=posthog}"
|
|
|
|
export PGPORT="${PGPORT:=5432}"
|
|
|
|
export DATABASE_URL="postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${DATABASE}"
|
|
|
|
|
2022-08-09 11:27:21 +02:00
|
|
|
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
|
|
|
|
|
|
|
|
recreateDatabases() {
|
2022-08-09 20:12:41 +02:00
|
|
|
echo "~~~~~~~~~~~~~ dropping and creating databases ~~~~~~~~~~~~~"
|
|
|
|
|
2022-08-09 11:27:21 +02:00
|
|
|
dropdb --if-exists $DATABASE
|
|
|
|
createdb $DATABASE
|
2022-01-03 15:26:54 +01:00
|
|
|
|
2022-08-09 11:27:21 +02:00
|
|
|
# Delete and recreate clickhouse database
|
|
|
|
echo 'DROP DATABASE if exists posthog_test' | curl 'http://localhost:8123/' --data-binary @-
|
|
|
|
echo 'create database posthog_test' | curl 'http://localhost:8123/' --data-binary @-
|
|
|
|
}
|
2021-02-26 15:50:21 +01:00
|
|
|
|
2022-08-09 11:27:21 +02:00
|
|
|
migrateDatabases() {
|
2022-08-09 20:12:41 +02:00
|
|
|
echo "~~~~~~~~~~~~~ migrating databases ~~~~~~~~~~~~~"
|
2022-08-09 11:27:21 +02:00
|
|
|
python manage.py migrate
|
|
|
|
python manage.py migrate_clickhouse
|
|
|
|
}
|
2022-01-03 15:26:54 +01:00
|
|
|
|
2022-08-09 11:27:21 +02:00
|
|
|
setupDev() {
|
2022-08-09 20:12:41 +02:00
|
|
|
echo "~~~~~~~~~~~~~ setting up django ~~~~~~~~~~~~~"
|
2022-08-09 11:27:21 +02:00
|
|
|
python manage.py setup_dev &
|
|
|
|
}
|
|
|
|
|
2022-08-25 13:00:34 +02:00
|
|
|
nc -z localhost 9092 || ( echo -e "\033[0;31mKafka isn't running. Please run\n\tdocker compose -f docker-compose.dev.yml up zookeeper kafka clickhouse db redis\nI'll wait while you do that.\033[0m" ; bin/check_kafka_clickhouse_up )
|
|
|
|
wget -nv -t1 --spider 'http://localhost:8123/' || ( echo -e "\033[0;31mClickhouse isn't running. Please run\n\tdocker compose -f docker-compose.dev.yml up zookeeper kafka clickhouse db redis.\nI'll wait while you do that.\033[0m" ; bin/check_kafka_clickhouse_up )
|
2022-01-03 15:26:54 +01:00
|
|
|
|
2022-08-09 11:27:21 +02:00
|
|
|
$SKIP_RECREATE_DATABASE || recreateDatabases
|
2022-08-09 13:20:02 +02:00
|
|
|
$SKIP_MIGRATE || migrateDatabases
|
2022-08-09 11:27:21 +02:00
|
|
|
$SKIP_SETUP_DEV || setupDev
|
2022-01-03 15:26:54 +01:00
|
|
|
|
2022-08-09 11:27:21 +02:00
|
|
|
# parallel block
|
2022-01-03 15:26:54 +01:00
|
|
|
./bin/plugin-server &
|
2021-02-26 15:50:21 +01:00
|
|
|
# Only start webpack if not already running
|
|
|
|
nc -vz 127.0.0.1 8234 2> /dev/null || ./bin/start-frontend &
|
2022-12-12 10:28:06 +01:00
|
|
|
pnpm dlx cypress open --config-file cypress.e2e.config.ts &
|
2022-01-03 15:26:54 +01:00
|
|
|
python manage.py runserver 8080
|
2021-02-26 15:50:21 +01:00
|
|
|
|