189 lines
5.7 KiB
YAML
189 lines
5.7 KiB
YAML
name: Deploy Application
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
environment:
|
|
description: 'Deployment environment'
|
|
required: true
|
|
default: 'staging'
|
|
type: choice
|
|
options:
|
|
- development
|
|
- staging
|
|
- production
|
|
|
|
skip_tests:
|
|
description: 'Skip tests before deployment'
|
|
required: false
|
|
default: false
|
|
type: boolean
|
|
|
|
backup_first:
|
|
description: 'Backup database before deployment'
|
|
required: false
|
|
default: true
|
|
type: boolean
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: macos-arm64
|
|
name: Deploy to ${{ github.event.inputs.environment }}
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Deployment Configuration
|
|
run: |
|
|
echo "🚀 Deployment Configuration"
|
|
echo "=========================="
|
|
echo "Environment: ${{ github.event.inputs.environment }}"
|
|
echo "Skip Tests: ${{ github.event.inputs.skip_tests }}"
|
|
echo "Backup First: ${{ github.event.inputs.backup_first }}"
|
|
echo "Deployed by: ${{ github.actor }}"
|
|
echo "Commit: ${{ github.sha }}"
|
|
echo "=========================="
|
|
|
|
- name: Setup environment
|
|
run: |
|
|
python3 -m venv venv
|
|
source venv/bin/activate
|
|
pip install --upgrade pip
|
|
pip install -r requirements.txt
|
|
|
|
- name: Run pre-deployment tests
|
|
if: github.event.inputs.skip_tests != 'true'
|
|
run: |
|
|
source venv/bin/activate
|
|
echo "🧪 Running pre-deployment tests..."
|
|
pytest tests/unit/ -q
|
|
echo "✅ Tests passed"
|
|
|
|
- name: Backup database
|
|
if: github.event.inputs.backup_first == 'true'
|
|
run: |
|
|
echo "💾 Creating database backup..."
|
|
timestamp=$(date +%Y%m%d_%H%M%S)
|
|
mkdir -p backups
|
|
|
|
# Backup SQLite databases if they exist
|
|
if [ -f "data/clean_tracks.db" ]; then
|
|
cp data/clean_tracks.db backups/clean_tracks_${timestamp}.db
|
|
echo "✅ Database backed up to backups/clean_tracks_${timestamp}.db"
|
|
fi
|
|
|
|
# Backup word lists
|
|
if [ -d "data/word_lists" ]; then
|
|
tar -czf backups/word_lists_${timestamp}.tar.gz data/word_lists/
|
|
echo "✅ Word lists backed up"
|
|
fi
|
|
|
|
- name: Deploy to Development
|
|
if: github.event.inputs.environment == 'development'
|
|
run: |
|
|
echo "🔧 Deploying to Development..."
|
|
|
|
# Development deployment (local)
|
|
source venv/bin/activate
|
|
|
|
# Kill existing process if running
|
|
pkill -f "python.*app.py" || true
|
|
|
|
# Start in development mode
|
|
cd src
|
|
nohup python3 app.py --debug > ../dev_server.log 2>&1 &
|
|
|
|
sleep 3
|
|
curl -f http://localhost:5000 || echo "Server starting..."
|
|
|
|
echo "✅ Deployed to Development"
|
|
echo "Access at: http://localhost:5000"
|
|
|
|
- name: Deploy to Staging
|
|
if: github.event.inputs.environment == 'staging'
|
|
run: |
|
|
echo "🎭 Deploying to Staging..."
|
|
|
|
# Staging deployment
|
|
source venv/bin/activate
|
|
|
|
# Create staging config
|
|
cat > config/staging.env << EOF
|
|
ENVIRONMENT=staging
|
|
DEBUG=False
|
|
PORT=5001
|
|
DATABASE_URL=sqlite:///data/staging.db
|
|
EOF
|
|
|
|
# Start staging server
|
|
cd src
|
|
export ENV_FILE=../config/staging.env
|
|
nohup python3 app.py > ../staging_server.log 2>&1 &
|
|
|
|
echo "✅ Deployed to Staging"
|
|
echo "Access at: http://localhost:5001"
|
|
|
|
- name: Deploy to Production
|
|
if: github.event.inputs.environment == 'production'
|
|
run: |
|
|
echo "🚀 Deploying to Production..."
|
|
|
|
# Production deployment checks
|
|
source venv/bin/activate
|
|
|
|
# Verify all tests pass
|
|
pytest tests/ -q --tb=short
|
|
|
|
# Check for security issues
|
|
pip install bandit
|
|
bandit -r src/ -ll || true
|
|
|
|
# Production config
|
|
cat > config/production.env << EOF
|
|
ENVIRONMENT=production
|
|
DEBUG=False
|
|
PORT=5000
|
|
DATABASE_URL=sqlite:///data/production.db
|
|
LOG_LEVEL=INFO
|
|
EOF
|
|
|
|
echo "✅ Ready for Production deployment"
|
|
echo "Manual step required: Start production server with supervisor/systemd"
|
|
|
|
- name: Health Check
|
|
if: github.event.inputs.environment != 'production'
|
|
run: |
|
|
echo "🏥 Running health checks..."
|
|
sleep 5
|
|
|
|
# Check if service is responding
|
|
if [ "${{ github.event.inputs.environment }}" = "development" ]; then
|
|
port=5000
|
|
elif [ "${{ github.event.inputs.environment }}" = "staging" ]; then
|
|
port=5001
|
|
fi
|
|
|
|
curl -f http://localhost:${port} && echo "✅ Service is healthy" || echo "⚠️ Service may still be starting"
|
|
|
|
- name: Deployment Summary
|
|
if: always()
|
|
run: |
|
|
echo ""
|
|
echo "📋 Deployment Summary"
|
|
echo "===================="
|
|
echo "Environment: ${{ github.event.inputs.environment }}"
|
|
echo "Status: ${{ job.status }}"
|
|
echo "Commit: ${{ github.sha }}"
|
|
echo ""
|
|
|
|
if [ "${{ github.event.inputs.environment }}" = "production" ]; then
|
|
echo "⚠️ Production deployment prepared but not auto-started"
|
|
echo "Next steps:"
|
|
echo "1. Review production config"
|
|
echo "2. Start service with process manager"
|
|
echo "3. Configure reverse proxy (nginx/caddy)"
|
|
echo "4. Set up SSL certificates"
|
|
else
|
|
echo "✅ Deployment completed successfully"
|
|
fi |