mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
Feature/ssl integration (#1)
* feat: update E2E testing configuration to use ssl * fix: add IPv6 loopback support to mkcert generation command in CI workflow * feat: centralize SSL certificate generation into a reusable workflow job * fix: use static ip in mkcert command * fix: correct mkcert command args * feat: implement certificate caching in CI workflow to persist SSL files across jobs * refactor: optimize CI workflow caching * ci: implement certificate caching in workflow * fix: correct certificate caching keys and fix environment file paths in CI workflows * fix: correct environment file paths and parallelize frontend dependency installation in CI workflow * test: set TZ environment variable to Asia/Kolkata in vitest configuration * fix: force en-US locale in Intl formatters to ensure consistent date and time output * fix: update MAILPIT_API_URL protocol from https to http in e2e environment example * chore: set test timezone to Asia/Kolkata * ci: add sll support and enhance e2e workflow * ci: improve compatibility for docker-compose execution * refactor: improve container orchestration detection and fallback logic in e2e test script * feat: add container runtime validation and force docker usage in CI environment * feat: add caching for Playwright dependencies in CI workflow * chore: update restart policy to unless-stopped for postgres and mailpit services in e2e docker-compose --------- Co-authored-by: ramvignesh-b <ramvignesh-b@github.com>
This commit is contained in:
+45
-78
@@ -1,98 +1,65 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Get absolute path of project root
|
||||
PROJECT_ROOT=$(pwd)
|
||||
# Use podman if available. Not everyone has it
|
||||
CONTAINER_BIN=$(command -v podman || command -v docker)
|
||||
if [ -z "$CONTAINER_BIN" ]; then
|
||||
echo "Sorry, you need either podman or docker installed to run this script."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Configuration
|
||||
ENV_FILE="$PROJECT_ROOT/.env.e2e"
|
||||
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 "[INFO] Loading configuration from $ENV_FILE..."
|
||||
echo "Loading settings..."
|
||||
set -a
|
||||
source "$ENV_FILE"
|
||||
set +a
|
||||
elif [ "$CI" != "true" ]; then
|
||||
echo "[ERROR] $ENV_FILE not found! Please create it for local testing (use .env.e2e.example as template)."
|
||||
exit 1
|
||||
else
|
||||
echo "[INFO] Running in CI mode (using direct environment variables)..."
|
||||
echo "Error: Configuration file $ENV_FILE is missing!!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Map E2E variables to Django expected names
|
||||
# In CI, these should be set via GitHub Actions env variables
|
||||
export DB_NAME=${E2E_DB_DB:-piku_e2e}
|
||||
export DB_USER=${E2E_DB_USER:-piku_test}
|
||||
export DB_PASSWORD=${E2E_DB_PASS:-piku_test}
|
||||
export DB_HOST=${E2E_DB_HOST:-localhost}
|
||||
export DB_PORT=${E2E_DB_PORT:-5433}
|
||||
export E2E_BACKEND_PORT=${E2E_BACKEND_PORT:-8001}
|
||||
|
||||
echo "[START] Initializing E2E Test Environment..."
|
||||
|
||||
# 1. Cleanup / Start Services (Skip in CI)
|
||||
if [ "$CI" != "true" ]; then
|
||||
if podman ps -a --format "{{.Names}}" | grep -q "^$E2E_DB_NAME$"; then
|
||||
echo "[CLEANUP] Removing existing container $E2E_DB_NAME..."
|
||||
podman rm -f $E2E_DB_NAME
|
||||
fi
|
||||
|
||||
echo "[DB] Starting disposable Postgres on port $DB_PORT..."
|
||||
podman run --name $E2E_DB_NAME \
|
||||
-e POSTGRES_DB=$DB_NAME \
|
||||
-e POSTGRES_USER=$DB_USER \
|
||||
-e POSTGRES_PASSWORD=$DB_PASSWORD \
|
||||
-p $DB_PORT:5432 \
|
||||
-d docker.io/library/postgres:16-alpine > /dev/null
|
||||
|
||||
echo "[DB] Waiting for Postgres to be ready..."
|
||||
until podman exec $E2E_DB_NAME pg_isready -U $DB_USER > /dev/null 2>&1; do
|
||||
sleep 1
|
||||
done
|
||||
echo "[DB] Postgres is ready."
|
||||
fi
|
||||
|
||||
# Trap to ensure cleanup
|
||||
# This cleans up containers. Very useful for local e2e to free system resources immediately.
|
||||
cleanup() {
|
||||
echo "[CLEANUP] Stopping services..."
|
||||
if [ "$CI" != "true" ]; then
|
||||
podman rm -f $E2E_DB_NAME || true
|
||||
fi
|
||||
if [ ! -z "$BACKEND_PID" ]; then
|
||||
kill "$BACKEND_PID" 2>/dev/null || true
|
||||
fi
|
||||
echo "Cleaning up..."
|
||||
$CONTAINER_BIN rm -f "$DB_NAME" 2>/dev/null || true
|
||||
[ -n "$BACKEND_PID" ] && kill "$BACKEND_PID" 2>/dev/null || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# 2. Prepare Backend
|
||||
echo "[BACKEND] Running database migrations..."
|
||||
export PIKU_ENV_FILE="$ENV_FILE"
|
||||
(cd backend && uv run manage.py migrate --noinput)
|
||||
echo "Starting Database and Mail server..."
|
||||
COMPOSE_BIN="$(command -v docker-compose || true)"
|
||||
|
||||
echo "[BACKEND] Starting server on port $E2E_BACKEND_PORT..."
|
||||
(cd backend && uv run manage.py runserver $E2E_BACKEND_PORT) > /tmp/piku_e2e_backend.log 2>&1 &
|
||||
BACKEND_PID=$!
|
||||
|
||||
echo "[BACKEND] Waiting for server to respond..."
|
||||
until curl -s http://localhost:$E2E_BACKEND_PORT > /dev/null; do
|
||||
sleep 1
|
||||
if ! kill -0 $BACKEND_PID 2>/dev/null; then
|
||||
echo "[ERROR] Backend failed to start. Logs:"
|
||||
cat /tmp/piku_e2e_backend.log
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
echo "[BACKEND] Server is ready."
|
||||
|
||||
# 3. Run Playwright
|
||||
export VITE_API_URL="http://localhost:$E2E_BACKEND_PORT"
|
||||
|
||||
if [ "$CI" = "true" ]; then
|
||||
echo "[TEST] Running Playwright Tests (CI)..."
|
||||
(cd frontend && bun run test:e2e --project=chromium "$@")
|
||||
if echo "$CONTAINER_BIN" | grep -q "podman"; then
|
||||
podman compose -f "./docker-compose.e2e.yml" up -d
|
||||
elif [ -n "$COMPOSE_BIN" ]; then
|
||||
"$COMPOSE_BIN" -f "./docker-compose.e2e.yml" up -d
|
||||
else
|
||||
echo "[TEST] Running Playwright Tests in Distrobox..."
|
||||
(cd frontend && distrobox-enter --name ubuntu-24.04 -- env VITE_API_URL=$VITE_API_URL bun run test:e2e --project=chromium "$@")
|
||||
docker compose -f "./docker-compose.e2e.yml" up -d
|
||||
fi
|
||||
|
||||
echo "[SUCCESS] E2E Tests Completed."
|
||||
# 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
|
||||
|
||||
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=$!
|
||||
|
||||
if [ "$CI" = "true" ]; then
|
||||
cd frontend && bun run test:e2e "$@"
|
||||
else
|
||||
# Because playwright decided not to support Fedora :)
|
||||
cd frontend && distrobox-enter --name ubuntu-24.04 -- bun run test:e2e "$@"
|
||||
fi
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
(podman compose up -d) &
|
||||
(cd backend && uv run manage.py runserver) &
|
||||
(cd backend && uv run manage.py serve) &
|
||||
(cd frontend && bun run dev)
|
||||
|
||||
Reference in New Issue
Block a user