Skip to main content

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)

Metadata

Release files for drag 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drag 0.1.3
File Size Uploaded
drag-0.1.3.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drag 0.1.3
File Interpreter ABI Platform
drag-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / drag-0.1.3.tar.gz

Download URL drag-0.1.3.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
365800b2ad7e769228309408e74981fac2b97d2101aa425e9229455d1de51816
BLAKE2b-256 checksum
How to use checksums
45a5ed0ed4835b57281c590d6b55683b10e61be51ccfab07af802aac69711d52
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / drag-0.1.3-py3-none-any.whl

Download URL drag-0.1.3-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6bb1787f7d2d1d90d40ac36fefdb2d4e190ec108a3598fbcad631c4a6b51c28
BLAKE2b-256 checksum
How to use checksums
dbd9c54214af502130137b0ff397f9c3130dfec278baea7327b22959cb4a8c0a
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page