From b44267aac09da603e0a9745017c9239d0e443ef2 Mon Sep 17 00:00:00 2001 From: Zhi Date: Sat, 14 Mar 2026 08:32:33 +0000 Subject: [PATCH] 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 --- cleanup-frontend.sh | 61 -------------------------------------------- run-test-frontend.sh | 44 +++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 73 deletions(-) delete mode 100755 cleanup-frontend.sh diff --git a/cleanup-frontend.sh b/cleanup-frontend.sh deleted file mode 100755 index e67a8c3..0000000 --- a/cleanup-frontend.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash -# Cleanup script for HarborForge Frontend Test -# Usage: ./cleanup-frontend.sh [--expose-port {on|off}] -# Default: off - -set -e - -EXPOSE_PORT="off" -COMPOSE_FILE="docker-compose-frontend.yml" - -# Load environment variables from .env.TEST if exists -if [ -f ".env.TEST" ]; then - echo "๐Ÿ“‹ Loading .env.TEST..." - set -a - source .env.TEST - set +a -fi - -# Parse arguments -while [[ $# -gt 0 ]]; do - case $1 in - --expose-port) - EXPOSE_PORT="$2" - shift 2 - ;; - --expose-port=*) - EXPOSE_PORT="${1#*=}" - shift - ;; - *) - echo "Unknown option: $1" - echo "Usage: $0 [--expose-port {on|off}]" - exit 1 - ;; - esac -done - -# Validate expose-port value -if [[ "$EXPOSE_PORT" != "on" && "$EXPOSE_PORT" != "off" ]]; then - echo "Error: --expose-port must be 'on' or 'off'" - exit 1 -fi - -# Select compose file based on expose-port -if [[ "$EXPOSE_PORT" == "on" ]]; then - COMPOSE_FILE="docker-compose-frontend-expose.yml" - echo "๐Ÿ”Œ Port exposure: ON" -else - echo "๐Ÿ”Œ Port exposure: OFF" -fi - -echo "๐Ÿ“ฆ Using compose file: $COMPOSE_FILE" -echo "๐Ÿงน Cleaning up HarborForge Test containers..." - -# Stop and remove containers, networks (keep images) -docker compose -f "$COMPOSE_FILE" down - -# Also remove the wizard config volume -docker volume rm harborforgetest_wizard_config 2>/dev/null || true - -echo "โœ… Cleanup complete!" diff --git a/run-test-frontend.sh b/run-test-frontend.sh index 9b2aaa7..99c5efc 100755 --- a/run-test-frontend.sh +++ b/run-test-frontend.sh @@ -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