server_update.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. # Скрипт автоматического обновления сайта
  3. PROJECT_DIR="/var/www/radionica3d"
  4. echo "==== DEPLOY STARTING: $(date) ===="
  5. cd $PROJECT_DIR
  6. # 1. Забираем код
  7. echo "git pull..."
  8. git pull origin master
  9. # 2. Собираем фронтенд
  10. echo "building frontend..."
  11. npm install --legacy-peer-deps
  12. # 2. Собираем фронтенд
  13. echo "building frontend..."
  14. rm -rf dist/ # Clean old build
  15. npm install --legacy-peer-deps
  16. bash build_frontend.sh
  17. # 3. Обновляем бэкенд
  18. echo "updating backend..."
  19. ./backend/venv/bin/pip install -r backend/requirements.txt
  20. echo "running database migrations..."
  21. # Create backup before migrating
  22. mkdir -p backups
  23. echo "Backing up database to backups/ folder..."
  24. # If you use a .env file for DB credentials, source it here:
  25. # [ -f .env ] && export $(grep -v '^#' .env | xargs)
  26. mysqldump --no-tablespaces -h ${DB_HOST:-localhost} -u ${DB_USER:-radionica} -p${DB_PASS:-NY9B9VLifDC9ehZ} ${DB_NAME:-radionica3d} > backups/db_pre_migration_$(date +%Y%m%d_%H%M%S).sql
  27. ./backend/venv/bin/python3 backend/run_migrations.py
  28. # 4. Перезапуск
  29. echo "restarting services..."
  30. sudo chown -R www-data:www-data $PROJECT_DIR
  31. sudo systemctl restart radionica-backend
  32. cp /var/www/radionica3d/nginx.conf /etc/nginx/sites-available/radionica3d
  33. sudo systemctl reload nginx
  34. echo "==== DEPLOY FINISHED: $(date) ===="