mnemo_cards/tools/scripts/check_deploy_ready.sh
2025-11-20 01:41:54 +03:00

112 lines
3.2 KiB
Bash
Executable file

#!/bin/bash
# Script to check if deployment is ready
# Run this before attempting deployment
set -e
# Change to project root
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
cd "$PROJECT_ROOT"
echo "🔍 Checking deployment readiness..."
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
SERVER_IP="147.45.152.129"
SSH_KEY="${SSH_DEPLOY_KEY:-$HOME/.ssh/forgejo_deploy}"
print_status() {
echo -e "${GREEN}[OK]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
# Check 1: SSH key exists
echo "1. Checking SSH key..."
if [ -f "$SSH_KEY" ]; then
print_status "SSH private key found at $SSH_KEY"
else
print_error "SSH private key not found at $SSH_KEY"
echo " Generate with: ssh-keygen -t ed25519 -C 'forgejo-deploy@mnemo-cards.online' -f $SSH_KEY"
exit 1
fi
# Check 2: SSH connection
echo "2. Checking SSH connection..."
if ssh -o ConnectTimeout=10 -o BatchMode=yes -i "$SSH_KEY" root@$SERVER_IP "echo 'SSH OK'" 2>/dev/null; then
print_status "SSH connection to server successful"
else
print_error "Cannot connect to server via SSH"
echo " Possible causes:"
echo " 1. SSH key has a passphrase - remove it with: ssh-keygen -p -f $SSH_KEY"
echo " 2. Public key not added to server: ssh-copy-id -i $SSH_KEY.pub root@$SERVER_IP"
echo " 3. Wrong permissions on ~/.ssh directory: chmod 700 ~/.ssh && chmod 600 ~/.ssh/*"
echo " 4. Server firewall blocks SSH: check ufw status on server"
exit 1
fi
# Check 3: Required software on server
echo "3. Checking server software..."
if ssh -i "$SSH_KEY" root@$SERVER_IP "which dart nginx" >/dev/null 2>&1; then
print_status "Dart and Nginx are installed on server"
else
print_error "Dart or Nginx not found on server"
echo " Install with: apt update && apt install -y dart nginx"
exit 1
fi
# Check 4: DNS resolution
echo "4. Checking DNS resolution..."
for domain in "mnemo-cards.online" "api.mnemo-cards.online" "code.mnemo-cards.online"; do
if nslookup "$domain" 2>/dev/null | grep -q "$SERVER_IP"; then
print_status "DNS for $domain resolves to $SERVER_IP"
else
print_warning "DNS for $domain may not be configured correctly"
echo " Expected: $domain -> $SERVER_IP"
fi
done
# Check 5: Network connectivity
echo "5. Checking network connectivity..."
for port in 22 80 443 8443 8081; do
if nc -z -w5 $SERVER_IP $port 2>/dev/null; then
print_status "Port $port is accessible"
else
print_warning "Port $port is not accessible"
fi
done
# Check 6: Local tests
echo "6. Running local CI/CD tests..."
if ./test_ci_locally.sh 2>&1 | grep -q "SUCCESS.*CORS configuration check completed"; then
print_status "Local CI/CD tests passed"
else
print_warning "Local CI/CD tests failed - check output above"
fi
# Summary
echo ""
print_info "=== DEPLOYMENT READINESS SUMMARY ==="
print_info "Server IP: $SERVER_IP"
print_info "SSH Key: $SSH_KEY"
print_info ""
print_info "If all checks passed, you can proceed with deployment!"
print_info "Run: git push origin main"
echo ""