Skip to main content

Webhook listener dragging along the main Docker process

Project description

Drag: A Webook listener dragging along its dockerized service

Minimalistic GitHub/GitLab webhook listener for use in an existing Docker image.

Problem

The basic premise for Docker and other virtualization environments is to isolate the single service they provide from the environment, for containment, ease of administration, and security.

Sometimes, however, it is necessary to inform the running service of changes, without having to recreate the entire container. For example, a web or DNS server should serve new files or use a different configuration.

The classic solution is to expose the directory tree in question to the host or another container, which updates the contents. That works great unless the server needs to be informed when it should start to use the new data.

Running the update process on the host is often not an option. Running it inside another container requires either a listener in the service container (which brings us back to square one) or exposing the Docker control socket to the container, with security and dependency problems.

Alternatives include running a service manager inside the container.

Solution: Webhook inside the service container

drag is an easy way of adding a webhook to an existing container. Just create a Dockerfile inheriting from the original service, installing drag and using it as a wrapper for the original command.

FROM cznic/knot:latest

RUN apt update && \
    apt install --no-install-recommends --yes python3-pip git ssh && \
    apt clean && \
    rm -rf /var/lib/apt/lists/*
RUN pip3 install drag && rm -rf ${HOME}/.cache

# `drag` is configured by environment variables
# The secret that must be part of a GitHub- or GitLab-style request
ENV DRAG_SECRET 123
# The command to execute, passed to a shell
ENV DRAG_COMMAND cd /storage/data && git update && knotc reload
# Ensure everything is up to date at start (cannot reload daemon yet)
ENV DRAG_INIT cd /storage/data && git update

# Just prepend `drag` to the original command line
CMD ["drag", "knot", "-c", "/config/knot.cfg']

Operation

drag forks a child process, which listen for HTTP webhook requests on port 1291, verifying them against DRAG_SECRET, before running DRAG_COMMAND.

The main process replaces itself by what the service process, so it maintains process ID 1, and termination of the service process will be managed by Docker as usual.

HTTPS support

HTTPS support is missing on purpose, as it is expected that you already run your HTTPS proxy somewhere. If not, have a look at https-portal, which can be configured e.g. with the following lines of docker-compose.yml:

version: '2'
services:
  reverse-proxy:
    image: steveltn/https-portal:1
    restart: unless-stopped
    volumes:
      - ./ssl-certs:/var/lib/https-portal
      - ./vhosts:/var/www/vhosts
    ports:
      - '80:80'
      - '443:443'
    environment:
      DOMAINS: |
        hook.example.com -> dockerhost:1291,
        (more domains here)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drag-0.1.3.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

drag-0.1.3-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file drag-0.1.3.tar.gz.

File metadata

  • Download URL: drag-0.1.3.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.5

File hashes

Hashes for drag-0.1.3.tar.gz
Algorithm Hash digest
SHA256 365800b2ad7e769228309408e74981fac2b97d2101aa425e9229455d1de51816
MD5 7da4626eec50734812c84ec0ccca70b9
BLAKE2b-256 45a5ed0ed4835b57281c590d6b55683b10e61be51ccfab07af802aac69711d52

See more details on using hashes here.

File details

Details for the file drag-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: drag-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.5

File hashes

Hashes for drag-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d6bb1787f7d2d1d90d40ac36fefdb2d4e190ec108a3598fbcad631c4a6b51c28
MD5 b447a0e8744f60681c4e2bf0f5fc0730
BLAKE2b-256 dbd9c54214af502130137b0ff397f9c3130dfec278baea7327b22959cb4a8c0a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page