hosting-platform/WEBHOOK_SETUP.md

4.8 KiB

🔗 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:
{
  "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:

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):

{
  "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

# 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

ssh root@176.96.129.77 'tail -f /var/log/hosting-backend.log'

Check Service Status

ssh root@176.96.129.77 'supervisorctl status'

🛠️ Troubleshooting

Webhook Returns Error

  1. Check backend logs:

    ssh root@176.96.129.77 'tail -100 /var/log/hosting-backend.log'
    
  2. Verify deployment script exists:

    ssh root@176.96.129.77 'ls -la /opt/hosting-platform/deploy-local.sh'
    
  3. Test deployment script manually:

    ssh root@176.96.129.77 '/opt/hosting-platform/deploy-local.sh'
    

Deployment Fails

  1. Check deployment logs:

    ssh root@176.96.129.77 'cat /var/log/auto-deploy.log'
    
  2. Check for git issues:

    ssh root@176.96.129.77 'cd /opt/hosting-platform && git status'
    
  3. Restart services manually:

    ssh root@176.96.129.77 'supervisorctl restart hosting-backend hosting-frontend'
    

🔐 Security (Optional)

To add webhook secret validation:

  1. Generate a secret:

    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