#!/bin/bash # Docker VP8 Webcam Recording Test Runner # ====================================== set -e CONTAINER_NAME="teto_ai_dev" OUTPUT_DIR="./output" LOG_FILE="./docker_test.log" echo "🐳 Docker VP8 Webcam Recording Test Runner" echo "==========================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color log() { echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1" | tee -a "$LOG_FILE" } success() { echo -e "${GREEN}✅ $1${NC}" | tee -a "$LOG_FILE" } warning() { echo -e "${YELLOW}⚠️ $1${NC}" | tee -a "$LOG_FILE" } error() { echo -e "${RED}❌ $1${NC}" | tee -a "$LOG_FILE" } # Function to check if container is running check_container() { if docker-compose ps | grep -q "$CONTAINER_NAME.*Up"; then return 0 else return 1 fi } # Function to wait for container to be ready wait_for_container() { log "Waiting for container to be ready..." local attempts=0 local max_attempts=30 while [ $attempts -lt $max_attempts ]; do if check_container; then # Wait a bit more for the bot to initialize sleep 5 success "Container is running and ready" return 0 fi sleep 2 attempts=$((attempts + 1)) echo -n "." done error "Container failed to start within $max_attempts attempts" return 1 } # Function to run VP8 tests inside container run_vp8_tests() { log "Running VP8 implementation tests inside container..." if docker-compose exec -T $CONTAINER_NAME node test_vp8.js; then success "VP8 implementation tests passed" return 0 else error "VP8 implementation tests failed" return 1 fi } # Function to check output directory check_output_dir() { log "Checking output directory setup..." # Check host output directory if [ -d "$OUTPUT_DIR" ]; then success "Host output directory exists: $OUTPUT_DIR" else warning "Creating host output directory: $OUTPUT_DIR" mkdir -p "$OUTPUT_DIR" fi # Check container output directory if docker-compose exec -T $CONTAINER_NAME ls /tmp/output >/dev/null 2>&1; then success "Container output directory accessible: /tmp/output" else error "Container output directory not accessible" return 1 fi # Test volume mounting local test_file="docker_test_$(date +%s).tmp" if docker-compose exec -T $CONTAINER_NAME sh -c "echo 'test' > /tmp/output/$test_file"; then if [ -f "$OUTPUT_DIR/$test_file" ]; then success "Volume mounting working correctly" rm -f "$OUTPUT_DIR/$test_file" docker-compose exec -T $CONTAINER_NAME rm -f "/tmp/output/$test_file" else error "Volume mounting not working - file not visible on host" return 1 fi else error "Cannot write to container output directory" return 1 fi } # Function to check environment variables check_environment() { log "Checking environment variables..." if [ -z "$USER_TOKEN" ]; then error "USER_TOKEN environment variable not set" echo "Please run: export USER_TOKEN=\"your_discord_token\"" return 1 else success "USER_TOKEN is set" fi # Check other optional variables if [ -n "$BOT_CLIENT_ID" ]; then success "BOT_CLIENT_ID is set" else warning "BOT_CLIENT_ID not set (optional)" fi } # Function to show container logs show_logs() { log "Recent container logs:" echo "====================" docker-compose logs --tail=20 $CONTAINER_NAME echo "====================" } # Function to test Docker networking test_networking() { log "Testing Docker networking capabilities..." # Test basic connectivity if docker-compose exec -T $CONTAINER_NAME ping -c 1 8.8.8.8 >/dev/null 2>&1; then success "Container has internet connectivity" else error "Container networking issues - no internet" return 1 fi # Test Discord connectivity if docker-compose exec -T $CONTAINER_NAME curl -s https://discord.com >/dev/null 2>&1; then success "Container can reach Discord servers" else warning "Cannot reach Discord servers (may be temporary)" fi } # Function to check FFmpeg check_ffmpeg() { log "Checking FFmpeg in container..." if docker-compose exec -T $CONTAINER_NAME ffmpeg -version >/dev/null 2>&1; then success "FFmpeg is available in container" # Check VP8 codec support if docker-compose exec -T $CONTAINER_NAME ffmpeg -codecs 2>/dev/null | grep -q "libvpx"; then success "VP8 codec support confirmed" else warning "VP8 codec support unclear" fi else error "FFmpeg not available in container" return 1 fi } # Function to run readiness check inside container run_readiness_check() { log "Running comprehensive readiness check..." if docker-compose exec -T $CONTAINER_NAME node check_ready.js; then success "Readiness check passed" return 0 else error "Readiness check failed" return 1 fi } # Main test sequence main() { log "Starting Docker VP8 test sequence..." echo > "$LOG_FILE" # Clear log file # Pre-flight checks log "=== PRE-FLIGHT CHECKS ===" check_environment || exit 1 # Start container if not running if ! check_container; then log "Starting Docker container..." docker-compose up -d --build else log "Container already running" fi wait_for_container || exit 1 # Run all tests log "=== CONTAINER TESTS ===" check_output_dir || exit 1 test_networking || exit 1 check_ffmpeg || exit 1 run_vp8_tests || exit 1 run_readiness_check || exit 1 # Final status log "=== FINAL STATUS ===" success "All Docker VP8 tests passed!" echo "" echo "🎉 Container is ready for VP8 webcam recording!" echo "" echo "Next steps:" echo "1. Join a Discord voice channel" echo "2. Run: test vp8" echo "3. Run: record webcam" echo "4. Check output: ls -la $OUTPUT_DIR" echo "" echo "Monitor logs: docker-compose logs -f $CONTAINER_NAME" echo "Access VNC: localhost:5901" echo "" } # Handle script arguments case "${1:-test}" in "test") main ;; "logs") docker-compose logs -f $CONTAINER_NAME ;; "shell") docker-compose exec $CONTAINER_NAME /bin/bash ;; "stop") docker-compose down ;; "restart") docker-compose restart $CONTAINER_NAME ;; "clean") docker-compose down -v --remove-orphans docker system prune -f ;; "help"|"-h"|"--help") echo "Docker VP8 Test Runner" echo "Usage: $0 [command]" echo "" echo "Commands:" echo " test Run full test suite (default)" echo " logs Follow container logs" echo " shell Open shell in container" echo " stop Stop container" echo " restart Restart container" echo " clean Clean up containers and volumes" echo " help Show this help" ;; *) error "Unknown command: $1" echo "Run '$0 help' for usage information" exit 1 ;; esac