|
| 1 | +# Receiving GitLab Webhooks Locally |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +- Docker Compose |
| 6 | +- A [GitLab](https://gitlab.com) project with maintainer access (or a self-hosted instance) |
| 7 | +- An [ngrok](https://ngrok.com) account (free tier works) |
| 8 | + |
| 9 | +## 1. Get your ngrok tunnel URL |
| 10 | + |
| 11 | +Start only ngrok and NATS to obtain a public URL before configuring GitLab: |
| 12 | + |
| 13 | +```bash |
| 14 | +docker compose --profile dev up ngrok nats |
| 15 | +``` |
| 16 | + |
| 17 | +Find the tunnel URL in the ngrok container logs: |
| 18 | + |
| 19 | +```bash |
| 20 | +docker compose logs ngrok |
| 21 | +``` |
| 22 | + |
| 23 | +Look for the `gitlab` tunnel URL (e.g. `https://abc123.ngrok-free.app`). |
| 24 | + |
| 25 | +## 2. Configure your GitLab webhook |
| 26 | + |
| 27 | +1. Go to **Settings → Webhooks** in your GitLab project |
| 28 | +2. Click **Add new webhook** |
| 29 | +3. Set: |
| 30 | + - **URL**: `https://<ngrok-url>/webhook` |
| 31 | + - **Secret token**: a secret of your choice (you will use this as `GITLAB_WEBHOOK_SECRET`) |
| 32 | +4. Select the trigger events you want to receive (e.g. Push events, Merge request events) |
| 33 | +5. Click **Add webhook** |
| 34 | + |
| 35 | +## 3. Start the webhook receiver |
| 36 | + |
| 37 | +Set `GITLAB_WEBHOOK_SECRET` in your `.env` to the secret token from step 2, |
| 38 | +then bring up the full stack: |
| 39 | + |
| 40 | +```bash |
| 41 | +docker compose --profile dev up |
| 42 | +``` |
| 43 | + |
| 44 | +## 4. Verify |
| 45 | + |
| 46 | +Trigger an event in GitLab (e.g. push a commit or open a merge request). You should see: |
| 47 | + |
| 48 | +- The webhook receiver log the incoming event |
| 49 | +- The event published to NATS on `gitlab.{event}` |
| 50 | + |
| 51 | +You can inspect NATS with: |
| 52 | + |
| 53 | +```bash |
| 54 | +nats sub -s nats://nats.trogonai.orb.local:4222 "gitlab.>" |
| 55 | +``` |
| 56 | + |
| 57 | +Without `--profile dev`, ngrok is excluded and only the core services start. |
| 58 | + |
| 59 | +## Environment variables |
| 60 | + |
| 61 | +| Variable | Required | Default | Description | |
| 62 | +|---|---|---|---| |
| 63 | +| `GITLAB_WEBHOOK_SECRET` | yes | — | Secret token configured in GitLab's webhook settings | |
| 64 | +| `NGROK_AUTHTOKEN` | yes (dev profile) | — | ngrok auth token | |
| 65 | +| `GITLAB_WEBHOOK_PORT` | no | `8080` | HTTP port for the webhook receiver | |
| 66 | +| `GITLAB_SUBJECT_PREFIX` | no | `gitlab` | NATS subject prefix (must be valid NATS token) | |
| 67 | +| `GITLAB_STREAM_NAME` | no | `GITLAB` | JetStream stream name (must be valid NATS token) | |
| 68 | +| `GITLAB_STREAM_MAX_AGE_SECS` | no | `604800` | Max message age in seconds (7 days) | |
| 69 | +| `GITLAB_NATS_ACK_TIMEOUT_MS` | no | `10000` | JetStream ACK timeout in milliseconds | |
| 70 | +| `GITLAB_MAX_BODY_SIZE` | no | `26214400` | Maximum webhook body size in bytes (25 MB) | |
| 71 | +| `NATS_URL` | no | `localhost:4222` | NATS server URL(s) | |
| 72 | +| `RUST_LOG` | no | `info` | Log level | |
0 commit comments