clj-webhook-consumer is simple Clojure server that sets up endpoints for responding to webhooks like those from dockerhub and github. For example, you configure the server to restart a docker container with an updated image when a new image is pushed to dockerhub. It’s meant to be the final link in a continuous deployment system.
clj-webhook-consumer uses a configuration file to set up your endpoints.
hooks:
- name: dockerhub
script: ./new-image-alert.sh
- name: github
script: ./repo-pushed-alert.sh
This will set up endpoints at localhost:3000/dockerhub
and localhost:3000/github
that will respond to events by running the specified shell script.
If you set the environment variable CLJ_WEBHOOK_KEY
, then you will need to pass it with your requests as a query parameter:
https://your-domain/dockerhub?key=your_api_key
This server doesn’t directly support https, but it’s meant to be run behind a reverse proxy (nginx) that does.
You can also map any json data received from the webhook to environment variables.
hooks:
- name: dockerhub
script:
- ./echo-repo-description.sh
- ./copy-dockerfile.sh
body->env:
repository:
full_description: FULL_DESCRIPTION
dockerfile: _
This example expects json like the following:
{
"repository": {
"full_description": "A description of the repository that was pushed to",
"dockerfile": "The contents of the Dockerfile used for the build"
}
}
When the scripts run, the environment variables will be set accordingly:
echo $FULL_DESCRIPTION => "A description of the repository that was pushed to"
echo $DOCKERFILE => "The contents of the Dockerfile used for the build"
You can also map query string parameters to environment variables:
hooks:
- name: get-hook
script:
- ./echo-param.sh
query->env:
param: PARAM
This expects a get request like this:
https://your-domain.com/get-hook?key=your_api_key¶m=paramval
Build a standalone jar (or download the latest release)
./build.sh
Run the standalone jar:
java -jar target/clj-webhook-consumer-0.2.0-SNAPSHOT-standalone.jar
The server will look for your .clj-webhook.yaml
file and scripts in the directory that you run the jar.
lein test
lein run
Copyright © 2019 Lane Spangler
This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.~~