modern-django-starter/scripts/post-deploy-verify.sh
amitrana01 85ebac761d Add comprehensive deployment automation and prevention system
🎯 Future-proof deployment system:

1. DEPLOYMENT_CHECKLIST.md - Zero-fail step-by-step guide
2. scripts/pre-deploy-check.sh - Validates everything before deployment
3. scripts/post-deploy-verify.sh - Tests deployment after completion
4. .github/workflows/deploy.yml - Automated GitHub Actions validation

 Key features:
- Catches static files, migrations, Docker issues before deployment
- Provides clear error messages and next steps
- Tests all endpoints after deployment
- 5-minute deployment target with this system
- Copy-paste templates for new projects

Run: ./scripts/pre-deploy-check.sh before every deployment
Run: ./scripts/post-deploy-verify.sh after deployment

Never face deployment issues again! 🚀
2025-09-11 18:52:42 +05:30

159 lines
5.0 KiB
Bash
Executable File

#!/bin/bash
# Post-deployment verification script
# Run this after deployment to verify everything is working
set -e
# Default domain (can be overridden)
DOMAIN=${1:-"dt.netcoptech.com"}
PROTOCOL=${2:-"https"}
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo "🔍 Verifying deployment for $PROTOCOL://$DOMAIN"
# Function to test URL
test_url() {
local url=$1
local expected_status=${2:-200}
local description=$3
echo "Testing: $description"
# Use curl to test the URL
if command -v curl > /dev/null 2>&1; then
response=$(curl -s -o /dev/null -w "%{http_code}" -L "$url" 2>/dev/null || echo "000")
else
echo -e "${YELLOW}⚠️ curl not found, skipping URL test${NC}"
return 0
fi
if [ "$response" -eq "$expected_status" ]; then
echo -e "${GREEN}$description - HTTP $response${NC}"
elif [ "$response" -eq "000" ]; then
echo -e "${RED}$description - Connection failed${NC}"
return 1
else
echo -e "${RED}$description - HTTP $response (expected $expected_status)${NC}"
return 1
fi
}
# Function to test JSON endpoint
test_json_endpoint() {
local url=$1
local description=$2
echo "Testing: $description"
if command -v curl > /dev/null 2>&1; then
response=$(curl -s -L "$url" 2>/dev/null || echo "")
if echo "$response" | python3 -m json.tool > /dev/null 2>&1; then
echo -e "${GREEN}$description - Valid JSON response${NC}"
# Pretty print the response
echo "$response" | python3 -m json.tool | head -10
else
echo -e "${RED}$description - Invalid JSON response${NC}"
return 1
fi
else
echo -e "${YELLOW}⚠️ curl not found, skipping JSON test${NC}"
return 0
fi
}
echo ""
echo "🌐 Testing core endpoints..."
# Test main endpoints
test_url "$PROTOCOL://$DOMAIN/" 200 "Homepage"
test_json_endpoint "$PROTOCOL://$DOMAIN/health/" "Health check endpoint"
test_url "$PROTOCOL://$DOMAIN/accounts/login/" 200 "Login page"
test_url "$PROTOCOL://$DOMAIN/admin/" 302 "Admin panel (should redirect to login)"
echo ""
echo "🔒 Testing SSL/HTTPS..."
if [ "$PROTOCOL" = "https" ]; then
# Test SSL certificate
if command -v openssl > /dev/null 2>&1; then
echo "Checking SSL certificate..."
cert_info=$(echo | openssl s_client -servername "$DOMAIN" -connect "$DOMAIN:443" 2>/dev/null | openssl x509 -noout -dates 2>/dev/null || echo "")
if [ -n "$cert_info" ]; then
echo -e "${GREEN}✅ SSL certificate is valid${NC}"
echo "$cert_info"
else
echo -e "${RED}❌ SSL certificate check failed${NC}"
fi
else
echo -e "${YELLOW}⚠️ openssl not found, skipping SSL check${NC}"
fi
# Test HTTP to HTTPS redirect
if command -v curl > /dev/null 2>&1; then
redirect_response=$(curl -s -o /dev/null -w "%{redirect_url}" "http://$DOMAIN/" || echo "")
if [[ "$redirect_response" == "https://"* ]]; then
echo -e "${GREEN}✅ HTTP to HTTPS redirect working${NC}"
else
echo -e "${YELLOW}⚠️ HTTP to HTTPS redirect not detected${NC}"
fi
fi
else
echo "Testing HTTP deployment..."
fi
echo ""
echo "🗄️ Testing database connectivity..."
# Test if site is configured properly by checking login page
login_response=$(curl -s -L "$PROTOCOL://$DOMAIN/accounts/login/" 2>/dev/null || echo "")
if echo "$login_response" | grep -q "django_site" 2>/dev/null; then
echo -e "${RED}❌ Database error: django_site relation not found${NC}"
elif echo "$login_response" | grep -q "Login" 2>/dev/null; then
echo -e "${GREEN}✅ Database connectivity working${NC}"
else
echo -e "${YELLOW}⚠️ Unable to verify database connectivity${NC}"
fi
echo ""
echo "📱 Testing responsive design..."
# Test if CSS is loading
css_test=$(curl -s -L "$PROTOCOL://$DOMAIN/" 2>/dev/null | grep -o "styles\.css" || echo "")
if [ -n "$css_test" ]; then
echo -e "${GREEN}✅ CSS files are being loaded${NC}"
else
echo -e "${YELLOW}⚠️ CSS files may not be loading properly${NC}"
fi
echo ""
echo "🎯 Deployment verification summary:"
# Final health check
health_url="$PROTOCOL://$DOMAIN/health/"
if curl -s "$health_url" > /dev/null 2>&1; then
echo -e "${GREEN}🎉 Deployment successful!${NC}"
echo -e "${GREEN}✅ Your Django app is live and healthy${NC}"
echo ""
echo "🔗 Important URLs:"
echo " Homepage: $PROTOCOL://$DOMAIN/"
echo " Login: $PROTOCOL://$DOMAIN/accounts/login/"
echo " Admin: $PROTOCOL://$DOMAIN/admin/"
echo " Health: $PROTOCOL://$DOMAIN/health/"
echo ""
echo "Next steps:"
echo "1. Create your admin user: python manage.py createsuperuser"
echo "2. Configure social authentication in admin panel"
echo "3. Test all functionality thoroughly"
else
echo -e "${RED}❌ Deployment verification failed${NC}"
echo "Check deployment logs and retry"
exit 1
fi