Git Product home page Git Product logo

thatsk-_-docker-hook's Introduction

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
  • Authentification support

Setup

1. Prepare Your Server

Download docker-hook

No worries - it just downloads a Python script. There won't be anything installed or written elsewhere.

$ curl https://raw.githubusercontent.com/schickling/docker-hook/master/docker-hook > /usr/local/bin/docker-hook; chmod +x /usr/local/bin/docker-hook

Start docker-hook

$ 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. See the following example. This command will be triggered each time someone makes a HTTP request.

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-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 is written in plain Python and does have no further dependencies. It uses BaseHTTPRequestHandler to listen for incoming HTTP requests from Docker Hub and then executes the provided command if the authentification 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

thatsk-_-docker-hook's People

Contributors

martinthoma avatar schickling avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.