- example for app example.com
- i assume you installed nginx
1. Add a repository webhook on Github
- Settings > Webhooks > Add webhook: add a webhook with settings:
+ Payload UR: https://example-app.com/hooks/example-webhook
+ Content type: application/json
+ Secret: your-secret-key
+ SSL verification: enabled
+ Which events would you like to trigger this webhook: Default option: "Just the push event."
+ Active — Uncheck this option. We will activate later after we create the endpoin
2. Install Webhook server to listen incoming request from Github
- install Webhook server
tar -xzf webhook-linux-amd64.tar.gz
sudo systemctl stop webhook.service
sudo cp webhook-linux-amd64/webhook /usr/bin/
sudo systemctl start webhook.service
webhook --version
# must be version 2.8.0
# webhook will start default port 9000, location in /usr/bin
which webhook -version
https://github.com/adnanh/webhook
# webhook version 2.6.9 not working
- create /var/www/hook.json in
{
"id": "example-webhook",
"execute-command": "/var/www/auto_deploy/autodeploy-example.sh",
"command-working-directory": "/var/www/example.com",
"trigger-rule":
{
"and":
[
{
"match":
{
"type": "payload-hmac-sha1",
"secret": "your-secret-key",
"parameter":
{
"source": "header",
"name": "X-Hub-Signature"
}
}
},
{
"match":
{
"type": "value",
"value": "refs/heads/master",
"parameter":
{
"source": "payload",
"name": "ref"
}
}
}
]
}
}
]
- create /var/www/auto_deploy/autodeploy-example.sh
- make it executable for autodeploy-example.sh
- start Webhook
3. Config nginx for webhook
- configure nginx that redirects all requests with destination https://example.com/hooks/..... to Webhook.
sudo nano /etc/nginx/sites-available/example.com
# Webhook reverse proxy
location /hooks/ {
proxy_pass http://127.0.0.1:9000/hooks/;
}
sudo systemctl restart nginx
* some errors can happen
- [webhook] error in exec: "...autodeploy-example.sh": permission denied
chmod +x autodeploy-example.sh
Thank you.

No comments:
Post a Comment