/docker-webhook

A lightweight webhook server for redeploying docker containers.

Primary LanguagePythonMIT LicenseMIT

Docker Webhook

Release GitHub Release Docker Image Size License

A lightweight webhook server for redeploying docker containers.

Inspired by adnanh/webhook which does not support docker officially.

Getting started

Installation

Using docker command

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-webhook

Using docker compose

name: 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.yaml

Configuration

config.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-recreate

The 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.

Testing

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}

Triggering from Docker Hub

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}.

Similar Projects

License

MIT License © 2024 Bean Deng