Skip to content

WingLim/caddy-webhook

Repository files navigation

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:

  • github
  • gitlab
  • gitee
  • bitbucket
  • gogs

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
}
  • 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.

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