happybell80 66009f2326
Some checks failed
Deploy Nginx Config to Ubuntu Server / deploy (push) Has been cancelled
Add Gitea Actions workflow for nginx deployment
- Create .gitea/workflows/deploy.yml for automated nginx config deployment
- Implement local server deployment (no SSH required)
- Add automatic backup, validation, and rollback features
- Update README.md with Gitea Actions setup instructions
- Include sudo permissions configuration guide

Features:
- Automatic nginx config backup before deployment
- Configuration syntax validation
- Seamless nginx service reload
- Automatic rollback on deployment failure
- Old backup cleanup (keeps last 5)
2025-07-14 17:13:05 +09:00

107 lines
3.5 KiB
YAML

# Ubuntu 서버 nginx 설정 자동 배포 워크플로우 (Gitea Actions)
#
# 성공 조건:
# - Gitea Actions 활성화
# - admin 사용자 sudo NOPASSWD 설정 완료
# - nginx 서비스 실행 중
#
# 실패 조건:
# - sudo 권한 없음
# - nginx 설정 문법 오류
# - 시스템 서비스 오류
#
# 주요 작업:
# 1. 소스 코드 체크아웃
# 2. nginx 설정 백업
# 3. 새 설정 적용 (/etc/nginx/sites-available/default)
# 4. nginx 설정 검증 (nginx -t)
# 5. nginx 서비스 reload
# 6. 배포 결과 확인
name: Deploy Nginx Config to Ubuntu Server
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Backup current nginx config
run: |
echo "📋 Creating backup of current nginx configuration..."
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.backup.$(date +%Y%m%d_%H%M%S)
echo "✅ Backup created successfully"
- name: Validate new nginx configuration
run: |
echo "🔍 Validating new nginx configuration syntax..."
# Create temporary copy to validate
sudo cp server-nginx-default /tmp/nginx-test-config
sudo nginx -t -c /tmp/nginx-test-config || {
echo "❌ New nginx configuration has syntax errors!"
exit 1
}
echo "✅ New configuration syntax is valid"
- name: Apply new nginx configuration
run: |
echo "📋 Applying new nginx configuration..."
sudo cp server-nginx-default /etc/nginx/sites-available/default
echo "✅ Configuration file updated"
- name: Test nginx configuration
run: |
echo "🔍 Testing nginx configuration with current setup..."
sudo nginx -t
echo "✅ Configuration test passed"
- name: Reload nginx service
run: |
echo "🔄 Reloading nginx service..."
sudo systemctl reload nginx
echo "✅ Nginx service reloaded successfully"
- name: Verify deployment
run: |
echo "🚀 Verifying deployment status..."
# Check nginx service status
sudo systemctl is-active nginx || {
echo "❌ Nginx service is not running!"
# Rollback on failure
echo "🔄 Rolling back to previous configuration..."
BACKUP_FILE=$(ls -t /etc/nginx/sites-available/default.backup.* 2>/dev/null | head -1)
if [ -n "$BACKUP_FILE" ]; then
sudo cp "$BACKUP_FILE" /etc/nginx/sites-available/default
sudo systemctl reload nginx
echo "✅ Rollback completed"
fi
exit 1
}
# Test HTTP response
curl -f -s -I http://localhost:80 > /dev/null || {
echo "⚠️ Warning: HTTP response test failed, but nginx is running"
}
echo "✅ Deployment completed successfully!"
echo "📊 Deployment Summary:"
echo " - Configuration: Applied"
echo " - Service: Running"
echo " - Status: Success"
- name: Cleanup old backups
run: |
echo "🧹 Cleaning up old backup files (keeping last 5)..."
cd /etc/nginx/sites-available/
sudo ls -t default.backup.* 2>/dev/null | tail -n +6 | sudo xargs rm -f
echo "✅ Cleanup completed"