91 lines
2.6 KiB
Bash
Executable file
91 lines
2.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Deployment script for Mnemo Cards Web App
|
|
# 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 Flutter web app for production
|
|
build_flutter_app
|
|
|
|
print_status "Uploading files to server using rsync..."
|
|
# Upload files directly using rsync (much faster and more reliable)
|
|
rsync -avz --delete build/web/ "$SERVER_USER@$SERVER_IP:$WEB_ROOT/"
|
|
|
|
print_status "Uploading nginx configuration..."
|
|
# Upload nginx config separately
|
|
scp deploy/nginx.conf "$SERVER_USER@$SERVER_IP:/tmp/nginx.conf"
|
|
|
|
print_status "Deploying on server..."
|
|
# Execute deployment commands on server
|
|
ssh "$SERVER_USER@$SERVER_IP" << EOF
|
|
set -e
|
|
|
|
# Create 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 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
|
|
|
|
# Install SSL certificate first (self-signed for now)
|
|
if [ ! -f "$SSL_SELF_CERT" ]; then
|
|
echo "Generating self-signed SSL certificate..."
|
|
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
|
|
-keyout $SSL_SELF_KEY \
|
|
-out $SSL_SELF_CERT \
|
|
-subj "/C=RU/ST=Moscow/L=Moscow/O=MnemoCards/OU=IT/CN=$SERVER_IP"
|
|
fi
|
|
|
|
# Configure nginx
|
|
echo "Configuring nginx..."
|
|
|
|
# Install nginx if not installed
|
|
if ! command -v nginx &> /dev/null; then
|
|
apt update
|
|
apt install -y nginx
|
|
fi
|
|
|
|
# Copy nginx configuration
|
|
cp /tmp/nginx.conf $NGINX_CONFIG
|
|
|
|
# Enable site
|
|
ln -sf $NGINX_CONFIG $NGINX_ENABLED
|
|
|
|
# Remove default nginx site if it exists
|
|
rm -f /etc/nginx/sites-enabled/default
|
|
|
|
# Test nginx configuration
|
|
nginx -t
|
|
|
|
# Restart nginx
|
|
systemctl restart nginx
|
|
systemctl enable nginx
|
|
|
|
# Configure firewall
|
|
ufw allow '$FIREWALL_ALLOW_NGINX'
|
|
ufw allow $FIREWALL_ALLOW_SSH
|
|
ufw --force enable
|
|
|
|
echo "Deployment completed successfully!"
|
|
echo "Application is available at: https://$SERVER_IP"
|
|
EOF
|
|
|
|
print_success "Deployment completed successfully! 🎉"
|
|
print_success "Your app is now available at: https://$SERVER_IP"
|
|
print_warning "Note: The SSL certificate is self-signed. For production, consider using Let's Encrypt or a commercial certificate."
|