CI/CD Deployment System

Webhook Setup Guide

Configure Gitea and GitHub webhooks for automated deployments

Gitea Webhook Setup

Prerequisites

  • • Gitea server access
  • • SSH keys configured with Gitea
  • • Repository already created in Gitea

Step 1: Get Your Webhook URL

Find your server's IP address:

hostname -I | awk '{print $1}'

Your webhook URL will be: http://YOUR_SERVER_IP:9001/deploy

Step 2: Add Webhook in Gitea

  1. Navigate to your repository - Go to your Gitea instance and select your repository
  2. Go to Webhooks settings - Click Settings in the repository menu, then click Webhooks in the left sidebar
  3. Click "Add Webhook"

Step 3: Configure Webhook Settings

Target URL: http://YOUR_SERVER_IP:9001/deploy
HTTP Method: POST
Content Type: application/json
Secret: Leave empty for now
Events: ✅ Push Events
Branch Filter: main
Active: ✅ Yes

Step 4: Save and Test

  1. Click Add Webhook
  2. Click the webhook name to view details
  3. Click Test Delivery to test

GitHub Webhook Setup

Prerequisites

  • • GitHub account
  • • SSH keys configured with GitHub
  • • Repository already created on GitHub

Step 1: Get Your Webhook URL

Same as Gitea - find your server IP:

hostname -I | awk '{print $1}'

Your webhook URL: http://YOUR_SERVER_IP:9001/deploy

Step 2: Add Webhook in GitHub

  1. Navigate to your repository - Go to github.com and select your repository
  2. Go to Webhooks settings - Click Settings tab, then click Webhooks in the left sidebar
  3. Click "Add webhook"

Step 3: Configure Webhook Settings

Payload URL: http://YOUR_SERVER_IP:9001/deploy
Content type: application/json
Secret: Leave empty for now
Which events: Just the push event
Active: ✅ Yes

Step 4: Save and Test

  1. Click Add webhook
  2. GitHub will show you recent deliveries
  3. Click on a delivery to see details

SSH Setup (Required for Both)

For Gitea:

  1. Generate SSH key (if you don't have one):
    ssh-keygen -t ed25519 -C "your-email@example.com"
  2. Add SSH key to Gitea:
    cat ~/.ssh/id_ed25519.pub
  3. Copy the output, go to Gitea → Settings → SSH/GPG Keys
  4. Click "Add Key" and paste your public key
  5. Test connection:
    ssh -T git@your-gitea-server.com

For GitHub:

  1. Generate SSH key (if you don't have one):
    ssh-keygen -t ed25519 -C "your-email@example.com"
  2. Add SSH key to GitHub:
    cat ~/.ssh/id_ed25519.pub
  3. Copy the output, go to GitHub → Settings → SSH and GPG keys
  4. Click "New SSH key" and paste your public key
  5. Test connection:
    ssh -T git@github.com

Branch Configuration

Determine Your Main Branch

Check your repository's default branch:

git branch -r

Look for origin/main or origin/master

Set Webhook Branch Filter Accordingly

  • • If you see origin/main → Use main
  • • If you see origin/master → Use master

Update Deploy Script if Needed

Your deploy.sh should match your main branch:

echo "=== PULLING LATEST CHANGES ==="
git pull origin main # or git pull origin master

Testing Your Webhook

Method 1: Push Test

# Make a small change
echo "test" >> test.txt
git add test.txt
git commit -m "Test webhook"
git push origin main

Method 2: Manual Test

curl -X POST http://localhost:9001/deploy \
-H "Content-Type: application/json" \
-d '{
"ref": "refs/heads/main",
"repository": {
"name": "your-repo-name"
}
}'

Method 3: Built-in Test

  • Gitea: Use "Test Delivery" button in webhook settings
  • GitHub: View recent deliveries in webhook settings

Verify Success

Check your webhook server logs:

journalctl -u webhook-multi-repo -f

You should see deployment logs indicating success!

Common Webhook Issues

Issue: "404 Not Found"

Cause: Wrong webhook URL

Fix: Verify your server IP and port 9001 is accessible

Issue: "400 Bad Request"

Cause: Wrong content type

Fix: Ensure "application/json" is selected

Issue: "No deployment triggered"

Cause: Wrong branch filter

Fix: Match webhook branch filter to your actual main branch

Issue: "Git pull failed"

Cause: SSH keys not configured

Fix: Set up SSH keys with your Git provider

Webhook Setup Complete!

Your webhook is now configured and ready to trigger deployments!

  • ✅ Webhook server running on port 9001
  • ✅ Correct webhook URL configured
  • ✅ SSH keys set up with Git provider
  • ✅ Branch filter matches your main branch
  • ✅ Test push triggers deployment
  • ✅ Deployment logs show success