modern-django-starter/scripts/pre-deploy-check.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

105 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# Pre-deployment validation script
# Run this before every deployment to catch issues early
set -e
echo "🔍 Running pre-deployment checks..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print status
print_status() {
if [ $1 -eq 0 ]; then
echo -e "${GREEN}$2${NC}"
else
echo -e "${RED}$2${NC}"
exit 1
fi
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
# Check 1: Verify Tailwind CSS is built
echo "📦 Checking Tailwind CSS files..."
if [ -f "theme/static/css/dist/styles.css" ]; then
print_status 0 "Tailwind CSS files exist"
else
print_status 1 "Tailwind CSS not built. Run: cd theme/static_src && npm run build"
fi
# Check 2: Test collectstatic
echo "📁 Testing static file collection..."
if python manage.py collectstatic --noinput --dry-run > /dev/null 2>&1; then
print_status 0 "Static files collection test passed"
else
print_status 1 "Static files collection failed. Check STATIC_ROOT and STATICFILES_DIRS"
fi
# Check 3: Check for pending migrations
echo "🗄️ Checking for pending migrations..."
if python manage.py showmigrations --plan | grep -q "\[ \]"; then
print_status 1 "Pending migrations found. Run: python manage.py makemigrations"
else
print_status 0 "No pending migrations"
fi
# Check 4: Validate Django configuration
echo "⚙️ Validating Django settings..."
if python manage.py check > /dev/null 2>&1; then
print_status 0 "Django configuration valid"
else
print_status 1 "Django configuration issues found. Run: python manage.py check"
fi
# Check 5: Test Docker build
echo "🐳 Testing Docker build..."
if docker build --target production -t django-deploy-test . > /dev/null 2>&1; then
print_status 0 "Docker build successful"
docker rmi django-deploy-test > /dev/null 2>&1 || true
else
print_status 1 "Docker build failed. Check Dockerfile"
fi
# Check 6: Verify startup script
echo "🚀 Checking startup script..."
if [ -x "startup.sh" ]; then
print_status 0 "Startup script is executable"
else
print_status 1 "Startup script not executable. Run: chmod +x startup.sh"
fi
# Check 7: Validate environment variables
echo "🔐 Checking environment configuration..."
if [ -f ".env.example" ]; then
print_status 0 "Environment example file exists"
else
print_warning "No .env.example file found. Consider creating one"
fi
# Check 8: Verify required files
required_files=("manage.py" "requirements/production.txt" "docker-compose.dokploy-simple.yml")
for file in "${required_files[@]}"; do
if [ -f "$file" ]; then
print_status 0 "Required file exists: $file"
else
print_status 1 "Missing required file: $file"
fi
done
echo ""
echo -e "${GREEN}🎉 All pre-deployment checks passed!${NC}"
echo -e "${GREEN}✅ Ready for deployment!${NC}"
echo ""
echo "Next steps:"
echo "1. git add . && git commit -m 'Ready for deployment' && git push"
echo "2. Deploy in Dokploy"
echo "3. Test endpoints after deployment"