Files
prod/.github/workflows/deploy.yml
Andrey 3ee72ec48a chore: update CI and deployment workflows for improved notifications and permissions
- Upgraded the upload-artifact action from v3 to v4 in CI workflow for better performance.
- Added a notification step in the CI workflow to send test results via Telegram, including job status and repository details.
- Modified the deployment workflow to ensure correct file permissions before and after code updates.
- Renamed the deployment notification step for clarity and included a link to the action run details in the message.
2026-01-25 15:35:56 +03:00

117 lines
4.3 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Deploy to Production
on:
workflow_dispatch: # Только ручной запуск
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy Infrastructure
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to server
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ vars.SERVER_HOST || secrets.SERVER_HOST }}
username: ${{ vars.SERVER_USER || secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ vars.SSH_PORT || secrets.SSH_PORT || 22 }}
script: |
set -e
echo "🚀 Starting deployment..."
# Переходим в директорию проекта
cd /home/prod
# Сохраняем текущий коммит для отката
CURRENT_COMMIT=$(git rev-parse HEAD)
echo "Current commit: $CURRENT_COMMIT" > /tmp/last_deploy_commit.txt
# Обновляем код
echo "📥 Pulling latest changes..."
# Исправляем права на файлы перед обновлением
sudo chown -R deploy:deploy /home/prod || true
git fetch origin main
git reset --hard origin/main
# Устанавливаем правильные права после обновления
sudo chown -R deploy:deploy /home/prod || true
# Проверяем, что изменения есть
NEW_COMMIT=$(git rev-parse HEAD)
if [ "$CURRENT_COMMIT" = "$NEW_COMMIT" ]; then
echo " No new changes to deploy"
else
echo "✅ Code updated: $CURRENT_COMMIT → $NEW_COMMIT"
fi
# Перезапускаем сервисы
echo "🔄 Restarting services..."
if command -v make &> /dev/null; then
make restart || docker-compose restart
else
cd /home/prod
docker-compose down
docker-compose up -d --build
fi
echo "✅ Deployment completed"
- name: Health check
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ vars.SERVER_HOST || secrets.SERVER_HOST }}
username: ${{ vars.SERVER_USER || secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ vars.SSH_PORT || secrets.SSH_PORT || 22 }}
script: |
echo "🏥 Running health checks..."
sleep 15 # Даем время сервисам запуститься
# Проверяем Prometheus
if curl -f http://localhost:9090/-/healthy > /dev/null 2>&1; then
echo "✅ Prometheus is healthy"
else
echo "❌ Prometheus health check failed"
exit 1
fi
# Проверяем Grafana
if curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
echo "✅ Grafana is healthy"
else
echo "❌ Grafana health check failed"
exit 1
fi
# Проверяем статус контейнеров
echo "📊 Container status:"
cd /home/prod
docker-compose ps || docker ps --filter "name=bots_"
echo "✅ All health checks passed"
- name: Send deployment notification
if: always()
uses: appleboy/telegram-action@v1.0.0
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
message: |
🚀 Deployment ${{ job.status }}
Repository: prod
Branch: ${{ github.ref_name }}
Commit: ${{ github.sha }}
Author: ${{ github.actor }}
${{ job.status == 'success' && '✅ Deployment successful!' || '❌ Deployment failed!' }}
View details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
continue-on-error: true