Webhook to auto-deploy on git push to Github

What is a webhook? A webhook is an endpoint on your server which allows you to execute a particular task. Webhooks are usually triggered by some event. A good use-case for a webhook is running tests on a dedicated test server or deploying your latest master branch to staging/production. Github / Gitlab / Bitbucket allow you to specify a webhook URL in your repository settings. Github triggers the webhook which sends the event data on every push. Webhook server Webhook is a very useful golang project which runs any script you specify when a particular endpoint is hit. Download and extract the binary for your operating system from the releases page. For Linux, it is here. The program takes as config a hooks.json file: [ { "id": "hello-world", "execute-command": "/home/user/scripts/hello.sh", "command-working-directory": "/home/user/webhook" } ] Replace user with the username of your linux user. The hello.sh script. #!/bin/bash echo 'Hello!' Make the script executable by running chmod +x hello.sh Start webhook server as webhook -hooks hooks.json -hotreload -logfile webhooks.log. The server will run on port 9000 by default. You can check if everything is working by running curl http://localhost:9000/hooks/hello-world. This will print “Hello!” in the log file. ...

May 25 2020 · 3 min · Raunak