Spaces:
Sleeping
Sleeping
File size: 13,765 Bytes
d0ae716 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
#!/bin/bash
# Comprehensive Docker test for Atari environment
# Tests: Build, Start, Health, Reset, Step, State, Cleanup
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
IMAGE_NAME="atari-env"
IMAGE_TAG="test"
CONTAINER_NAME="atari-env-test"
PORT="8765" # Use non-standard port to avoid conflicts
HEALTH_RETRIES=30
HEALTH_DELAY=2
# Cleanup function
cleanup() {
echo -e "\n${BLUE}Cleaning up...${NC}"
docker stop ${CONTAINER_NAME} 2>/dev/null || true
docker rm ${CONTAINER_NAME} 2>/dev/null || true
echo -e "${GREEN}โ${NC} Cleanup complete"
}
# Set trap to cleanup on exit
trap cleanup EXIT
# Header
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
echo " ATARI ENVIRONMENT DOCKER TEST"
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
echo ""
# Check prerequisites
echo -e "${BLUE}Checking prerequisites...${NC}"
if ! command -v docker &> /dev/null; then
echo -e "${RED}โ${NC} Docker is not installed"
exit 1
fi
echo -e "${GREEN}โ${NC} Docker is installed"
if ! command -v curl &> /dev/null; then
echo -e "${RED}โ${NC} curl is not installed"
exit 1
fi
echo -e "${GREEN}โ${NC} curl is installed"
# Check if we're in the right directory
if [ ! -f "src/envs/atari_env/server/Dockerfile" ]; then
echo -e "${RED}โ${NC} Must run from OpenEnv root directory"
exit 1
fi
echo -e "${GREEN}โ${NC} In correct directory"
# Step 1: Build Docker image
echo ""
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${BLUE}STEP 1: Building Docker Image${NC}"
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo "Building ${IMAGE_NAME}:${IMAGE_TAG}..."
if docker build -f src/envs/atari_env/server/Dockerfile -t ${IMAGE_NAME}:${IMAGE_TAG} . 2>&1 | tee /tmp/atari_build.log | tail -n 20; then
echo -e "${GREEN}โ${NC} Docker image built successfully"
else
echo -e "${RED}โ${NC} Docker build failed"
echo "See /tmp/atari_build.log for full output"
exit 1
fi
# Check image exists
if docker image inspect ${IMAGE_NAME}:${IMAGE_TAG} &> /dev/null; then
IMAGE_SIZE=$(docker image inspect ${IMAGE_NAME}:${IMAGE_TAG} --format='{{.Size}}' | awk '{print $1/1024/1024}')
echo -e "${GREEN}โ${NC} Image size: ${IMAGE_SIZE} MB"
else
echo -e "${RED}โ${NC} Image not found after build"
exit 1
fi
# Step 2: Start container
echo ""
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${BLUE}STEP 2: Starting Container${NC}"
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
# Clean up any existing container
docker rm -f ${CONTAINER_NAME} 2>/dev/null || true
echo "Starting container on port ${PORT}..."
docker run -d \
--name ${CONTAINER_NAME} \
-p ${PORT}:8000 \
-e ATARI_GAME=pong \
-e ATARI_OBS_TYPE=ram \
-e ATARI_FRAMESKIP=4 \
${IMAGE_NAME}:${IMAGE_TAG}
if [ $? -eq 0 ]; then
echo -e "${GREEN}โ${NC} Container started: ${CONTAINER_NAME}"
else
echo -e "${RED}โ${NC} Failed to start container"
exit 1
fi
# Wait for container to be running
sleep 2
if docker ps | grep -q ${CONTAINER_NAME}; then
echo -e "${GREEN}โ${NC} Container is running"
else
echo -e "${RED}โ${NC} Container is not running"
docker logs ${CONTAINER_NAME}
exit 1
fi
# Step 3: Wait for health check
echo ""
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${BLUE}STEP 3: Waiting for Server${NC}"
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo "Waiting for server to be ready (timeout: ${HEALTH_RETRIES}s)..."
for i in $(seq 1 ${HEALTH_RETRIES}); do
if curl -s http://localhost:${PORT}/health > /dev/null 2>&1; then
echo -e "${GREEN}โ${NC} Server is ready (${i}s)"
break
fi
if [ $i -eq ${HEALTH_RETRIES} ]; then
echo -e "${RED}โ${NC} Server did not become ready in time"
echo "Container logs:"
docker logs ${CONTAINER_NAME}
exit 1
fi
echo -n "."
sleep ${HEALTH_DELAY}
done
# Step 4: Test health endpoint
echo ""
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${BLUE}STEP 4: Testing Health Endpoint${NC}"
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
HEALTH_RESPONSE=$(curl -s http://localhost:${PORT}/health)
echo "Response: ${HEALTH_RESPONSE}"
if echo "${HEALTH_RESPONSE}" | grep -q "healthy"; then
echo -e "${GREEN}โ${NC} Health endpoint working"
else
echo -e "${RED}โ${NC} Health endpoint failed"
exit 1
fi
# Step 5: Test reset endpoint
echo ""
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${BLUE}STEP 5: Testing Reset Endpoint${NC}"
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
RESET_RESPONSE=$(curl -s -X POST http://localhost:${PORT}/reset -H "Content-Type: application/json" -d '{}')
if [ -z "${RESET_RESPONSE}" ]; then
echo -e "${RED}โ${NC} Reset endpoint returned empty response"
docker logs ${CONTAINER_NAME} | tail -20
exit 1
fi
echo "Response (first 200 chars): ${RESET_RESPONSE:0:200}..."
# Check if response contains expected fields
if echo "${RESET_RESPONSE}" | grep -q "observation" && \
echo "${RESET_RESPONSE}" | grep -q "screen" && \
echo "${RESET_RESPONSE}" | grep -q "legal_actions"; then
echo -e "${GREEN}โ${NC} Reset endpoint working"
# Extract some info
SCREEN_LEN=$(echo "${RESET_RESPONSE}" | grep -o '"screen":\[[^]]*\]' | wc -c)
echo " Screen data length: ${SCREEN_LEN} chars"
else
echo -e "${RED}โ${NC} Reset response missing required fields"
echo "Full response: ${RESET_RESPONSE}"
exit 1
fi
# Step 6: Test step endpoint
echo ""
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${BLUE}STEP 6: Testing Step Endpoint${NC}"
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
STEP_PAYLOAD='{"action": {"action_id": 0, "game_name": "pong"}}'
STEP_RESPONSE=$(curl -s -X POST http://localhost:${PORT}/step -H "Content-Type: application/json" -d "${STEP_PAYLOAD}")
if [ -z "${STEP_RESPONSE}" ]; then
echo -e "${RED}โ${NC} Step endpoint returned empty response"
docker logs ${CONTAINER_NAME} | tail -20
exit 1
fi
echo "Response (first 200 chars): ${STEP_RESPONSE:0:200}..."
# Check if response contains expected fields
if echo "${STEP_RESPONSE}" | grep -q "observation" && \
echo "${STEP_RESPONSE}" | grep -q "reward" && \
echo "${STEP_RESPONSE}" | grep -q "done"; then
echo -e "${GREEN}โ${NC} Step endpoint working"
# Extract reward and done
REWARD=$(echo "${STEP_RESPONSE}" | grep -o '"reward":[^,}]*' | cut -d: -f2)
DONE=$(echo "${STEP_RESPONSE}" | grep -o '"done":[^,}]*' | cut -d: -f2)
echo " Reward: ${REWARD}"
echo " Done: ${DONE}"
else
echo -e "${RED}โ${NC} Step response missing required fields"
echo "Full response: ${STEP_RESPONSE}"
exit 1
fi
# Step 7: Test state endpoint
echo ""
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${BLUE}STEP 7: Testing State Endpoint${NC}"
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
STATE_RESPONSE=$(curl -s http://localhost:${PORT}/state)
if [ -z "${STATE_RESPONSE}" ]; then
echo -e "${RED}โ${NC} State endpoint returned empty response"
docker logs ${CONTAINER_NAME} | tail -20
exit 1
fi
echo "Response: ${STATE_RESPONSE}"
# Check if response contains expected fields
if echo "${STATE_RESPONSE}" | grep -q "episode_id" && \
echo "${STATE_RESPONSE}" | grep -q "step_count" && \
echo "${STATE_RESPONSE}" | grep -q "game_name"; then
echo -e "${GREEN}โ${NC} State endpoint working"
# Extract info
GAME_NAME=$(echo "${STATE_RESPONSE}" | grep -o '"game_name":"[^"]*"' | cut -d'"' -f4)
STEP_COUNT=$(echo "${STATE_RESPONSE}" | grep -o '"step_count":[^,}]*' | cut -d: -f2)
echo " Game: ${GAME_NAME}"
echo " Steps: ${STEP_COUNT}"
else
echo -e "${RED}โ${NC} State response missing required fields"
echo "Full response: ${STATE_RESPONSE}"
exit 1
fi
# Step 8: Test multiple steps
echo ""
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${BLUE}STEP 8: Testing Multiple Steps${NC}"
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo "Taking 10 steps..."
TOTAL_REWARD=0
for i in {1..10}; do
ACTION_ID=$((RANDOM % 3)) # Random action 0-2
STEP_PAYLOAD="{\"action\": {\"action_id\": ${ACTION_ID}, \"game_name\": \"pong\"}}"
STEP_RESPONSE=$(curl -s -X POST http://localhost:${PORT}/step -H "Content-Type: application/json" -d "${STEP_PAYLOAD}")
if ! echo "${STEP_RESPONSE}" | grep -q "observation"; then
echo -e "${RED}โ${NC} Step ${i} failed"
exit 1
fi
REWARD=$(echo "${STEP_RESPONSE}" | grep -o '"reward":[^,}]*' | cut -d: -f2 | sed 's/null/0/')
DONE=$(echo "${STEP_RESPONSE}" | grep -o '"done":[^,}]*' | cut -d: -f2)
echo " Step ${i}: action=${ACTION_ID}, reward=${REWARD}, done=${DONE}"
if [ "${DONE}" = "true" ]; then
echo " Episode completed early at step ${i}"
break
fi
done
echo -e "${GREEN}โ${NC} Multiple steps completed successfully"
# Step 9: Check container logs for errors
echo ""
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
echo -e "${BLUE}STEP 9: Checking Container Logs${NC}"
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
LOGS=$(docker logs ${CONTAINER_NAME} 2>&1)
if echo "${LOGS}" | grep -i "error" | grep -v "LoggerMode.Error"; then
echo -e "${YELLOW}โ ${NC} Found errors in logs:"
echo "${LOGS}" | grep -i "error" | head -5
else
echo -e "${GREEN}โ${NC} No errors in container logs"
fi
if echo "${LOGS}" | grep -i "exception"; then
echo -e "${RED}โ${NC} Found exceptions in logs:"
echo "${LOGS}" | grep -i "exception" | head -5
exit 1
else
echo -e "${GREEN}โ${NC} No exceptions in container logs"
fi
# Final Summary
echo ""
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
echo -e "${GREEN}โ
ALL DOCKER TESTS PASSED${NC}"
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
echo ""
echo "Summary:"
echo " โ Docker image built successfully"
echo " โ Container started and ran"
echo " โ Health endpoint working"
echo " โ Reset endpoint working"
echo " โ Step endpoint working"
echo " โ State endpoint working"
echo " โ Multiple steps working"
echo " โ No errors or exceptions"
echo ""
echo "Image: ${IMAGE_NAME}:${IMAGE_TAG}"
echo "Container: ${CONTAINER_NAME}"
echo "Port: ${PORT}"
echo ""
echo "To keep container running: docker start ${CONTAINER_NAME}"
echo "To view logs: docker logs ${CONTAINER_NAME}"
echo ""
|