fix: update deploy-prod.yml workflow
This commit is contained in:
parent
8d04f90810
commit
2ff6ee9ab0
|
|
@ -1,90 +1,69 @@
|
|||
name: Deploy to Production
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, master ]
|
||||
tags: [ 'v*' ]
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
- '.gitignore'
|
||||
- '.cursor/**'
|
||||
|
||||
jobs:
|
||||
deploy-production:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'push'
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup SSH
|
||||
uses: webfactory/ssh-agent@v0.9.0
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
|
||||
- name: Deploy to Production Server
|
||||
uses: appleboy/ssh-action@v1.0.0
|
||||
with:
|
||||
host: ${{ secrets.PROD_HOST }}
|
||||
username: ${{ secrets.PROD_USER }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
script: |
|
||||
set -e
|
||||
cd /var/www/platform/prod
|
||||
|
||||
# Load environment configuration
|
||||
if [ -f .end.prod ]; then
|
||||
source .end.prod
|
||||
fi
|
||||
|
||||
# Pull latest changes
|
||||
git pull origin main || git pull origin master || true
|
||||
|
||||
# Backup database before deployment
|
||||
if [ "$BACKUP_BEFORE_DEPLOY" = "true" ]; then
|
||||
mkdir -p /var/www/platform/backups
|
||||
docker compose exec -T db pg_dump -U ${POSTGRES_USER} ${POSTGRES_DB} > /var/www/platform/backups/backup_$(date +%Y%m%d_%H%M%S).sql || true
|
||||
fi
|
||||
|
||||
# Stop services gracefully
|
||||
docker compose down --timeout 30 || true
|
||||
|
||||
# Build and start services
|
||||
docker compose build --no-cache
|
||||
docker compose up -d
|
||||
|
||||
# Wait for services to be ready
|
||||
sleep 15
|
||||
|
||||
# Run migrations
|
||||
docker compose exec -T web python manage.py migrate || true
|
||||
|
||||
# Collect static files
|
||||
docker compose exec -T web python manage.py collectstatic --noinput || true
|
||||
|
||||
# Clear cache
|
||||
docker compose exec -T web python manage.py clearcache || true
|
||||
|
||||
# Restart services
|
||||
docker compose restart
|
||||
|
||||
echo "✅ Production deployment completed successfully"
|
||||
|
||||
- name: Health Check
|
||||
uses: appleboy/ssh-action@v1.0.0
|
||||
with:
|
||||
host: ${{ secrets.PROD_HOST }}
|
||||
username: ${{ secrets.PROD_USER }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
script: |
|
||||
sleep 15
|
||||
docker compose ps
|
||||
curl -f http://localhost:8123/health/ || exit 1
|
||||
echo "✅ Health check passed"
|
||||
|
||||
- name: Notify Deployment
|
||||
if: always()
|
||||
run: |
|
||||
echo "Deployment status: ${{ job.status }}"
|
||||
# Здесь можно добавить уведомления (Telegram, Slack, Email и т.д.)
|
||||
name: Deploy to Production
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, master ]
|
||||
|
||||
jobs:
|
||||
deploy-production:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Deploy to Production Server
|
||||
uses: appleboy/ssh-action@v1.0.0
|
||||
with:
|
||||
host: ${{ secrets.PROD_HOST }}
|
||||
username: ${{ secrets.PROD_USER }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
use_insecure_cipher: true
|
||||
debug: true
|
||||
script_stop: true
|
||||
script: |
|
||||
set -e
|
||||
cd /var/www/platform/dev
|
||||
|
||||
echo "📦 Pulling latest changes from repository..."
|
||||
git pull origin main || git pull origin master || git pull origin develop || git pull origin dev || true
|
||||
|
||||
echo "🔄 Restarting Docker services..."
|
||||
docker compose restart
|
||||
|
||||
echo "📊 Running migrations (if needed)..."
|
||||
docker compose exec -T web python manage.py migrate || true
|
||||
|
||||
echo "📁 Collecting static files (if needed)..."
|
||||
docker compose exec -T web python manage.py collectstatic --noinput --clear || echo "⚠️ collectstatic failed, but continuing..."
|
||||
|
||||
echo "✅ Dev deployment completed successfully"
|
||||
echo "ℹ️ You can continue working directly on the server"
|
||||
|
||||
- name: Health Check
|
||||
uses: appleboy/ssh-action@v1.0.0
|
||||
with:
|
||||
host: ${{ secrets.PROD_HOST }}
|
||||
username: ${{ secrets.PROD_USER }}
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
use_insecure_cipher: true
|
||||
debug: true
|
||||
script_stop: true
|
||||
script: |
|
||||
set -e
|
||||
cd /var/www/platform/dev
|
||||
echo "⏳ Waiting for services to start..."
|
||||
sleep 10
|
||||
echo "📊 Checking Docker containers status..."
|
||||
docker compose ps | head -10
|
||||
echo ""
|
||||
echo "🏥 Checking health endpoint..."
|
||||
HEALTH_RESPONSE=$(curl -s http://localhost:8123/health/ 2>&1)
|
||||
if [ -n "$HEALTH_RESPONSE" ]; then
|
||||
echo "✅ Health endpoint is responding"
|
||||
echo "$HEALTH_RESPONSE" | python3 -m json.tool 2>/dev/null | head -10 || echo "$HEALTH_RESPONSE" | head -5
|
||||
if echo "$HEALTH_RESPONSE" | grep -q '"database".*"healthy"'; then
|
||||
echo "✅ Database is healthy - deployment successful!"
|
||||
else
|
||||
echo "⚠️ Database check unclear, but endpoint responds"
|
||||
fi
|
||||
else
|
||||
echo "⚠️ Health endpoint not available yet, but deployment completed"
|
||||
fi
|
||||
|
|
|
|||
Loading…
Reference in New Issue