Skip to content

Automatic Docker Deployment via Webhooks, [incomplete] running in a Docker container

License

Notifications You must be signed in to change notification settings

nilbus/docker-hook

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-hook

Automatic Docker Deployment via Webhooks

docker-hook listens to incoming HTTP requests and triggers your specified command.

Features

  • No dependencies
  • Super lightweight
  • Dead simple setup process
  • Authentication support

Setup

1. Prepare Your Server

Start docker-hook

Arguments for docker-hook can be passed to docker run, e.g.:

docker run --rm nilbus/docker-hook --help

docker run -d --name docker-hook -p 8555:8555 nilbus/docker-hook -t <auth-token> -c <command>

If your command needs control over the docker daemon it's running in, give it control from within the container by mounting the Docker socket:

docker run \
  -d \
  --name docker-hook \
  -p 8555:8555 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  nilbus/docker-hook -t <auth-token> -c <command>
Auth-Token

Please choose a secure auth-token string or generate one with $ uuidgen. Keep it safe or otherwise other people might be able to trigger the specified command.

Command

The command can be any bash command of your choice. This command will be triggered each time someone makes an HTTP request with a valid token.

2. Configuration On Docker Hub

Add a webhook like on the following image. example.com can be the domain of your server or its ip address. docker-hook listens to port 8555. Please replace my-super-safe-token with your auth-token.

Example

This example will stop the current running yourname/app container, pull the newest version and start a new container.

docker run \
  -d \
  --name docker-hook \
  -p 8555:8555 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v ./deploy.sh:/deploy.sh \
  nilbus/docker-hook -t my-super-safe-token -c sh /deploy.sh

deploy.sh

#!/bin/bash

IMAGE="yourname/app"
docker ps | grep $IMAGE | awk '{print $1}' | xargs docker stop
docker pull $IMAGE
docker run -d $IMAGE

You can now test it by pushing something to yourname/app or by running the following command where yourdomain.com is either a domain pointing to your server or just its ip address.

$ curl -X POST yourdomain.com:8555/my-super-safe-token

How it works

docker-hook uses BaseHTTPRequestHandler to listen for incoming HTTP requests from Docker Hub and then executes the provided command if the authentication was successful.

Caveat

This tool was built as a proof-of-concept and might not be completly secure. If you have any improvement suggestions please open up an issue.

License

MIT License

About

Automatic Docker Deployment via Webhooks, [incomplete] running in a Docker container

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%