#!/bin/bash # Binary Validation Script - Prevents deploying wrong binaries # Usage: ./validate_binary.sh set -e BINARY_NAME="$1" if [ -z "$BINARY_NAME" ]; then echo "โŒ Usage: $0 " exit 1 fi LOCAL_PATH="target/release/examples/${BINARY_NAME}" S3_KEY="binaries/current/${BINARY_NAME}" S3_ENDPOINT="https://s3api-eur-is-1.runpod.io" S3_BUCKET="se3zdnb5o4" echo "========================================" echo "Binary Validation: ${BINARY_NAME}" echo "========================================" # 1. Check local binary exists if [ ! -f "$LOCAL_PATH" ]; then echo "โŒ FAIL: Local binary not found at $LOCAL_PATH" exit 1 fi echo "โœ… Local binary exists" # 2. Test local binary works (basic smoke test) echo "๐Ÿงช Testing local binary..." if [[ "$BINARY_NAME" == hyperopt* ]]; then # Test hyperopt binaries with --help if ! $LOCAL_PATH --help &>/dev/null; then echo "โŒ FAIL: Local binary --help failed" exit 1 fi # Verify critical arguments present if ! $LOCAL_PATH --help 2>&1 | grep -q -- "--base-dir"; then echo "โŒ FAIL: Local binary missing --base-dir argument" echo "This binary was built BEFORE VarMap fix!" exit 1 fi fi echo "โœ… Local binary works and has correct arguments" # 3. Calculate local SHA256 echo "๐Ÿ” Calculating local SHA256..." LOCAL_SHA256=$(sha256sum "$LOCAL_PATH" | awk '{print $1}') echo "Local SHA256: $LOCAL_SHA256" # 4. Check if S3 binary exists echo "๐Ÿ” Checking S3 binary..." if ! aws s3api head-object \ --bucket "$S3_BUCKET" \ --key "$S3_KEY" \ --endpoint-url "$S3_ENDPOINT" \ --profile runpod &>/dev/null; then echo "โš ๏ธ S3 binary does not exist - will be uploaded" echo "VALIDATION: LOCAL_ONLY" exit 0 fi # 5. Get S3 metadata S3_SIZE=$(aws s3api head-object \ --bucket "$S3_BUCKET" \ --key "$S3_KEY" \ --endpoint-url "$S3_ENDPOINT" \ --profile runpod \ | jq -r '.ContentLength') S3_MODIFIED=$(aws s3api head-object \ --bucket "$S3_BUCKET" \ --key "$S3_KEY" \ --endpoint-url "$S3_ENDPOINT" \ --profile runpod \ | jq -r '.LastModified') echo "S3 Size: $S3_SIZE bytes" echo "S3 Modified: $S3_MODIFIED" # 6. Download S3 binary to temp location for checksum echo "โฌ‡๏ธ Downloading S3 binary for checksum..." TEMP_S3="/tmp/${BINARY_NAME}_s3_$$" aws s3 cp \ "s3://${S3_BUCKET}/${S3_KEY}" \ "$TEMP_S3" \ --endpoint-url "$S3_ENDPOINT" \ --profile runpod \ --quiet # 7. Calculate S3 SHA256 echo "๐Ÿ” Calculating S3 SHA256..." S3_SHA256=$(sha256sum "$TEMP_S3" | awk '{print $1}') echo "S3 SHA256: $S3_SHA256" # 8. Cleanup temp file rm -f "$TEMP_S3" # 9. Compare checksums echo "" echo "========================================" if [ "$LOCAL_SHA256" = "$S3_SHA256" ]; then echo "โœ… VALIDATION PASSED" echo "Local and S3 binaries match perfectly" echo "========================================" exit 0 else echo "โŒ VALIDATION FAILED" echo "Local and S3 binaries DO NOT MATCH" echo "" echo "Local: $LOCAL_SHA256" echo "S3: $S3_SHA256" echo "" echo "REQUIRED ACTION:" echo "1. Delete S3 binary: aws s3 rm s3://${S3_BUCKET}/${S3_KEY} --endpoint-url $S3_ENDPOINT --profile runpod" echo "2. Upload local binary: aws s3 cp $LOCAL_PATH s3://${S3_BUCKET}/${S3_KEY} --endpoint-url $S3_ENDPOINT --profile runpod" echo "3. Re-run validation" echo "========================================" exit 1 fi