2025-12-02 23:28:12 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
# Deployment script for Mnemo Cards Admin Panel
|
|
|
|
|
|
# Usage: ./deploy.sh
|
|
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
|
|
# Load configuration
|
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
|
|
source "$SCRIPT_DIR/config.sh"
|
|
|
|
|
|
|
|
|
|
|
|
echo "🚀 Starting deployment of $APP_TITLE..."
|
|
|
|
|
|
|
|
|
|
|
|
# Check if we're in the right directory
|
|
|
|
|
|
check_project_root
|
|
|
|
|
|
|
|
|
|
|
|
# Build the React app for production
|
|
|
|
|
|
build_react_app
|
|
|
|
|
|
|
|
|
|
|
|
print_status "Uploading files to server using rsync..."
|
|
|
|
|
|
# Upload files directly using rsync (much faster and more reliable)
|
|
|
|
|
|
rsync -avz --delete $BUILD_DIR/ "$SERVER_USER@$SERVER_IP:$WEB_ROOT/"
|
|
|
|
|
|
|
|
|
|
|
|
print_status "Uploading nginx configuration..."
|
|
|
|
|
|
# Upload nginx config separately
|
|
|
|
|
|
scp nginx.conf "$SERVER_USER@$SERVER_IP:/tmp/admin_nginx.conf"
|
|
|
|
|
|
|
|
|
|
|
|
print_status "Deploying on server..."
|
|
|
|
|
|
# Execute deployment commands on server
|
|
|
|
|
|
ssh "$SERVER_USER@$SERVER_IP" << EOF
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
|
|
# Create admin web directory if it doesn't exist
|
|
|
|
|
|
mkdir -p $WEB_ROOT
|
|
|
|
|
|
|
|
|
|
|
|
# Backup existing deployment
|
|
|
|
|
|
if [ -d "$WEB_ROOT" ] && [ "\$(ls -A $WEB_ROOT)" ]; then
|
|
|
|
|
|
echo "Creating backup of existing admin deployment..."
|
|
|
|
|
|
cp -r $WEB_ROOT $BACKUP_DIR.\$(date +%Y%m%d_%H%M%S)
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Set proper permissions
|
|
|
|
|
|
chown -R $WEB_USER:$WEB_GROUP $WEB_ROOT
|
|
|
|
|
|
chmod -R $WEB_PERMISSIONS $WEB_ROOT
|
|
|
|
|
|
|
2025-12-03 01:22:59 +00:00
|
|
|
|
# SSL certificate is managed centrally via setup_ssl.sh during backend deployment
|
2025-12-03 00:56:29 +00:00
|
|
|
|
if [ -d "/etc/letsencrypt/live/admin.mnemo-cards.online" ] && [ -f "/etc/letsencrypt/live/admin.mnemo-cards.online/fullchain.pem" ]; then
|
2025-12-02 23:28:12 +00:00
|
|
|
|
echo "✅ Let's Encrypt certificate exists for admin.mnemo-cards.online"
|
|
|
|
|
|
else
|
2025-12-03 01:22:59 +00:00
|
|
|
|
echo "❌ SSL certificate not found for admin.mnemo-cards.online"
|
|
|
|
|
|
echo " Certificate should be created by setup_ssl.sh during backend deployment"
|
|
|
|
|
|
exit 1
|
2025-12-02 23:28:12 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Configure nginx
|
|
|
|
|
|
echo "Configuring nginx for admin panel..."
|
|
|
|
|
|
|
|
|
|
|
|
# Install nginx if not installed
|
|
|
|
|
|
if ! command -v nginx &> /dev/null; then
|
|
|
|
|
|
apt update
|
|
|
|
|
|
apt install -y nginx
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Copy nginx configuration
|
|
|
|
|
|
cp /tmp/admin_nginx.conf $NGINX_CONFIG
|
|
|
|
|
|
|
|
|
|
|
|
# Enable site
|
|
|
|
|
|
ln -sf $NGINX_CONFIG $NGINX_ENABLED
|
|
|
|
|
|
|
|
|
|
|
|
# Remove default nginx site if it exists (only if no other sites exist)
|
|
|
|
|
|
if [ ! -L "/etc/nginx/sites-enabled/mnemo_cards" ]; then
|
|
|
|
|
|
rm -f /etc/nginx/sites-enabled/default
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Test nginx configuration
|
2025-12-03 00:13:30 +00:00
|
|
|
|
/usr/sbin/nginx -t
|
2025-12-02 23:28:12 +00:00
|
|
|
|
|
|
|
|
|
|
# Restart nginx
|
|
|
|
|
|
systemctl restart nginx
|
|
|
|
|
|
systemctl enable nginx
|
|
|
|
|
|
|
|
|
|
|
|
# Configure firewall (ports should already be open)
|
2025-12-03 00:13:30 +00:00
|
|
|
|
# Note: ufw may not be available in all environments
|
|
|
|
|
|
if command -v ufw &> /dev/null; then
|
|
|
|
|
|
ufw allow '$FIREWALL_ALLOW_NGINX' 2>/dev/null || true
|
|
|
|
|
|
ufw allow $FIREWALL_ALLOW_SSH 2>/dev/null || true
|
|
|
|
|
|
ufw --force enable 2>/dev/null || true
|
|
|
|
|
|
echo "✅ Firewall configured"
|
|
|
|
|
|
else
|
|
|
|
|
|
echo "ℹ️ UFW not available, skipping firewall configuration"
|
|
|
|
|
|
fi
|
2025-12-02 23:28:12 +00:00
|
|
|
|
|
|
|
|
|
|
echo "Admin panel deployment completed successfully!"
|
|
|
|
|
|
echo "Application is available at: https://admin.mnemo-cards.online"
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
|
|
print_success "Deployment completed successfully! 🎉"
|
|
|
|
|
|
print_success "Admin panel is now available at: https://admin.mnemo-cards.online"
|
|
|
|
|
|
print_info "SSL certificate: Let's Encrypt (preferred) or self-signed (fallback)"
|