WingLim / caddy-webhook

Caddy v2 module for serving a webhook.
MIT License
29 stars 4 forks source link
caddy caddy-module webhook

caddy-webhook

Build License: MIT

Caddy v2 module for serving a webhook.

English | 中文

Installation

Build with xcaddy

xcaddy build \
  --with github.com/WingLim/caddy-webhook

Run in Docker

See caddy-docker for Dockerfile.

DockerHub: winglim/caddy

GitHub Package: winglim/caddy

Usage

Now supported webhook type:

Caddyfile Format

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
}

Example

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:

  1. Clone https://github.com/WingLim/winglim.github.io.git to blog when initializes.

    1. If the repo is already exist, will fetch and checkout to the branch you set.
  2. Run the command hugo --destination ../www inside the blog directory.

  3. Listen and serve at /webhook and handle the webhook request.

    1. When receive correct webhook request, will update repo and do step 2 again.

Thanks to