This is a simple webhook that listens for POST requests and runs a shell script. It is intended to be used in a Docker container.
export WEBHOOK_SECRET=secretdocker build -t webhook .Or get them from github docker registry
docker pull ghcr.io/danildzambrana/docker-webhook:mainYou can check the image is downloaded with the following command:
docker images lsand check the image is in the list.
docker run -p 5030:80 --privileged --name webhook -e WEBHOOK_SECRET -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/danildzambrana/docker-webhook:main uvicorn main:app --host 0.0.0.0 --port 80or you can run the compose file compose.yml with the following command:
Note
Remember to check the image name in the compose file, if you build the image with the name webhook you don't need to change anything, otherwise you need to change the image name in the compose file.
docker-compose up -dcurl -X POST http://localhost:5030/webhook- Go to the repository settings
- Click on Webhooks
- Click on Add webhook
- Set the Payload URL to http://localhost:5030/webhook
- Set the Content type to application/json
- Set the Secret to the value of the environment variable WEBHOOK_SECRET
- Select the event DELETE in the events section
- Click on Add webhook
- Delete a branch in the repository
- Check the logs of the webhook container
- The webhook should have received the POST request and executed the shell script
- The branch should have been deleted
docker stop webhookdocker rm webhook