├── rpm ├── .gitignore ├── Makefile ├── webhook.spec ├── .travis.yml └── webhook.init ├── README.md ├── docker ├── Makefile ├── Dockerfile └── README.md ├── snapcraft.yaml ├── testing └── linux │ └── coverage └── LICENSE /rpm/.gitignore: -------------------------------------------------------------------------------- 1 | src/ 2 | rpmbuild/ 3 | *.rpm 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # webhook-contrib 2 | Repository for community contributed tools and helpers for http://github.com/adnanh/webhook 3 | -------------------------------------------------------------------------------- /docker/Makefile: -------------------------------------------------------------------------------- 1 | DOCKER_IMAGE_NAME = adnanh/webhook 2 | CONTAINER_NAME = webhook 3 | 4 | docker-build: Dockerfile 5 | docker build --force-rm=true --tag=$(DOCKER_IMAGE_NAME) . 6 | 7 | docker-run: 8 | @echo "Here's an example command on how to run a webhook container:" 9 | @echo "docker run -d -p 9000:9000 -v /etc/webhook:/etc/webhook --name=$(CONTAINER_NAME) \\" 10 | @echo " $(DOCKER_IMAGE_NAME) -verbose -hooks=/etc/webhook/hooks.json -hotreload" 11 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | MAINTAINER Adnan Hajdarevic 3 | 4 | ENV GOPATH /go 5 | ENV SRCPATH ${GOPATH}/src/github.com/adnanh/webhook 6 | COPY . ${SRCPATH} 7 | RUN apk add --update -t build-deps go git libc-dev gcc libgcc && \ 8 | cd ${SRCPATH} && go get -d && go build -o /usr/local/bin/webhook && \ 9 | apk del --purge build-deps && \ 10 | rm -rf /var/cache/apk/* && \ 11 | rm -rf ${GOPATH} 12 | 13 | EXPOSE 9000 14 | ENTRYPOINT ["/usr/local/bin/webhook"] 15 | -------------------------------------------------------------------------------- /snapcraft.yaml: -------------------------------------------------------------------------------- 1 | name: webhook 2 | version: '1.0' 3 | summary: webhook is a lightweight incoming webhook server to run shell commands 4 | description: | 5 | webhook is a lightweight incoming webhook server to run shell commands. 6 | grade: stable 7 | confinement: strict 8 | base: core18 9 | parts: 10 | webhook: 11 | plugin: go 12 | source: https://github.com/adnanh/webhook.git 13 | go-importpath: github.com/adnanh/webhook 14 | build-packages: 15 | - build-essential 16 | apps: 17 | webhook: 18 | command: bin/webhook 19 | daemon: simple 20 | restart-condition: on-abnormal 21 | plugs: 22 | - home 23 | - network 24 | - network-bind 25 | -------------------------------------------------------------------------------- /rpm/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR=$(CURDIR)/rpmbuild 2 | 3 | build_rpm: 4 | rm -rf src 5 | git clone https://github.com/adnanh/webhook src 6 | cd src && \ 7 | export VERSION=$$(git describe --tags --abbrev=0 | sed -e 's!v!!') && \ 8 | export COMMIT=$$(git rev-parse HEAD) && \ 9 | export SHORTCOMMIT=$$(git rev-parse HEAD|cut -c-7) && \ 10 | export COMMIT_COUNT=$$(git rev-list --count HEAD) && \ 11 | make build && \ 12 | cd .. && \ 13 | mkdir -p $(TOP_DIR)/ && \ 14 | cp src/webhook $(TOP_DIR)/ && \ 15 | cp src/hooks.json.example $(TOP_DIR)/ && \ 16 | cp src/LICENSE $(TOP_DIR)/ && \ 17 | cp src/README.md $(TOP_DIR)/ && \ 18 | rpmbuild -bb \ 19 | --define "_commit $$COMMIT" \ 20 | --define "_shortcommit $$SHORTCOMMIT" \ 21 | --define "_commitcount $$COMMIT_COUNT" \ 22 | --define "_version $$VERSION" \ 23 | --define "_topdir $(TOP_DIR)" \ 24 | webhook.spec 25 | cp $(TOP_DIR)/RPMS/**/*.rpm . 26 | rm -rf $(TOP_DIR) 27 | 28 | .PHONY: clean 29 | clean: 30 | rm -rf *.rpm 31 | rm -rf src 32 | rm -rf $(TOP_DIR) 33 | -------------------------------------------------------------------------------- /testing/linux/coverage: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # this file is from: 4 | # https://raw.githubusercontent.com/mlafeldt/chef-runner/v0.7.0/script/coverage 5 | # it is covered by the Apache License v2.0 6 | # modified for our purpose 7 | # 8 | # Generate test coverage statistics for Go packages. 9 | # 10 | # Works around the fact that `go test -coverprofile` currently does not work 11 | # with multiple packages, see https://code.google.com/p/go/issues/detail?id=6909 12 | # 13 | # Usage: script/coverage 14 | # 15 | 16 | #set -e 17 | 18 | workdir=.cover 19 | profile="$workdir/cover.out" 20 | mode=count 21 | 22 | generate_cover_data() { 23 | echo "Cleaning" 24 | rm -rf "$workdir" 25 | mkdir "$workdir" 26 | 27 | for pkg in "$@"; do 28 | echo $pkg 29 | f="$workdir/$(echo $pkg | tr / -).cover" 30 | go test -covermode="$mode" -coverprofile="$f" "$pkg" 31 | done 32 | 33 | echo "Building coverfile" 34 | echo "mode: $mode" >"$profile" 35 | grep -h -v "^mode:" "$workdir"/*.cover >>"$profile" 36 | } 37 | 38 | generate_cover_data $(go list ./...) 39 | echo "Showing report" 40 | go tool cover -html="$profile" 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Adnan Hajdarević 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | # Running webhook in Docker 2 | The simplest usage of [adnanh/webhook](https://hub.docker.com/r/adnanh/webhook/) image is for one to host the hooks JSON file on their machine and mount the directory in which those are kept as a volume to the Docker container: 3 | ```shell 4 | docker run -d -p 9000:9000 -v /dir/to/hooks/on/host:/etc/webhook --name=webhook \ 5 | adnanh/webhook -verbose -hooks=/etc/webhook/hooks.json -hotreload 6 | ``` 7 | 8 | Another method of using this Docker image is to create a simple `Dockerfile`: 9 | ```docker 10 | FROM adnanh/webhook 11 | COPY hooks.json.example /etc/webhook/hooks.json 12 | ``` 13 | 14 | This `Dockerfile` and `hooks.json.example` files should be placed inside the same directory. After that run `docker build -t my-webhook-image .` and then start your container: 15 | ```shell 16 | docker run -d -p 9000:9000 --name=webhook my-webhook-image -verbose -hooks=/etc/webhook/hooks.json -hotreload 17 | ``` 18 | 19 | Additionally, one can specify the parameters to be passed to [webhook](https://github.com/adnanh/webhook/) in `Dockerfile` simply by adding one more line to the previous example: 20 | ```docker 21 | FROM adnanh/webhook 22 | COPY hooks.json.example /etc/webhook/hooks.json 23 | CMD ["-verbose", "-hooks=/etc/webhook/hooks.json", "-hotreload"] 24 | ``` 25 | 26 | Now, after building your Docker image with `docker build -t my-webhook-image .`, you can start your container by running just: 27 | ```shell 28 | docker run -d -p 9000:9000 --name=webhook my-webhook-image 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /rpm/webhook.spec: -------------------------------------------------------------------------------- 1 | %global provider github 2 | %global provider_tld com 3 | %global project adnanh 4 | %global repo webhook 5 | # https://github.com/adnanh/webhook 6 | %global provider_prefix %{provider}.%{provider_tld}/%{project}/%{repo} 7 | 8 | # set via `rpmbuild --define "_fooo bar" ... 9 | %if 0%{?_commit:1} 10 | %global commit %{_commit} 11 | %else 12 | %global commit unknown 13 | %endif 14 | 15 | %if 0%{?_version:1} 16 | %global version %{_version} 17 | %else 18 | %global version unknown 19 | %endif 20 | %global shortcommit %(c=%{commit}; echo ${c:0:7}) 21 | 22 | Name: %{repo} 23 | Version: %{version} 24 | Release: %{_commitcount}_%{shortcommit}%{?dist} 25 | Summary: webhook is a lightweight configurable webhook server written in Go 26 | License: MIT 27 | URL: https://%{provider_prefix} 28 | 29 | %description 30 | %{summary} 31 | 32 | %prep 33 | 34 | %build 35 | 36 | %install 37 | install -d -p %{buildroot}%{_bindir} 38 | install -p -m 0755 %{_topdir}/%{name} %{buildroot}%{_bindir} 39 | install -d -p %{buildroot}%{_sysconfdir}/webhook/ 40 | install -p -m 0640 %{_topdir}/hooks.json.example %{buildroot}%{_sysconfdir}/%{name}/ 41 | install -d -p %{buildroot}%{_docdir}/%{name}-%{version}/ 42 | install -p -m 0640 %{_topdir}/README.md %{buildroot}%{_docdir}/%{name}-%{version}/ 43 | install -p -m 0640 %{_topdir}/hooks.json.example %{buildroot}%{_docdir}/%{name}-%{version}/ 44 | install -d -p %{buildroot}%{_licensedir}/%{name}-%{version}/ 45 | install -p -m 0640 %{_topdir}/LICENSE %{buildroot}%{_licensedir}/%{name}-%{version}/ 46 | 47 | %files 48 | %license LICENSE 49 | %doc README.md hooks.json.example 50 | %config(noreplace)%{_sysconfdir}/webhook/* 51 | %{_bindir}/webhook 52 | -------------------------------------------------------------------------------- /rpm/.travis.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - master 4 | notifications: 5 | email: 6 | on_success: never 7 | on_failure: always 8 | sudo: required 9 | services: 10 | - docker 11 | before_install: 12 | - echo "deb http://us.archive.ubuntu.com/ubuntu trusty main universe" | sudo tee -a /etc/apt/sources.list 13 | - sudo apt-get update 14 | - docker pull fedora:22 15 | before_script: 16 | - docker run -i --privileged -d -v $HOME/build/$TRAVIS_REPO_SLUG:$HOME/build/$TRAVIS_REPO_SLUG --name test_fedora fedora:22 bash 17 | - docker exec -i test_fedora bash -c "dnf install -y rpmdevtools make mock git python-pip" 18 | - docker exec -i test_fedora bash -c "dnf install -y go-compilers-golang-compiler" 19 | - docker exec -i test_fedora bash -c "dnf install -y https://kojipkgs.fedoraproject.org//packages/golang-github-go-fsnotify-fsnotify/1.2.0/0.1.git96c060f.fc22/noarch/golang-github-go-fsnotify-fsnotify-devel-1.2.0-0.1.git96c060f.fc22.noarch.rpm" 20 | - docker exec -i test_fedora bash -c "dnf install -y https://kojipkgs.fedoraproject.org//packages/golang-github-codegangsta-negroni/0.1/1.gitc7477ad.fc22/noarch/golang-github-codegangsta-negroni-devel-0.1-1.gitc7477ad.fc22.noarch.rpm" 21 | - docker exec -i test_fedora bash -c "dnf install -y https://kojipkgs.fedoraproject.org//packages/golang-github-gorilla-mux/0/0.18.git8096f47.fc22/noarch/golang-github-gorilla-mux-devel-0-0.18.git8096f47.fc22.noarch.rpm" 22 | - docker exec -i test_fedora bash -c "useradd -g root fedora; usermod -a -G mock fedora" 23 | - docker exec -i test_fedora bash -c "pip install git+https://github.com/shawnsi/docker-rpmbuild" 24 | script: 25 | - docker exec -i test_fedora bash -c "pip install git+https://github.com/shawnsi/docker-rpmbuild" 26 | - docker exec -u fedora -i test_fedora bash -c "cd $HOME/build/$TRAVIS_REPO_SLUG ; make build_rpm" 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /rpm/webhook.init: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Start the Webhook daemon 4 | # 5 | # chkconfig: 35 82 16 6 | # description: webhook is a lightweight configurable tool written in Go, that \ 7 | # allows you to easily create HTTP endpoints (hooks) on your server, which \ 8 | # you can use to execute configured commands. 9 | 10 | ### BEGIN INIT INFO 11 | # Provides: webhook 12 | # Required-Start: $syslog $local_fs 13 | # Required-Stop: $syslog $local_fs 14 | # Should-Start: 0 1 2 6 15 | # Should-Stop: 3 5 16 | # Default-Start: 0 1 2 6 17 | # Default-Stop: 3 5 18 | # Short-Description: webhook allows you to easily create HTTP endpoints (hooks) on your server 19 | # Description: webhook allows you to easily create HTTP endpoints (hooks) on your server 20 | ### END INIT INFO 21 | 22 | # Source function library. 23 | . /etc/rc.d/init.d/functions 24 | 25 | exec="/usr/bin/webhook" 26 | prog="webhook" 27 | config="/etc/webhook/hooks.json" 28 | 29 | [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog 30 | 31 | 32 | 33 | 34 | lockfile=/var/lock/subsys/$prog 35 | pidfile=/var/run/$prog.pid 36 | 37 | start() { 38 | [ -x $exec ] || exit 5 39 | [ -f $config ] || exit 6 40 | echo -n $"Starting $prog: " 41 | # if not running, start it up here, usually something like "daemon $exec" 42 | ((exec $exec -hooks=$config $OPTIONS &>/dev/null)&) 43 | retval=$? 44 | echo 45 | [ $retval -eq 0 ] && touch $lockfile 46 | return $retval 47 | } 48 | 49 | stop() { 50 | echo -n $"Stopping $prog: " 51 | killproc $prog 52 | retval=$? 53 | echo 54 | [ $retval -eq 0 ] && rm -f $lockfile 55 | return $retval 56 | } 57 | 58 | restart() { 59 | stop 60 | start 61 | } 62 | 63 | reload() { 64 | restart 65 | } 66 | 67 | force_reload() { 68 | restart 69 | } 70 | 71 | rh_status() { 72 | # run checks to determine if the service is running or use generic status 73 | status $prog 74 | } 75 | 76 | rh_status_q() { 77 | rh_status >/dev/null 2>&1 78 | } 79 | 80 | 81 | case "$1" in 82 | start) 83 | rh_status_q && exit 0 84 | $1 85 | ;; 86 | stop) 87 | rh_status_q || exit 0 88 | $1 89 | ;; 90 | restart) 91 | $1 92 | ;; 93 | reload) 94 | rh_status_q || exit 7 95 | $1 96 | ;; 97 | force-reload) 98 | force_reload 99 | ;; 100 | status) 101 | rh_status 102 | ;; 103 | condrestart|try-restart) 104 | rh_status_q || exit 0 105 | restart 106 | ;; 107 | *) 108 | echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" 109 | exit 2 110 | esac 111 | exit $? 112 | --------------------------------------------------------------------------------