Merge cleanup logic into run-test-frontend

- --expose-port on: keep services running after test
- --expose-port off: auto cleanup (default)
- Removed cleanup-frontend.sh
This commit is contained in:
Zhi
2026-03-14 08:32:33 +00:00
parent 03067ca3a8
commit b44267aac0
2 changed files with 32 additions and 73 deletions

View File

@@ -1,7 +1,10 @@
#!/bin/bash
# Run frontend test with optional port exposure
# Usage: ./run-test-frontend.sh [--expose-port {on|off}]
# Default: off (no ports exposed to host)
# Default: off
#
# --expose-port on: Keep services running after test (manual cleanup required)
# --expose-port off: Auto cleanup after test (default)
set -e
@@ -44,18 +47,19 @@ fi
# Select compose file based on expose-port
if [[ "$EXPOSE_PORT" == "on" ]]; then
COMPOSE_FILE="docker-compose-frontend-expose.yml"
echo "🔌 Port exposure: ON"
echo "🔌 Port exposure: ON (services will keep running)"
else
echo "🔌 Port exposure: OFF"
echo "🔌 Port exposure: OFF (auto cleanup after test)"
fi
echo "📦 Using compose file: $COMPOSE_FILE"
echo "🚀 Running HarborForge Frontend Test..."
# Clean any previous containers first
docker compose -f "$COMPOSE_FILE" down 2>/dev/null || true
echo "🧹 Cleaning up previous containers..."
docker compose -f "$COMPOSE_FILE" down -v 2>/dev/null || true
# Start services
echo "📦 Starting services..."
docker compose -f "$COMPOSE_FILE" up -d
# Wait for frontend to be ready
@@ -78,17 +82,33 @@ fi
echo "✅ Services ready!"
# Run test
echo "🧪 Running test..."
docker compose -f "$COMPOSE_FILE" run --rm test
TEST_EXIT_CODE=$?
echo ""
echo "🧹 Cleaning up containers and volumes..."
docker compose -f "$COMPOSE_FILE" down -v
if [ $TEST_EXIT_CODE -eq 0 ]; then
echo "✅ Test passed!"
# Cleanup decision based on expose-port
if [[ "$EXPOSE_PORT" == "on" ]]; then
echo ""
echo "🔌 Port exposure is ON - keeping services running!"
echo " Use './run-test-frontend.sh --expose-port on' to cleanup"
echo " Or manually: docker compose -f $COMPOSE_FILE down -v"
echo ""
if [ $TEST_EXIT_CODE -eq 0 ]; then
echo "✅ Test passed!"
else
echo "❌ Test failed with exit code: $TEST_EXIT_CODE"
fi
else
echo "❌ Test failed with exit code: $TEST_EXIT_CODE"
echo ""
echo "🧹 Cleaning up containers and volumes..."
docker compose -f "$COMPOSE_FILE" down -v
if [ $TEST_EXIT_CODE -eq 0 ]; then
echo "✅ Test passed!"
else
echo "❌ Test failed with exit code: $TEST_EXIT_CODE"
fi
fi
exit $TEST_EXIT_CODE