mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
83 lines
2.4 KiB
Bash
Executable File
83 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
# Usage: ./run-e2e.sh [--docker] [--ui]
|
|
|
|
NODE_BIN= $(command -v bun || command -v npm)
|
|
# Use podman if available. Not everyone has it
|
|
CONTAINER_BIN=$(command -v podman || command -v docker)
|
|
COMPOSE_BIN="$(command -v docker-compose || true)"
|
|
if [ -z "$CONTAINER_BIN" ]; then
|
|
echo "Sorry, you need either podman or docker installed to run this script."
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$CI" = "true" ]; then
|
|
CONTAINER_BIN=$(command -v docker)
|
|
fi
|
|
|
|
echo "Using $CONTAINER_BIN for container operations..."
|
|
|
|
ENV_FILE="./.env.e2e"
|
|
|
|
if [ -f "$ENV_FILE" ]; then
|
|
echo "Loading settings..."
|
|
set -a
|
|
source "$ENV_FILE"
|
|
set +a
|
|
else
|
|
echo "Error: Configuration file $ENV_FILE is missing!!"
|
|
exit 1
|
|
fi
|
|
|
|
# This cleans up django backend process and containers. Very useful for local e2e to free system resources immediately.
|
|
cleanup() {
|
|
echo "Cleaning up..."
|
|
$CONTAINER_BIN compose -p "piku_e2e" -f "./docker-compose.e2e.yml" down --remove-orphans -v
|
|
[ -n "$BACKEND_PID" ] && kill "$BACKEND_PID" 2>/dev/null || true
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
echo "Starting Database and Mail server..."
|
|
|
|
if echo "$CONTAINER_BIN" | grep -q "podman"; then
|
|
podman compose -p "piku_e2e" -f "./docker-compose.e2e.yml" up -d
|
|
elif [ -n "$COMPOSE_BIN" ]; then
|
|
"$COMPOSE_BIN" -p "piku_e2e" -f "./docker-compose.e2e.yml" up -d
|
|
else
|
|
docker compose -p "piku_e2e" -f "./docker-compose.e2e.yml" up -d
|
|
fi
|
|
|
|
# postgress will take some time, so we wait, and no race condition. Also, no point in logging this output
|
|
until $CONTAINER_BIN exec "$DB_NAME" pg_isready -U "${DB_USER:-test}" >/dev/null 2>&1; do
|
|
echo "Waiting for DB..."
|
|
sleep 2
|
|
done
|
|
|
|
export PIKU_ENV_FILE="$ENV_FILE"
|
|
echo "Starting Backend..."
|
|
mkdir -p ./tmp/logs
|
|
(cd backend && uv run manage.py migrate)
|
|
(cd backend && uv run manage.py serve) > ./tmp/logs/backend.log 2>&1 &
|
|
BACKEND_PID=$!
|
|
|
|
TEST_COMMAND="test:e2e"
|
|
MODE="local"
|
|
|
|
for arg in "$@"; do
|
|
echo "$arg"
|
|
if [ "$arg" = "--ui" ]; then
|
|
TEST_COMMAND="test:e2e:ui"
|
|
fi
|
|
if [ "$arg" = "--docker" ]; then
|
|
MODE="docker"
|
|
fi
|
|
done
|
|
|
|
# optionally using docker to run playwright since someone at microsoft thought it'd be nice to not support fedora :)
|
|
if [ $MODE = "docker" ]; then
|
|
$CONTAINER_BIN run --rm -it --network host -v $(pwd):/e2e:Z -w /e2e/frontend -p 43008:43008 mcr.microsoft.com/playwright:v1.59.1-noble npm run $TEST_COMMAND
|
|
else
|
|
(cd frontend && $NODE_BIN run $TEST_COMMAND)
|
|
fi
|