#!/bin/bash # Deployment script for argeict.net server # This script deploys backend and frontend to the production server set -e # Exit on error SERVER="root@argeict.net" BACKEND_DIR="/var/www/hosting-backend" FRONTEND_DIR="/var/www/hosting-frontend" echo "🚀 Starting deployment to argeict.net..." # 1. Deploy Backend echo "" echo "📦 Deploying Backend..." ssh $SERVER "mkdir -p $BACKEND_DIR" # Copy backend files rsync -avz --exclude='venv' --exclude='__pycache__' --exclude='*.pyc' --exclude='hosting.db' \ backend/ $SERVER:$BACKEND_DIR/ # Copy .env.example as template scp backend/.env.example $SERVER:$BACKEND_DIR/.env.example echo "✅ Backend files copied" # Install dependencies and restart backend ssh $SERVER << 'ENDSSH' cd /var/www/hosting-backend # Create venv if not exists if [ ! -d "venv" ]; then echo "Creating virtual environment..." python3 -m venv venv fi # Activate venv and install dependencies source venv/bin/activate pip install --upgrade pip pip install -r requirements.txt # Check if .env exists, if not create from example if [ ! -f ".env" ]; then echo "Creating .env file..." cp .env.example .env # Generate random encryption key ENCRYPTION_KEY=$(python3 -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())") sed -i "s|ENCRYPTION_KEY=.*|ENCRYPTION_KEY=$ENCRYPTION_KEY|" .env echo "⚠️ Please edit .env file and set DATABASE_URL and other settings" fi # Initialize database if needed if [ ! -f "hosting.db" ]; then echo "Initializing database..." python3 -c "from app.main import app, db; app.app_context().push(); db.create_all()" fi # Restart backend service (if using systemd) if systemctl is-active --quiet hosting-backend; then echo "Restarting backend service..." sudo systemctl restart hosting-backend else echo "⚠️ Backend service not found. Please start manually or create systemd service." fi echo "✅ Backend deployed" ENDSSH # 2. Deploy Frontend echo "" echo "📦 Deploying Frontend..." # Build frontend locally first echo "Building frontend..." cd frontend npm install npm run build cd .. # Copy built files to server ssh $SERVER "mkdir -p $FRONTEND_DIR" rsync -avz --delete frontend/dist/ $SERVER:$FRONTEND_DIR/ echo "✅ Frontend deployed" # 3. Update Nginx configuration (if needed) echo "" echo "🔧 Checking Nginx configuration..." ssh $SERVER << 'ENDSSH' # Reload nginx if config changed if nginx -t 2>/dev/null; then echo "Reloading Nginx..." sudo systemctl reload nginx echo "✅ Nginx reloaded" else echo "⚠️ Nginx config test failed. Please check configuration." fi ENDSSH echo "" echo "✅ Deployment completed!" echo "" echo "🌐 URLs:" echo " Frontend: https://argeict.net" echo " API: https://api.argeict.net" echo " Gitea: https://gitea.argeict.net" echo "" echo "📝 Next steps:" echo " 1. SSH to server and check .env file: ssh $SERVER" echo " 2. Set DATABASE_URL in /var/www/hosting-backend/.env" echo " 3. Check backend logs: journalctl -u hosting-backend -f" echo " 4. Test API: curl https://api.argeict.net/health"