Files
ivatar/scripts/test_deployment.sh
Oliver Falk cfa3d11b35 Fix logging directory permission handling
- Add robust writeability testing for logs directory
- Implement fallback hierarchy: logs/ → /tmp/libravatar-logs → user-specific temp
- Handle cases where directory exists but isn't writable
- Prevent Django startup failures due to permission errors

Resolves development instance startup issues with /var/www/dev.libravatar.org/logs/
2025-10-16 12:36:42 +02:00

126 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
# Test deployment verification script
set -e
# Configuration
DEV_URL="https://dev.libravatar.org"
PROD_URL="https://libravatar.org"
MAX_RETRIES=5
RETRY_DELAY=10
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to test deployment
test_deployment() {
local url=$1
local name=$2
local max_retries=$3
echo -e "${YELLOW}Testing $name deployment at $url${NC}"
for i in $(seq 1 $max_retries); do
echo "Attempt $i/$max_retries: Checking $name deployment..."
# Check if site is responding
if curl -sf "$url/deployment/version/" >/dev/null 2>&1; then
echo "$name site is responding, checking version..."
# Get deployed version info
VERSION_INFO=$(curl -sf "$url/deployment/version/")
echo "Version info: $VERSION_INFO"
# Extract commit hash
COMMIT_HASH=$(echo "$VERSION_INFO" | jq -r '.commit_hash // empty')
BRANCH=$(echo "$VERSION_INFO" | jq -r '.branch // empty')
VERSION=$(echo "$VERSION_INFO" | jq -r '.version // empty')
echo "Deployed commit: $COMMIT_HASH"
echo "Deployed branch: $BRANCH"
echo "Deployed version: $VERSION"
# Run basic functionality tests
echo "Running basic functionality tests..."
# Test avatar endpoint
if curl -sf "$url/avatar/test@example.com" >/dev/null; then
echo -e "${GREEN}✅ Avatar endpoint working${NC}"
else
echo -e "${RED}❌ Avatar endpoint failed${NC}"
return 1
fi
# Test stats endpoint
if curl -sf "$url/stats/" >/dev/null; then
echo -e "${GREEN}✅ Stats endpoint working${NC}"
else
echo -e "${RED}❌ Stats endpoint failed${NC}"
return 1
fi
echo -e "${GREEN}🎉 $name deployment verification completed successfully!${NC}"
return 0
else
echo "$name site not responding yet..."
fi
if [ $i -lt $max_retries ]; then
echo "Waiting $RETRY_DELAY seconds before next attempt..."
sleep $RETRY_DELAY
fi
done
echo -e "${RED}❌ FAILED: $name deployment verification timed out after $max_retries attempts${NC}"
return 1
}
# Main execution
echo "Libravatar Deployment Verification Script"
echo "=========================================="
# Check if jq is available
if ! command -v jq &>/dev/null; then
echo -e "${RED}Error: jq is required but not installed${NC}"
echo "Install with: brew install jq (macOS) or apt-get install jq (Ubuntu)"
exit 1
fi
# Test dev deployment
echo ""
test_deployment "$DEV_URL" "Dev" $MAX_RETRIES
DEV_RESULT=$?
# Test production deployment
echo ""
test_deployment "$PROD_URL" "Production" $MAX_RETRIES
PROD_RESULT=$?
# Summary
echo ""
echo "=========================================="
echo "Deployment Verification Summary:"
echo "=========================================="
if [ $DEV_RESULT -eq 0 ]; then
echo -e "${GREEN}✅ Dev deployment: PASSED${NC}"
else
echo -e "${RED}❌ Dev deployment: FAILED${NC}"
fi
if [ $PROD_RESULT -eq 0 ]; then
echo -e "${GREEN}✅ Production deployment: PASSED${NC}"
else
echo -e "${RED}❌ Production deployment: FAILED${NC}"
fi
# Exit with error if any test failed
if [ $DEV_RESULT -ne 0 ] || [ $PROD_RESULT -ne 0 ]; then
exit 1
fi
echo -e "${GREEN}🎉 All deployment verifications passed!${NC}"