Add separate compose files for port exposure options
- docker-compose-frontend.yml: No port exposure (default)
- docker-compose-frontend-expose.yml: Expose ports to host
- run-test-frontend.sh: Test script with --expose-port {on|off} option
- cleanup-frontend.sh: Cleanup script with --expose-port option
This commit is contained in:
86
run-test-frontend.sh
Executable file
86
run-test-frontend.sh
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/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)
|
||||
|
||||
set -e
|
||||
|
||||
EXPOSE_PORT="off"
|
||||
COMPOSE_FILE="docker-compose-frontend.yml"
|
||||
|
||||
# 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 "🚀 Running HarborForge Frontend Test..."
|
||||
|
||||
# Clean any previous containers first
|
||||
docker compose -f "$COMPOSE_FILE" down 2>/dev/null || true
|
||||
|
||||
# Start services
|
||||
docker compose -f "$COMPOSE_FILE" up -d
|
||||
|
||||
# Wait for frontend to be ready
|
||||
echo "⏳ Waiting for services..."
|
||||
MAX_RETRIES=30
|
||||
RETRY_COUNT=0
|
||||
until docker run --rm --network harborforgetest_test-network curlimages/curl -s -o /dev/null -w "%{http_code}" http://frontend:3000/ 2>/dev/null | grep -q "200" || [ $RETRY_COUNT -eq $MAX_RETRIES ]; do
|
||||
echo " Waiting for frontend... ($RETRY_COUNT/$MAX_RETRIES)"
|
||||
sleep 2
|
||||
RETRY_COUNT=$((RETRY_COUNT+1))
|
||||
done
|
||||
|
||||
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
|
||||
echo "❌ Frontend failed to start"
|
||||
docker compose -f "$COMPOSE_FILE" logs
|
||||
docker compose -f "$COMPOSE_FILE" down -v
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Services ready!"
|
||||
|
||||
# Run 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!"
|
||||
else
|
||||
echo "❌ Test failed with exit code: $TEST_EXIT_CODE"
|
||||
fi
|
||||
|
||||
exit $TEST_EXIT_CODE
|
||||
Reference in New Issue
Block a user