chore: consolidate docker-compose and add integration tests
- Merge infrastructure/docker-compose.yml + docker-compose.app.yml into root docker-compose.yml with profiles (infra/app). - Add healthchecks for mysql/redis/rabbitmq/mci-server/channel-service and depends_on conditions. - Rewrite scripts/local-up.sh to use profiles and wait for healthy states. - Add curl to mci-server and channel-service Docker images for healthchecks. - Add npm test script to admin-web (type-check + build smoke test). - Add scripts/test-external-api.sh covering 11 API endpoints. - Verify Java (7/7), Python (6/6), npm build, external API (11/11), and UI flows.
This commit is contained in:
@@ -4,47 +4,42 @@ set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR/.."
|
||||
|
||||
echo "Creating shared network..."
|
||||
docker network create mci-network 2>/dev/null || true
|
||||
wait_for_healthy() {
|
||||
local service=$1
|
||||
local max_retries=${2:-60}
|
||||
local retry_count=0
|
||||
local container_name
|
||||
|
||||
echo "Starting local infrastructure..."
|
||||
docker compose -f infrastructure/docker-compose.yml up -d
|
||||
echo "Waiting for $service to become healthy..."
|
||||
while [ "$retry_count" -lt "$max_retries" ]; do
|
||||
container_name=$(docker compose --profile infra --profile app ps -q "$service" 2>/dev/null | head -n1)
|
||||
|
||||
echo "Waiting for MySQL..."
|
||||
MAX_RETRIES=60
|
||||
RETRY_COUNT=0
|
||||
until docker exec mci-mysql mysql -uroot -proot -e "SELECT 1" > /dev/null 2>&1; do
|
||||
RETRY_COUNT=$((RETRY_COUNT + 1))
|
||||
if [ "$RETRY_COUNT" -ge "$MAX_RETRIES" ]; then
|
||||
echo "MySQL did not become ready within ${MAX_RETRIES} seconds."
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
if [ -n "$container_name" ]; then
|
||||
local status
|
||||
status=$(docker inspect --format='{{.State.Health.Status}}' "$container_name" 2>/dev/null || true)
|
||||
if [ "$status" = "healthy" ]; then
|
||||
echo "$service is healthy."
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Waiting for Redis..."
|
||||
RETRY_COUNT=0
|
||||
until docker exec mci-redis redis-cli ping | grep -q "PONG"; do
|
||||
RETRY_COUNT=$((RETRY_COUNT + 1))
|
||||
if [ "$RETRY_COUNT" -ge 30 ]; then
|
||||
echo "Redis did not become ready within 30 seconds."
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
retry_count=$((retry_count + 1))
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "Waiting for RabbitMQ..."
|
||||
RETRY_COUNT=0
|
||||
until curl -s -o /dev/null -w "%{http_code}" http://guest:guest@localhost:15672/api/overview | grep -q "200"; do
|
||||
RETRY_COUNT=$((RETRY_COUNT + 1))
|
||||
if [ "$RETRY_COUNT" -ge 30 ]; then
|
||||
echo "RabbitMQ did not become ready within 30 seconds."
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
echo "$service did not become healthy within $((max_retries * 2)) seconds."
|
||||
docker compose --profile infra --profile app logs --tail=50 "$service"
|
||||
return 1
|
||||
}
|
||||
|
||||
echo "Local infrastructure is ready."
|
||||
echo "Starting infrastructure services..."
|
||||
docker compose --profile infra up -d
|
||||
|
||||
wait_for_healthy mysql 60
|
||||
wait_for_healthy redis 30
|
||||
wait_for_healthy rabbitmq 60
|
||||
|
||||
echo "Infrastructure is ready."
|
||||
echo "MySQL: jdbc:mysql://localhost:3306/sino_mci"
|
||||
echo "Redis: localhost:6379"
|
||||
echo "RabbitMQ: localhost:5672 / http://localhost:15672"
|
||||
@@ -52,7 +47,13 @@ echo "SeaweedFS: http://localhost:9333"
|
||||
|
||||
if [ "$1" == "--with-apps" ]; then
|
||||
echo "Starting application services..."
|
||||
docker compose -f docker-compose.app.yml up -d --build
|
||||
# Include infra profile so that depends_on conditions can resolve.
|
||||
docker compose --profile infra --profile app up -d --build
|
||||
|
||||
wait_for_healthy mci-server 90
|
||||
wait_for_healthy channel-service 60
|
||||
|
||||
echo "Application services are ready."
|
||||
echo "Admin Web: http://localhost"
|
||||
echo "Backend API: http://localhost:8080/msg-platform"
|
||||
echo "Channel Service: http://localhost:8000"
|
||||
|
||||
Reference in New Issue
Block a user