Gihub Webhook URL: http://<URL>:9000/hooks/dev-deploy
gh_webhook.sh:
#!/usr/local/bin/bash
set -euo pipefail
CONFIG="/home/user/webhook-freebsd-amd64/hooks.yaml"
WEBHOOK_BIN="/home/user/webhook-freebsd-amd64/webhook"
if pgrep -x "webhook" >/dev/null
then
echo "Webhook daemon is running"
else
echo "Starting webhook daemon..."
daemon -r -f -t "GitHub webhook" ${WEBHOOK_BIN} -hooks ${CONFIG}
fi
dev-deploy.sh:
#!/usr/local/bin/bash
set -euo pipefail
function git_clone() {
mkdir -p ${LOCAL_GIT_DIR}
cd ${LOCAL_GIT_DIR}
#/usr/bin/env git clone -q ${REPO_URL} . || rm -rf ${LOCAL_GIT_DIR}
/usr/bin/env git clone -q ${REPO_URL} .
}
function git_pull() {
cd ${LOCAL_GIT_DIR}
/usr/bin/env git checkout -q master
/usr/bin/env git fetch -p -q --all
/usr/bin/env git reset -q --hard origin/master
}
function main() {
while getopts ":D:U:" opt; do
case "${opt}" in
D) LOCAL_GIT_DIR="${OPTARG}"; ;;
U) REPO_URL="${OPTARG}"; ;;
h|*) echo "use -D, -U, option, not null"; ;;
esac
done
shift "$((OPTIND-1))"
if [ ! -d "${LOCAL_GIT_DIR}" ]; then
git_clone
git_pull
else
git_pull
fi
}
main "${@:-""}" echo "${*:-""} success"
hooks.yaml:
- id: dev-deploy
execute-command: "dev-deploy.sh"
command-working-directory: "/home/user/"
response-message: Executing redeploy script
include-command-output-in-response: true
trigger-rule-mismatch-http-response-code: 400
pass-arguments-to-command:
- source: string
name: -D
- source: string
name: "/home/user/site.com"
- source: string
name: -U
- source: payload
name: repository.clone_url
trigger-rule:
and:
- match:
type: payload-hmac-sha1
secret: "S3cr3t"
parameter:
source: header
name: X-Hub-Signature
- match:
type: value
value: refs/heads/master
parameter:
source: payload
name: ref