|
| 1 | +# 🚀 CI/CD Deployment Guide |
| 2 | + |
| 3 | +Complete CI/CD setup for ChittyPro Streamlink with GitHub Actions for automatic deployment to derail.me. |
| 4 | + |
| 5 | +## 🔧 Required GitHub Secrets |
| 6 | + |
| 7 | +Configure these secrets in your GitHub repository (`Settings > Secrets and variables > Actions`): |
| 8 | + |
| 9 | +### Production Server Secrets |
| 10 | +``` |
| 11 | +PRODUCTION_HOST=derail.me # Your server IP or domain |
| 12 | +PRODUCTION_USER=ubuntu # SSH username (usually ubuntu, root, or deploy) |
| 13 | +PRODUCTION_SSH_KEY=-----BEGIN... # Your private SSH key |
| 14 | +PRODUCTION_PORT=22 # SSH port (default: 22) |
| 15 | +``` |
| 16 | + |
| 17 | +### Optional Service Integrations |
| 18 | +``` |
| 19 | +SLACK_WEBHOOK_URL=https://hooks.slack.com/... # Slack notifications |
| 20 | +HEALTH_CHECK_WEBHOOK=https://your-monitor.com/... # Health check alerts |
| 21 | +RAILWAY_TOKEN=your_railway_token # For staging deployment |
| 22 | +RENDER_API_KEY=your_render_key # Alternative staging |
| 23 | +RENDER_SERVICE_ID=srv-xxxxx # Render service ID |
| 24 | +``` |
| 25 | + |
| 26 | +## 📋 Server Setup |
| 27 | + |
| 28 | +### 1. Prepare Your Production Server |
| 29 | + |
| 30 | +**Create deployment user**: |
| 31 | +```bash |
| 32 | +# On your server (derail.me) |
| 33 | +sudo adduser deploy |
| 34 | +sudo usermod -aG sudo deploy |
| 35 | +su - deploy |
| 36 | + |
| 37 | +# Create SSH directory |
| 38 | +mkdir -p ~/.ssh |
| 39 | +chmod 700 ~/.ssh |
| 40 | +``` |
| 41 | + |
| 42 | +**Set up SSH key authentication**: |
| 43 | +```bash |
| 44 | +# On your local machine |
| 45 | +ssh-keygen -t ed25519 -C "deployment@derail.me" |
| 46 | +# Copy the public key to your server |
| 47 | + |
| 48 | +# On your server |
| 49 | +echo "your-public-key-here" >> ~/.ssh/authorized_keys |
| 50 | +chmod 600 ~/.ssh/authorized_keys |
| 51 | +``` |
| 52 | + |
| 53 | +**Prepare application directory**: |
| 54 | +```bash |
| 55 | +# On your server |
| 56 | +sudo mkdir -p /var/www/chittypro-streamlink |
| 57 | +sudo chown deploy:deploy /var/www/chittypro-streamlink |
| 58 | +``` |
| 59 | + |
| 60 | +### 2. Initial Server Setup |
| 61 | + |
| 62 | +**Run the deployment script once manually**: |
| 63 | +```bash |
| 64 | +# SSH to your server |
| 65 | +ssh deploy@derail.me |
| 66 | + |
| 67 | +# Clone and setup |
| 68 | +git clone https://github.com/your-username/chittypro-streamlink.git /var/www/chittypro-streamlink |
| 69 | +cd /var/www/chittypro-streamlink |
| 70 | + |
| 71 | +# Run initial setup |
| 72 | +chmod +x scripts/deploy-derail.sh |
| 73 | +./scripts/deploy-derail.sh full |
| 74 | +``` |
| 75 | + |
| 76 | +## 🔄 CI/CD Workflows |
| 77 | + |
| 78 | +### Production Deployment (`deploy-production.yml`) |
| 79 | +**Triggers**: Push to `main` or `master` branch |
| 80 | +**Target**: https://derail.me |
| 81 | + |
| 82 | +**Process**: |
| 83 | +1. ✅ Run tests and TypeScript checks |
| 84 | +2. ✅ Build application |
| 85 | +3. ✅ SSH to production server |
| 86 | +4. ✅ Pull latest code |
| 87 | +5. ✅ Install dependencies and build |
| 88 | +6. ✅ Update database schema |
| 89 | +7. ✅ Restart PM2 application |
| 90 | +8. ✅ Reload Nginx |
| 91 | +9. ✅ Run health checks |
| 92 | +10. ✅ Send Slack notification |
| 93 | + |
| 94 | +### Testing Pipeline (`test-and-build.yml`) |
| 95 | +**Triggers**: Push to any branch, Pull requests |
| 96 | +**Actions**: |
| 97 | +- Multi-version Node.js testing (18, 20) |
| 98 | +- Security audit |
| 99 | +- Docker image build |
| 100 | +- Preview deployment for PRs |
| 101 | + |
| 102 | +### Staging Deployment (`deploy-staging.yml`) |
| 103 | +**Triggers**: Push to `develop` branch |
| 104 | +**Target**: https://staging.derail.me (Railway/Render) |
| 105 | + |
| 106 | +### Health Monitoring (`health-check.yml`) |
| 107 | +**Schedule**: Every 15 minutes |
| 108 | +**Checks**: |
| 109 | +- Main site availability |
| 110 | +- API endpoints |
| 111 | +- WebSocket connectivity |
| 112 | +- SSL certificate expiry |
| 113 | +- Performance metrics |
| 114 | +- Database connectivity |
| 115 | + |
| 116 | +## 🏃♂️ Quick Start |
| 117 | + |
| 118 | +### 1. Push to GitHub |
| 119 | +```bash |
| 120 | +# Add all CI/CD files to git |
| 121 | +git add .github/ |
| 122 | +git commit -m "Add CI/CD workflows for derail.me deployment" |
| 123 | +git push origin main |
| 124 | +``` |
| 125 | + |
| 126 | +### 2. Configure Secrets |
| 127 | +1. Go to your GitHub repo → `Settings` → `Secrets and variables` → `Actions` |
| 128 | +2. Add all required secrets (see list above) |
| 129 | +3. Test connection: `ssh deploy@derail.me` should work |
| 130 | + |
| 131 | +### 3. First Deployment |
| 132 | +- Push to `main` branch |
| 133 | +- Watch `Actions` tab in GitHub |
| 134 | +- Deployment will automatically start |
| 135 | +- Check https://derail.me when complete |
| 136 | + |
| 137 | +## 📊 Monitoring & Alerts |
| 138 | + |
| 139 | +### Health Check Endpoints |
| 140 | +- `https://derail.me/api/health` - Full health status |
| 141 | +- `https://derail.me/api/ready` - Readiness check |
| 142 | +- `https://derail.me/api/live` - Liveness check |
| 143 | + |
| 144 | +### GitHub Actions Monitoring |
| 145 | +- All workflows visible in `Actions` tab |
| 146 | +- Email notifications on failure |
| 147 | +- Slack notifications (if configured) |
| 148 | +- Health checks every 15 minutes |
| 149 | + |
| 150 | +### Log Monitoring |
| 151 | +```bash |
| 152 | +# On production server |
| 153 | +pm2 logs chittypro-streamlink # Application logs |
| 154 | +sudo journalctl -u nginx # Nginx logs |
| 155 | +tail -f /var/log/nginx/access.log # Access logs |
| 156 | +``` |
| 157 | + |
| 158 | +## 🔧 Troubleshooting |
| 159 | + |
| 160 | +### Common Issues |
| 161 | + |
| 162 | +**Deployment fails with SSH connection error**: |
| 163 | +```bash |
| 164 | +# Test SSH connection manually |
| 165 | +ssh -i ~/.ssh/deploy_key deploy@derail.me |
| 166 | + |
| 167 | +# Check SSH key is added to GitHub secrets correctly |
| 168 | +# Ensure server allows SSH key authentication |
| 169 | +``` |
| 170 | + |
| 171 | +**Health check fails**: |
| 172 | +```bash |
| 173 | +# Check application status |
| 174 | +ssh deploy@derail.me |
| 175 | +pm2 status |
| 176 | +sudo systemctl status nginx |
| 177 | + |
| 178 | +# Check health endpoint manually |
| 179 | +curl https://derail.me/api/health |
| 180 | +``` |
| 181 | + |
| 182 | +**Database connection issues**: |
| 183 | +```bash |
| 184 | +# Check PostgreSQL status |
| 185 | +sudo systemctl status postgresql |
| 186 | + |
| 187 | +# Test database connection |
| 188 | +sudo -u postgres psql -l |
| 189 | +``` |
| 190 | + |
| 191 | +### Manual Recovery |
| 192 | + |
| 193 | +**Rollback deployment**: |
| 194 | +```bash |
| 195 | +# SSH to server |
| 196 | +cd /var/www/chittypro-streamlink |
| 197 | + |
| 198 | +# Restore from backup |
| 199 | +sudo cp -r backup-YYYYMMDD-HHMMSS/* . |
| 200 | + |
| 201 | +# Restart services |
| 202 | +pm2 restart chittypro-streamlink |
| 203 | +sudo systemctl reload nginx |
| 204 | +``` |
| 205 | + |
| 206 | +**Emergency deployment**: |
| 207 | +```bash |
| 208 | +# Trigger manual deployment from GitHub |
| 209 | +# Go to Actions tab → Deploy to derail.me → Run workflow |
| 210 | +``` |
| 211 | + |
| 212 | +## 📈 Performance Optimization |
| 213 | + |
| 214 | +### Build Optimization |
| 215 | +- Dependencies cached between builds |
| 216 | +- Multi-stage Docker builds |
| 217 | +- Parallel test execution |
| 218 | + |
| 219 | +### Deployment Speed |
| 220 | +- Incremental deployments (only changed files) |
| 221 | +- Warm PM2 restarts |
| 222 | +- Nginx reload (no downtime) |
| 223 | + |
| 224 | +### Monitoring |
| 225 | +- Performance metrics in health checks |
| 226 | +- Response time monitoring |
| 227 | +- SSL certificate expiry alerts |
| 228 | + |
| 229 | +## 🎯 Next Steps |
| 230 | + |
| 231 | +1. **Set up monitoring**: Configure Slack/email alerts |
| 232 | +2. **Add tests**: Implement unit and integration tests |
| 233 | +3. **Security scanning**: Add dependency vulnerability checks |
| 234 | +4. **Performance testing**: Add load testing to CI/CD |
| 235 | +5. **Blue-green deployment**: Implement zero-downtime deployments |
| 236 | + |
| 237 | +Your ChittyPro Streamlink now has enterprise-grade CI/CD! 🚀 |
0 commit comments