A lightweight webhook server for redeploying docker containers.
Inspired by adnanh/webhook which does not support docker officially.
docker run -d -p 8000:8000 --name docker-webhook \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /root/.docker/config.json:/root/.docker/config.json \ # add this line if your registry need login
-v /path/to/config.yaml:/app/config.yaml \
-v /path/to/logs:/app/logs \
-v /path/to/demo_compose_file.yaml:/path/to/demo_compose_file.yaml \
hadb/docker-webhookname: docker-webhook
services:
docker-webhook:
container_name: docker-webhook
image: docker-webhook
restart: always
network_mode: bridge
ports:
- 8000:8000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /root/.docker/config.json:/root/.docker/config.json # add this line if your registry need login
- /path/to/config.yaml:/app/config.yaml
- /path/to/logs:/app/logs
- /path/to/demo_compose_file.yaml:/path/to/demo_compose_file.yamlconfig.yaml:
token: global-token
webhooks:
- id: say-hello
command: echo "Hello, world!"
token: say-hello-token
- id: docker-info
command: docker info
- id: redeploy-demo-compose
command: docker compose -f /path/to/demo_compose_file.yaml up -d --pull=always --force-recreateThe global token is used to authenticate all webhooks. You can also set a specific token for each webhook which will override the global token.
Note that if you want to redeploy using docker compose, you need to mount the compose file to the same path to avoid the error that says the container name is already in use.
You can use the following url to trigger a webhook for test locally:
http://127.0.0.1:8000/webhook/{webhook_id}?token={webhook_token}It's recommended to use a reverse proxy like Nginx to expose the webhook service to the public.
Config new webhook on Docker Hub, set the Webhook URL to https://{your_public_domain}/webhook/{webhook_id}?token={webhook_token}.