# Wait for containers to be ready (up to 60 seconds) echo "[DEPLOY] Waiting for containers to be ready..." MAX_WAIT=60 WAIT_COUNT=0 while [ $WAIT_COUNT -lt $MAX_WAIT ]; do # Check if containers are running BACKEND_RUNNING=$(docker inspect --format='{{.State.Running}}' fetch-china-backend 2>/dev/null || echo "false") FRONTEND_RUNNING=$(docker inspect --format='{{.State.Running}}' fetch-china-frontend 2>/dev/null || echo "false") if [ "$BACKEND_RUNNING" = "true" ] && [ "$FRONTEND_RUNNING" = "true" ]; then # Containers are running, do HTTP health check HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:80/ 2>/dev/null || echo "000") if [ "$HTTP_CODE" = "200" ]; then echo "[DEPLOY] SUCCESS: All containers running and website responding (HTTP $HTTP_CODE)" exit 0 fi fi WAIT_COUNT=$((WAIT_COUNT + 5)) echo "[DEPLOY] Waiting for services... ($WAIT_COUNT/$MAX_WAIT seconds)" sleep 5 done # If we get here, something went wrong echo "[ERROR] Container status after ${MAX_WAIT}s:" docker inspect --format='{{.Names}}: {{.State.Running}} ({{.State.Status}})' fetch-china-backend fetch-china-frontend 2>/dev/null || true docker-compose logs --tail=30 exit 1