diff --git a/README.md b/README.md index 1706b79..001835c 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,9 @@ If you are using Debian linux ("stretch" or later), you can install webhook usin Prebuilt binaries for different architectures are available at [GitHub Releases](https://github.com/adnanh/webhook/releases). ## Configuration -Next step is to define some hooks you want [webhook][w] to serve. Begin by creating an empty file named `hooks.json`. This file will contain an array of hooks the [webhook][w] will serve. Check [Hook definition page](docs/Hook-Definition.md) to see the detailed description of what properties a hook can contain, and how to use them. +Next step is to define some hooks you want [webhook][w] to serve. +[webhook][w] supports JSON or YAML configuration files, but we'll focus primarily on JSON in the following example. +Begin by creating an empty file named `hooks.json`. This file will contain an array of hooks the [webhook][w] will serve. Check [Hook definition page](docs/Hook-Definition.md) to see the detailed description of what properties a hook can contain, and how to use them. Let's define a simple hook named `redeploy-webhook` that will run a redeploy script located in `/var/scripts/redeploy.sh`. Make sure that your bash script has `#!/bin/sh` shebang on top. @@ -61,6 +63,13 @@ Our `hooks.json` file will now look like this: ] ``` +**NOTE:** If you prefer YAML, the equivalent `hooks.yaml` file would be: +```yaml +- id: redeploy-webhook + execute-command: "/var/scripts/redeploy.sh" + command-working-directory: "/var/webhook" +``` + You can now run [webhook][w] using ```bash $ /path/to/webhook -hooks hooks.json -verbose @@ -90,7 +99,7 @@ All files are ignored unless they match one of the following criteria: In either case, the given file part will be parsed as JSON and added to the `payload` map. ## Templates -[webhook][w] can parse the `hooks.json` input file as a Go template when given the `-template` [CLI parameter](docs/Webhook-Parameters.md). See the [Templates page](docs/Templates.md) for more details on template usage. +[webhook][w] can parse the hooks configuration file as a Go template when given the `-template` [CLI parameter](docs/Webhook-Parameters.md). See the [Templates page](docs/Templates.md) for more details on template usage. ## Using HTTPS [webhook][w] by default serves hooks using http. If you want [webhook][w] to serve secure content using https, you can use the `-secure` flag while starting [webhook][w]. Files containing a certificate and matching private key for the server must be provided using the `-cert /path/to/cert.pem` and `-key /path/to/key.pem` flags. If the certificate is signed by a certificate authority, the cert file should be the concatenation of the server's certificate followed by the CA's certificate. diff --git a/docs/Hook-Definition.md b/docs/Hook-Definition.md index 7c54a20..925bea1 100644 --- a/docs/Hook-Definition.md +++ b/docs/Hook-Definition.md @@ -1,5 +1,6 @@ # Hook definition -Hooks are defined as JSON objects. Please note that in order to be considered valid, a hook object must contain the `id` and `execute-command` properties. All other properties are considered optional. + +Hooks are defined as objects in the JSON or YAML hooks configuration file. Please note that in order to be considered valid, a hook object must contain the `id` and `execute-command` properties. All other properties are considered optional. ## Properties (keys) diff --git a/docs/Hook-Examples.md b/docs/Hook-Examples.md index 7ca2600..ba581eb 100644 --- a/docs/Hook-Examples.md +++ b/docs/Hook-Examples.md @@ -1,5 +1,9 @@ -# Hook examples -This page is still work in progress. Feel free to contribute! +# Hook Examples + +Hooks are defined in a hooks configuration file in either JSON or YAML format, +although the examples on this page all use the JSON format. + +🌱 This page is still a work in progress. Feel free to contribute! ### Table of Contents diff --git a/docs/Templates.md b/docs/Templates.md index b7cb972..12798f4 100644 --- a/docs/Templates.md +++ b/docs/Templates.md @@ -1,12 +1,12 @@ # Templates in Webhook -[`webhook`][w] can parse the `hooks.json` input file as a Go template when given the `-template` [CLI parameter](Webhook-Parameters.md). +[`webhook`][w] can parse a hooks configuration file as a Go template when given the `-template` [CLI parameter](Webhook-Parameters.md). -In additional to the [built-in Go template functions and features][tt], `webhook` provides a `getenv` template function for inserting environment variables into a `hooks.json` file. +In additional to the [built-in Go template functions and features][tt], `webhook` provides a `getenv` template function for inserting environment variables into a templated configuration file. ## Example Usage -In the example `hooks.json` file below, the `payload-hmac-sha1` matching rule looks up the HMAC secret from the environment using the `getenv` template function. +In the example JSON template file below (YAML is also supported), the `payload-hmac-sha1` matching rule looks up the HMAC secret from the environment using the `getenv` template function. Additionally, the result is piped through the built-in Go template function `js` to ensure that the result is a well-formed Javascript/JSON string. ```