# 03 — Configurar o Webhook no Gitea + Listener ## A) Subir o listener na VPS 4 (um por projeto, porta única) ```bash # 1. Copiar o exemplo e ajustar variáveis cp webhook-listener/config.example.env /home/deploy/stack/webhook-listener/.env nano /home/deploy/stack/webhook-listener/.env # PORT=9003 # WEBHOOK_TOKEN= # DEPLOY_SCRIPT=/home/deploy/stack//deploy-prod-onhost.sh # GITEA_TOKEN= # 2. Instalar a unit systemd sudo cp webhook-listener/webhook-listener.service /etc/systemd/system/webhook-.service sudo systemctl daemon-reload sudo systemctl enable --now webhook- # 3. Conferir systemctl status webhook- ``` ## B) Criar o webhook no Gitea (VPS 3) No repositório → **Settings → Webhooks → Add Webhook → Gitea**: | Campo | Valor | |---|---| | Target URL | `http://10.99.0.4:9003/webhook?token=` | | HTTP Method | `POST` | | Content Type | `application/json` | | Trigger | *Push events* (branch `main`) | | Branch filter | `main` | > O `GITEA_TOKEN` (para reportar status) é gerado em **Settings → Applications → Generate Token** > com escopo `repo:status` (ou `write:repository`). ## C) Testar ```bash # Push de teste dispara o deploy: git commit --allow-empty -m "test: dispara webhook" && git push origin main # Acompanhar: tail -f /home/deploy/stack/webhook-listener/deploy.log ``` ## Pré-requisitos - Chave SSH do usuário `deploy` (VPS4) com acesso **sem senha** à VPS 1 (`ssh deploy@10.99.0.1 echo ok`). - Chave SSH do `deploy` com permissão de **push** no repositório do Gitea. - Porta do listener liberada apenas na rede VPN (`10.99.0.0/24`).