GitHub Integration & Auto-Deploy
Webhook-based automatic deployment from GitHub pushes.
Overview
When you push to a GitHub repository, a webhook automatically redeploys the service on collabrains.eu.
Webhook Receiver
| Component | Details |
|---|---|
| Location | /data/webhook-receiver/ |
| Port | 5000 (internal) |
| URL | https://collabrains.eu:5000/webhook/github |
| Status | Running in Docker |
GitHub Setup
1. Configure Webhook in GitHub
Repository → Settings → Webhooks → Add webhook
Settings:
- Payload URL: https://collabrains.eu:5000/webhook/github
- Content type: application/json
- Secret: Store in /data/webhook-receiver/.env as GITHUB_SECRET
- Events: Push events (or select specific branches)
2. Environment Variable
The webhook secret must match in /data/webhook-receiver/.env:
cat /data/webhook-receiver/.env | grep GITHUB_SECRET
How It Works
GitHub Push
↓
Webhook POST to https://collabrains.eu:5000/webhook/github
↓
webhook-receiver validates signature
↓
Triggers deployment script
↓
Service redeploys (docker pull + restart)
Testing Webhook
View Webhook Logs
docker logs webhook-receiver-webhook-1 --tail 20 -f
Test Webhook Delivery
GitHub provides webhook delivery logs: 1. Repository → Settings → Webhooks 2. Click webhook 3. View "Recent Deliveries"
Manual Test
# Test webhook endpoint
curl -I https://collabrains.eu:5000/webhook/github
# Test with payload (requires valid signature)
# Use GitHub's test delivery or:
curl -X POST https://collabrains.eu:5000/webhook/github \
-H "Content-Type: application/json" \
-d '{"action":"opened"}'
Configuration
Webhook Receiver .env
Location: /data/webhook-receiver/.env
Key variables:
GITHUB_SECRET=<your-webhook-secret>
PORT=5000
REPO_PATH=/data/services/
Troubleshooting
Webhook Not Triggering
-
Check webhook receiver is running:
bash docker ps | grep webhook -
Check logs:
bash docker logs webhook-receiver-webhook-1 --tail 50 -
Verify GitHub webhook delivery:
- Go to webhook settings
- Check "Recent Deliveries"
- Look for red X (failed) or green checkmark (success)
Webhook Signature Validation Fails
Symptoms: "403 Forbidden" or "Invalid signature"
Cause: Secret mismatch between GitHub and webhook-receiver
Fix:
1. Get GitHub webhook secret
2. Update /data/webhook-receiver/.env
3. Restart webhook-receiver:
bash
docker restart webhook-receiver-webhook-1
Service Not Redeploying
- Check webhook is triggering (see logs)
- Verify deployment script has correct path
- Check service docker-compose file location
- View deployment logs:
bash docker logs webhook-receiver-webhook-1 -f
Multiple Repositories
To trigger deploys for multiple repos:
- Add same webhook to each GitHub repo
- Webhook receiver should distinguish by repo name
- Edit deployment script if needed:
bash cat /data/webhook-receiver/deploy.sh
Security
⚠️ Important security considerations:
- Keep webhook secret secure
- Don't commit to git
- Store in
/data/webhook-receiver/.envonly -
Use strong random string
-
HTTPS only
- Webhook URL must be HTTPS
-
Let's Encrypt certificate manages this
-
Validate signatures
- Webhook receiver validates GitHub signature
-
Prevents unauthorized deployments
-
Limited permissions
- Deployment script runs as docker user
- Restrict access to service files only
Webhook Flow Diagram
GitHub Repository
│
├─ Developer pushes code
│
└─ Webhook event triggered
↓
HTTPS POST to collabrains.eu:5000/webhook/github
↓
Webhook receiver validates:
├─ HTTPS connection ✓
├─ Signature verification ✓
└─ Payload format ✓
↓
Extract repo info from payload
├─ Repo name
├─ Branch
└─ Commit hash
↓
Trigger deployment script
├─ cd to service directory
├─ git pull latest
└─ docker compose up -d --build
↓
Service redeploys
↓
Webhook receiver logs result
Monitoring Deployments
Check Deployment History
# View webhook receiver logs
docker logs webhook-receiver-webhook-1 --tail 100
# Filter for deployment events
docker logs webhook-receiver-webhook-1 | grep -i "deploy\|success\|error"
GitHub Webhook Deliveries
Webhook delivery status is visible in GitHub: 1. Repository → Settings → Webhooks 2. Click the webhook URL 3. "Recent Deliveries" shows status and timestamp
Best Practices
- Use branch protection rules
- Require PR reviews before push
-
Prevents accidental deploys
-
Test locally first
- Don't rely on webhook for first test
-
Verify code works before push
-
Monitor deployments
- Check webhook logs regularly
-
Set up alerts for failures
-
Limit webhook scope
- Only trigger on specific branches
-
Use specific events (push, release)
-
Backup before deploy
- Automated daily backups already running
- Manual backup before major changes
Disabling Webhook
To pause auto-deploys:
# Stop webhook receiver temporarily
docker stop webhook-receiver-webhook-1
# Or remove webhook in GitHub:
# Repository → Settings → Webhooks → Delete
Related Documentation
- Common Commands — Service management
- Troubleshooting — Deployment issues
- Services Overview — Service details