Caddy v2 module for serving a webhook.
English | 中文
xcaddy build \
--with github.com/WingLim/caddy-webhook
See caddy-docker for Dockerfile
.
DockerHub: winglim/caddy
GitHub Package: winglim/caddy
Now supported webhook type:
- github
- gitlab
- gitee
- bitbucket
- gogs
Notice: webhook
block should be the last handler of route
.
After receive request and handle it, we return nil
instead of the next middleware.
So, the next handler after webhook
will not work.
webhook [<repo> <path>] {
repo <text>
path <text>
branch <text>
depth <int>
type <text>
secret <text>
command <text>...
key <text>
username <text>
password <text>
token <text>
submodule
}
- repo - git repository url, supported http, https and ssh.
- path - path to clone and update repository.
- branch - branch to pull. Default is
main
. - depth - depth for pull. Default is
0
. - type - webhook type. Default is
github
. - secret - secret to verify webhook request.
- submodule - enable recurse submodules.
- command - the command run when repo initializes or get the correct webhook request.
- key - path of private key, using to access git with ssh.
- username - username for http auth.
- password - password for http auth.
- token - GitHub personal access token.
The full example to run a hugo blog:
Caddyfile
:
example.com
root www
file_server
route /webhook {
webhook {
repo https://github.com/WingLim/winglim.github.io.git
path blog
branch hugo
command hugo --destination ../www
submodule
}
}
With the config above, webhook module will do things:
-
Clone https://github.com/WingLim/winglim.github.io.git to
blog
when initializes.- If the repo is already exist, will fetch and checkout to the branch you set.
-
Run the command
hugo --destination ../www
inside theblog
directory. -
Listen and serve at
/webhook
and handle the webhook request.- When receive correct webhook request, will update repo and do
step 2
again.
- When receive correct webhook request, will update repo and do
- caddygit - Git module for Caddy v2
- caddy-git - git middleware for Caddy
- caddy-exec - Caddy v2 module for running one-off commands