基于Caddy的Webhook## 介绍本文介绍一种利用CaddyServer构建webhook服务的方法。¶
1.安装CaddyServer安装 caddy 最简单的方法是使用包管理器。¶
-
在 Debian/Ubuntu 上
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \ | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \ | sudo tee /etc/apt/sources.list.d/caddy-stable.list sudo apt update sudo apt install caddy -
在 RHEL/CentOS/RockyLinux 上
dnf install 'dnf-command(copr)' dnf copr enable @caddy/caddy dnf install caddy
2.添加Caddy模块- 在线添加套餐 ```¶
sudo caddy add-package XXX
```
XXX 是包名称,始终以github.com/xxxxxx开头。
从[下载页面][下载页面]很容易找到包名称。
示例: > 安装 webhook 模块: > >
sudo caddy add-package github.com/WingLim/caddy-webhook> 安装执行模块: > >sudo caddy add-package github.com/mholt/caddy-events-exec- 手动添加包 从[下载页面][DownloadPage]选择并下载带有模块的CaddyServer。 将可执行的caddy文件替换为下载的:sudo mv caddy /usr/bin sudo chmod +x /usr/bin/caddy sudo restorecon /usr/bin/caddy sudo chown root:root /usr/bin/caddy
3.修改CaddyServer的服务文件由于默认systemd文件中的配置,参数ProtectSystem=full,caddy失去了写入/usr,/boot和/etc的权限。(详见[参考2])。¶
- 添加对 caddy web 文件夹
/usr/share/caddy的读写权限将参数添加到[service]标签下的服务文件/usr/lib/systemd/system/caddy.service中:ReadWritePaths=/usr/share/caddy - 重新加载系统
sudo systemctl daemon-reload
4.配置Caddyfile¶
-
网络钩子模块配置介绍可参考:[caddy-webhook][webhook]
route /webhook { webhook { repo https://github.com/WingLim/winglim.github.io.git path /usr/share/caddy branch master depth 1 type github/gitlab/gitee/gogs/bitbucket command username password key token submodule } } -
执行模块配置介绍可用:[caddy-exec][exec]
route /webhook { exec { command git args pull directory /usr/share/caddy log file /var/log/caddy/git.log } }
参考文献[1]. https://caddyserver.com/docs/install¶
[2]. https://www.redhat.com/sysadmin/mastering-systemd
[3]. https://github.com/abiosoft/caddy-exec
[4]. https://github.com/WingLim/caddy-webhook
[5]. 在 RHEL 上使用 Caddy 进行反向代理 [参考2]:https://www.redhat.com/sysadmin/mastering-systemd[下载页面]:https://caddyserver.com/download[网络钩子]:https://github.com/WingLim/caddy-webhook[执行]:https://github.com/abiosoft/caddy-exec