diff --git a/README.md b/README.md index 467cf45..4a6abc5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/WEBHOOK_SETUP.md b/WEBHOOK_SETUP.md new file mode 100644 index 0000000..29a2d0a --- /dev/null +++ b/WEBHOOK_SETUP.md @@ -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 +