Add webhook auto-deployment system

This commit is contained in:
oguz ozturk 2026-01-10 15:42:21 +03:00
parent 733ecd66e7
commit 6fa9e5c43b
2 changed files with 251 additions and 7 deletions

View File

@ -175,18 +175,34 @@ Hosting Platform Team
## 🚀 Deployment
### Otomatik Deployment
### 🔗 Auto-Deploy Webhook (Önerilen)
Gitea'ya webhook ekleyerek otomatik deployment yapabilirsiniz:
**Webhook URL**: `https://api.argeict.net/webhook/deploy`
Detaylı kurulum için: [WEBHOOK_SETUP.md](WEBHOOK_SETUP.md)
```bash
# Webhook test
curl -X POST https://api.argeict.net/webhook/deploy \
-H "Content-Type: application/json" \
-d '{"repository":{"name":"hosting-platform"}}'
```
### 📦 Manuel Deployment (SSH)
```bash
./deploy.sh
```
Bu script:
1. ✅ Gitea'dan son kodu çeker
2. ✅ Backend dependencies yükler
3. ✅ Database migration yapar
4. ✅ Frontend build eder
5. ✅ Servisleri restart eder
6. ✅ Health check yapar
1. ✅ SSH ile sunucuya bağlanır
2. ✅ Gitea'dan son kodu çeker
3. ✅ Backend dependencies yükler
4. ✅ Database migration yapar
5. ✅ Frontend build eder
6. ✅ Servisleri restart eder
7. ✅ Health check yapar
### Manuel Deployment

228
WEBHOOK_SETUP.md Normal file
View File

@ -0,0 +1,228 @@
# 🔗 Webhook Setup Guide
## ✅ Webhook Status
- **Endpoint**: `https://api.argeict.net/webhook/deploy`
- **Method**: POST
- **Status**: ✅ Working
- **Last Test**: 2026-01-10 12:39:04 UTC
---
## 📝 Gitea Webhook Configuration
### Step 1: Access Gitea Repository Settings
1. Go to: https://gitea.argeict.net/hostadmin/hosting-platform
2. Click on **Settings** (top right)
3. Click on **Webhooks** in the left sidebar
### Step 2: Add New Webhook
1. Click **Add Webhook** button
2. Select **Gitea** from the dropdown
### Step 3: Configure Webhook
Fill in the following details:
```
Target URL: https://api.argeict.net/webhook/deploy
HTTP Method: POST
POST Content Type: application/json
Secret: (leave empty for now)
```
**Trigger On:**
- ✅ Push events (checked)
- Branch filter: `main`
**Active:**
- ✅ Active (checked)
### Step 4: Save and Test
1. Click **Add Webhook** button
2. The webhook will appear in the list
3. Click on the webhook to view details
4. Click **Test Delivery** button
5. Check the response - should see:
```json
{
"status": "success",
"message": "Deployment triggered successfully",
"repository": "hosting-platform",
"pusher": "hostadmin",
"timestamp": "2026-01-10T12:39:04.822854",
"note": "Check /var/log/auto-deploy.log for deployment progress"
}
```
---
## 🧪 Manual Testing
Test the webhook manually with curl:
```bash
curl -X POST https://api.argeict.net/webhook/deploy \
-H "Content-Type: application/json" \
-d '{
"repository": {
"name": "hosting-platform"
},
"pusher": {
"username": "test-user"
}
}'
```
Expected response (HTTP 202):
```json
{
"status": "success",
"message": "Deployment triggered successfully",
"repository": "hosting-platform",
"pusher": "test-user",
"timestamp": "2026-01-10T12:39:04.822854",
"note": "Check /var/log/auto-deploy.log for deployment progress"
}
```
---
## 📊 How It Works
```
┌─────────────┐
│ Developer │
│ git push │
└──────┬──────┘
┌─────────────────┐
│ Gitea Server │
│ (detects push) │
└──────┬──────────┘
│ POST /webhook/deploy
┌──────────────────────┐
│ Backend API │
│ (receives webhook) │
└──────┬───────────────┘
│ Triggers async
┌────────────────────────────┐
│ deploy-local.sh │
│ 1. git pull │
│ 2. install dependencies │
│ 3. database migration │
│ 4. build frontend │
│ 5. restart services │
└────────────────────────────┘
┌─────────────────┐
│ Deployment │
│ Complete! ✅ │
└─────────────────┘
```
---
## 🔍 Monitoring Deployments
### View Deployment Logs
```bash
# Real-time deployment logs
ssh root@176.96.129.77 'tail -f /var/log/auto-deploy.log'
# Last 50 lines
ssh root@176.96.129.77 'tail -50 /var/log/auto-deploy.log'
```
### View Backend Logs
```bash
ssh root@176.96.129.77 'tail -f /var/log/hosting-backend.log'
```
### Check Service Status
```bash
ssh root@176.96.129.77 'supervisorctl status'
```
---
## 🛠️ Troubleshooting
### Webhook Returns Error
1. Check backend logs:
```bash
ssh root@176.96.129.77 'tail -100 /var/log/hosting-backend.log'
```
2. Verify deployment script exists:
```bash
ssh root@176.96.129.77 'ls -la /opt/hosting-platform/deploy-local.sh'
```
3. Test deployment script manually:
```bash
ssh root@176.96.129.77 '/opt/hosting-platform/deploy-local.sh'
```
### Deployment Fails
1. Check deployment logs:
```bash
ssh root@176.96.129.77 'cat /var/log/auto-deploy.log'
```
2. Check for git issues:
```bash
ssh root@176.96.129.77 'cd /opt/hosting-platform && git status'
```
3. Restart services manually:
```bash
ssh root@176.96.129.77 'supervisorctl restart hosting-backend hosting-frontend'
```
---
## 🔐 Security (Optional)
To add webhook secret validation:
1. Generate a secret:
```bash
openssl rand -hex 32
```
2. Add to Gitea webhook configuration (Secret field)
3. Update backend code to validate the secret
---
## ✅ Verification Checklist
- [ ] Webhook added in Gitea
- [ ] Test Delivery successful (green checkmark)
- [ ] Push to main branch triggers deployment
- [ ] Deployment logs show successful completion
- [ ] Services restart automatically
- [ ] Frontend and backend updated
---
**Last Updated**: 2026-01-10
**Maintained By**: Hosting Platform Team