53 lines
1.7 KiB
Markdown
53 lines
1.7 KiB
Markdown
# 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/<projeto>.env
|
|
nano /home/deploy/stack/webhook-listener/<projeto>.env
|
|
# PORT=9003
|
|
# WEBHOOK_TOKEN=<token-forte>
|
|
# DEPLOY_SCRIPT=/home/deploy/stack/<projeto>/deploy-prod-onhost.sh
|
|
# GITEA_TOKEN=<token-da-API-do-gitea>
|
|
|
|
# 2. Instalar a unit systemd
|
|
sudo cp webhook-listener/webhook-listener.service /etc/systemd/system/webhook-<projeto>.service
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable --now webhook-<projeto>
|
|
|
|
# 3. Conferir
|
|
systemctl status webhook-<projeto>
|
|
```
|
|
|
|
## 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=<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`).
|