chore: update Python version in Dockerfile and improve test commands in Makefile
- Upgraded Python version in Dockerfile from 3.9 to 3.11.9 for enhanced performance and security. - Adjusted paths in Dockerfile to reflect the new Python version. - Modified test commands in Makefile to activate the virtual environment before running tests, ensuring proper dependency management.
This commit is contained in:
109
scripts/deploy-from-github.sh
Executable file
109
scripts/deploy-from-github.sh
Executable file
@@ -0,0 +1,109 @@
|
||||
#!/bin/bash
|
||||
# Скрипт для деплоя из GitHub Actions
|
||||
# Используется на сервере для безопасного обновления
|
||||
|
||||
set -e
|
||||
|
||||
PROJECT_DIR="/home/prod"
|
||||
BACKUP_DIR="/home/prod/backups"
|
||||
LOG_FILE="/home/prod/logs/deploy.log"
|
||||
|
||||
# Создаем директории если их нет
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
mkdir -p "$(dirname "$LOG_FILE")"
|
||||
|
||||
# Функция логирования
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
log "🚀 Starting deployment..."
|
||||
|
||||
# Переходим в директорию проекта
|
||||
cd "$PROJECT_DIR" || exit 1
|
||||
|
||||
# Сохраняем текущий коммит
|
||||
CURRENT_COMMIT=$(git rev-parse HEAD)
|
||||
log "Current commit: $CURRENT_COMMIT"
|
||||
|
||||
# Создаем backup конфигурации перед обновлением
|
||||
log "💾 Creating backup..."
|
||||
BACKUP_FILE="$BACKUP_DIR/backup-$(date +%Y%m%d-%H%M%S).tar.gz"
|
||||
tar -czf "$BACKUP_FILE" \
|
||||
infra/prometheus/prometheus.yml \
|
||||
infra/grafana/provisioning/ \
|
||||
docker-compose.yml \
|
||||
2>/dev/null || true
|
||||
log "Backup created: $BACKUP_FILE"
|
||||
|
||||
# Обновляем код
|
||||
log "📥 Pulling latest changes..."
|
||||
git fetch origin main
|
||||
git reset --hard origin/main
|
||||
|
||||
# Проверяем изменения
|
||||
NEW_COMMIT=$(git rev-parse HEAD)
|
||||
if [ "$CURRENT_COMMIT" = "$NEW_COMMIT" ]; then
|
||||
log "ℹ️ No new changes to deploy"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log "✅ Code updated: $CURRENT_COMMIT → $NEW_COMMIT"
|
||||
|
||||
# Проверяем синтаксис docker-compose
|
||||
log "🔍 Validating docker-compose.yml..."
|
||||
if ! docker-compose config > /dev/null 2>&1; then
|
||||
log "❌ docker-compose.yml validation failed!"
|
||||
log "🔄 Rolling back..."
|
||||
git reset --hard "$CURRENT_COMMIT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Перезапускаем сервисы
|
||||
log "🔄 Restarting services..."
|
||||
if command -v make &> /dev/null; then
|
||||
make restart
|
||||
else
|
||||
docker-compose down
|
||||
docker-compose up -d --build
|
||||
fi
|
||||
|
||||
# Ждем запуска сервисов
|
||||
log "⏳ Waiting for services to start..."
|
||||
sleep 20
|
||||
|
||||
# Health checks
|
||||
log "🏥 Running health checks..."
|
||||
|
||||
HEALTH_CHECK_FAILED=0
|
||||
|
||||
# Prometheus
|
||||
if curl -f http://localhost:9090/-/healthy > /dev/null 2>&1; then
|
||||
log "✅ Prometheus is healthy"
|
||||
else
|
||||
log "❌ Prometheus health check failed"
|
||||
HEALTH_CHECK_FAILED=1
|
||||
fi
|
||||
|
||||
# Grafana
|
||||
if curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
||||
log "✅ Grafana is healthy"
|
||||
else
|
||||
log "❌ Grafana health check failed"
|
||||
HEALTH_CHECK_FAILED=1
|
||||
fi
|
||||
|
||||
# Если health check не прошел, откатываемся
|
||||
if [ $HEALTH_CHECK_FAILED -eq 1 ]; then
|
||||
log "❌ Health checks failed! Rolling back..."
|
||||
git reset --hard "$CURRENT_COMMIT"
|
||||
make restart || docker-compose restart
|
||||
log "🔄 Rollback completed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "✅ Deployment completed successfully!"
|
||||
log "📊 Container status:"
|
||||
docker-compose ps || docker ps --filter "name=bots_"
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user