Spaces:
Running
Running
# Test script for LeRobot Arena Transport Server Docker setup | |
set -e | |
echo "π€ Testing LeRobot Arena Transport Server Docker Setup" | |
echo "==================================================" | |
# Colors for output | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
NC='\033[0m' # No Color | |
# Configuration | |
CONTAINER_NAME="lerobot-arena-transport-test" | |
PORT=7860 | |
MAX_WAIT=60 | |
# Cleanup function | |
cleanup() { | |
echo -e "\n${YELLOW}Cleaning up...${NC}" | |
docker stop $CONTAINER_NAME 2>/dev/null || true | |
docker rm $CONTAINER_NAME 2>/dev/null || true | |
} | |
# Set trap to cleanup on exit | |
trap cleanup EXIT | |
# Step 1: Build the Docker image | |
echo -e "\n${YELLOW}Step 1: Building Docker image...${NC}" | |
docker build -t lerobot-arena-transport . || { | |
echo -e "${RED}β Failed to build Docker image${NC}" | |
exit 1 | |
} | |
echo -e "${GREEN}β Docker image built successfully${NC}" | |
# Step 2: Start the container | |
echo -e "\n${YELLOW}Step 2: Starting container...${NC}" | |
docker run -d \ | |
--name $CONTAINER_NAME \ | |
-p $PORT:7860 \ | |
-e SERVE_FRONTEND=true \ | |
lerobot-arena-transport || { | |
echo -e "${RED}β Failed to start container${NC}" | |
exit 1 | |
} | |
echo -e "${GREEN}β Container started successfully${NC}" | |
# Step 3: Wait for container to be ready | |
echo -e "\n${YELLOW}Step 3: Waiting for container to be ready...${NC}" | |
COUNTER=0 | |
while [ $COUNTER -lt $MAX_WAIT ]; do | |
if curl -s http://localhost:$PORT/health > /dev/null 2>&1; then | |
echo -e "${GREEN}β Container is ready!${NC}" | |
break | |
fi | |
echo "Waiting... ($COUNTER/$MAX_WAIT)" | |
sleep 2 | |
COUNTER=$((COUNTER + 2)) | |
done | |
if [ $COUNTER -ge $MAX_WAIT ]; then | |
echo -e "${RED}β Container failed to start within $MAX_WAIT seconds${NC}" | |
echo "Container logs:" | |
docker logs $CONTAINER_NAME | |
exit 1 | |
fi | |
# Step 4: Test endpoints | |
echo -e "\n${YELLOW}Step 4: Testing endpoints...${NC}" | |
# Test health endpoint | |
echo "Testing /health endpoint..." | |
HEALTH_RESPONSE=$(curl -s http://localhost:$PORT/health) | |
if echo "$HEALTH_RESPONSE" | grep -q "healthy"; then | |
echo -e "${GREEN}β /health endpoint working${NC}" | |
else | |
echo -e "${RED}β /health endpoint failed${NC}" | |
echo "Response: $HEALTH_RESPONSE" | |
exit 1 | |
fi | |
# Test API health endpoint | |
echo "Testing /api/health endpoint..." | |
API_HEALTH_RESPONSE=$(curl -s http://localhost:$PORT/api/health) | |
if echo "$API_HEALTH_RESPONSE" | grep -q "healthy"; then | |
echo -e "${GREEN}β /api/health endpoint working${NC}" | |
else | |
echo -e "${RED}β /api/health endpoint failed${NC}" | |
echo "Response: $API_HEALTH_RESPONSE" | |
exit 1 | |
fi | |
# Test frontend | |
echo "Testing frontend..." | |
FRONTEND_RESPONSE=$(curl -s http://localhost:$PORT/) | |
if echo "$FRONTEND_RESPONSE" | grep -q "<!doctype html>" && echo "$FRONTEND_RESPONSE" | grep -q "_app/immutable"; then | |
echo -e "${GREEN}β Frontend is served correctly${NC}" | |
else | |
echo -e "${RED}β Frontend test failed${NC}" | |
echo "Response preview: $(echo "$FRONTEND_RESPONSE" | head -5)" | |
exit 1 | |
fi | |
# Test API documentation | |
echo "Testing API documentation..." | |
DOCS_RESPONSE=$(curl -s http://localhost:$PORT/api/docs) | |
if echo "$DOCS_RESPONSE" | grep -q "swagger"; then | |
echo -e "${GREEN}β API documentation accessible${NC}" | |
else | |
echo -e "${RED}β API documentation test failed${NC}" | |
exit 1 | |
fi | |
# Test robotics API | |
echo "Testing robotics API..." | |
ROBOTICS_RESPONSE=$(curl -s http://localhost:$PORT/api/robotics/rooms) | |
if [ $? -eq 0 ]; then | |
echo -e "${GREEN}β Robotics API accessible${NC}" | |
else | |
echo -e "${RED}β Robotics API test failed${NC}" | |
exit 1 | |
fi | |
# Test video API | |
echo "Testing video API..." | |
VIDEO_RESPONSE=$(curl -s http://localhost:$PORT/api/video/rooms) | |
if [ $? -eq 0 ]; then | |
echo -e "${GREEN}β Video API accessible${NC}" | |
else | |
echo -e "${RED}β Video API test failed${NC}" | |
exit 1 | |
fi | |
# Step 5: Show container information | |
echo -e "\n${YELLOW}Step 5: Container information${NC}" | |
echo "Container status:" | |
docker ps | grep $CONTAINER_NAME | |
echo -e "\nContainer resource usage:" | |
docker stats --no-stream $CONTAINER_NAME | |
# Step 6: Success summary | |
echo -e "\n${GREEN}π All tests passed successfully!${NC}" | |
echo "==================================================" | |
echo "β Docker image builds correctly" | |
echo "β Container starts and runs" | |
echo "β Health endpoints respond correctly" | |
echo "β Frontend is served" | |
echo "β API documentation is accessible" | |
echo "β Robotics API is working" | |
echo "β Video API is working" | |
echo "" | |
echo "π Access the application at: http://localhost:$PORT" | |
echo "π API docs available at: http://localhost:$PORT/api/docs" | |
echo "" | |
echo "To manually test:" | |
echo " docker run -p 7860:7860 -e SERVE_FRONTEND=true lerobot-arena-transport" | |
echo "" | |
echo -e "${YELLOW}Container will be cleaned up automatically.${NC}" |