1+ #! /bin/bash
2+ # Test frontend Docker image with specific environment configuration
3+ # Usage: ./test-frontend-docker.sh <image> <environment> [port]
4+ #
5+ # Parameters:
6+ # image - Docker image name/tag to test
7+ # environment - Frontend environment configuration (local, webnode, production, development, producer, fuzzing)
8+ # port - Optional port to use (default: 8080)
9+ #
10+ # Examples:
11+ # ./test-frontend-docker.sh o1labs/mina-rust-frontend:latest production
12+ # ./test-frontend-docker.sh test-frontend:local local 9090
13+
14+ set -euo pipefail
15+
16+ # Check arguments
17+ if [ $# -lt 2 ]; then
18+ echo " Usage: $0 <image> <environment> [port]"
19+ echo " "
20+ echo " Supported environments: local, webnode, production, development, producer, fuzzing"
21+ echo " "
22+ echo " Examples:"
23+ echo " $0 o1labs/mina-rust-frontend:latest production"
24+ echo " $0 test-frontend:local local 9090"
25+ exit 1
26+ fi
27+
28+ IMAGE=" $1 "
29+ ENVIRONMENT=" $2 "
30+ PORT=" ${3:- 8080} "
31+ CONTAINER_NAME=" test-frontend-${ENVIRONMENT} -$$ "
32+
33+ # Supported environments
34+ SUPPORTED_ENVS=" local webnode production development producer fuzzing"
35+ if [[ ! " $SUPPORTED_ENVS " =~ \ $ENVIRONMENT \ ]]; then
36+ echo " ❌ Unsupported environment: $ENVIRONMENT "
37+ echo " Supported environments: $SUPPORTED_ENVS "
38+ exit 1
39+ fi
40+
41+ echo " 🧪 Testing frontend image with environment: $ENVIRONMENT "
42+ echo " 📦 Image: $IMAGE "
43+ echo " 🔌 Port: $PORT "
44+ echo " 📝 Container: $CONTAINER_NAME "
45+ echo " "
46+
47+ # Cleanup function
48+ cleanup () {
49+ echo " 🧹 Cleaning up container: $CONTAINER_NAME "
50+ docker stop " $CONTAINER_NAME " 2> /dev/null || true
51+ docker rm " $CONTAINER_NAME " 2> /dev/null || true
52+ }
53+
54+ # Set up cleanup trap
55+ trap cleanup EXIT
56+
57+ # Check if port is available
58+ if ss -tuln | grep -q " :$PORT " ; then
59+ echo " ❌ Port $PORT is already in use"
60+ exit 1
61+ fi
62+
63+ # Run the container with the specific environment configuration
64+ echo " 🚀 Starting container..."
65+ docker run --rm -d \
66+ --name " $CONTAINER_NAME " \
67+ -p " $PORT :80" \
68+ -e MINA_FRONTEND_ENVIRONMENT=" $ENVIRONMENT " \
69+ " $IMAGE "
70+
71+ # Wait a moment for container to start
72+ echo " ⏳ Waiting for container to initialize..."
73+ sleep 10
74+
75+ # Check if container is running
76+ if ! docker ps | grep -q " $CONTAINER_NAME " ; then
77+ echo " ❌ Container failed to start with environment: $ENVIRONMENT "
78+ echo " 📋 Container logs:"
79+ docker logs " $CONTAINER_NAME " || echo " No logs available"
80+ exit 1
81+ fi
82+
83+ echo " ✅ Container started successfully with environment: $ENVIRONMENT "
84+
85+ # Test HTTP endpoint with retries (30 attempts with 3 second intervals = ~90s total)
86+ RETRY_COUNT=0
87+ MAX_RETRIES=30
88+ SUCCESS=false
89+
90+ echo " 🔍 Testing HTTP endpoint with retries (max $MAX_RETRIES attempts)..."
91+
92+ while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
93+ if curl -f -s -m 5 " http://localhost:$PORT /" > /dev/null 2>&1 ; then
94+ echo " ✅ HTTP endpoint is responding for environment: $ENVIRONMENT (attempt $(( RETRY_COUNT + 1 )) )"
95+ SUCCESS=true
96+ break
97+ else
98+ RETRY_COUNT=$(( RETRY_COUNT + 1 ))
99+ if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
100+ echo " ❌ HTTP endpoint not ready after $MAX_RETRIES attempts"
101+ else
102+ echo " ⏳ HTTP endpoint not ready, attempt $RETRY_COUNT /$MAX_RETRIES for environment: $ENVIRONMENT "
103+ sleep 3
104+ fi
105+ fi
106+ done
107+
108+ if [ " $SUCCESS " = false ]; then
109+ echo " ❌ HTTP endpoint failed after $MAX_RETRIES attempts for environment: $ENVIRONMENT "
110+ echo " 📋 Container logs:"
111+ docker logs " $CONTAINER_NAME "
112+ exit 1
113+ fi
114+
115+ echo " 🎉 Test completed successfully for environment: $ENVIRONMENT "
116+ echo " "
117+ echo " 🌐 Frontend is available at: http://localhost:$PORT /"
118+ echo " 🔍 To view logs: docker logs $CONTAINER_NAME "
119+ echo " 🛑 Container will be automatically stopped when script exits"
0 commit comments