├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── PLUGINS.md ├── README.md ├── plugins ├── available │ ├── autoremove │ │ ├── die │ │ └── plugin.toml │ ├── envhooks │ │ ├── create │ │ ├── destroy │ │ ├── die │ │ ├── exists │ │ ├── export │ │ ├── kill │ │ ├── pause │ │ ├── plugin.toml │ │ ├── restart │ │ ├── start │ │ ├── stop │ │ └── unpause │ ├── timeout │ │ ├── plugin.toml │ │ └── start │ └── webhooks │ │ ├── _post │ │ ├── create │ │ ├── destroy │ │ ├── die │ │ ├── exists │ │ ├── export │ │ ├── kill │ │ ├── pause │ │ ├── plugin.toml │ │ ├── restart │ │ ├── start │ │ ├── stop │ │ └── unpause └── config.toml └── start /.gitignore: -------------------------------------------------------------------------------- 1 | plugn 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04.5 2 | MAINTAINER Jeff Lindsay 3 | 4 | RUN apt-get update && apt-get install -y curl jq git 5 | 6 | ADD https://get.docker.com/builds/Linux/x86_64/docker-17.03.0-ce.tgz /tmp/docker.tgz 7 | ADD https://github.com/progrium/dockerhook/releases/download/v0.1.0/dockerhook_0.1.0_linux_x86_64.tgz /tmp/dockerhook.tgz 8 | ADD https://github.com/dokku/plugn/releases/download/v0.3.0/plugn_0.3.0_linux_x86_64.tgz /tmp/plugn.tgz 9 | 10 | RUN cd /tmp && tar -zxf /tmp/docker.tgz && rm /tmp/docker.tgz && mv /tmp/docker/* /bin \ 11 | && cd /bin && tar -zxf /tmp/dockerhook.tgz && rm /tmp/dockerhook.tgz \ 12 | && cd /bin && tar -zxf /tmp/plugn.tgz && rm /tmp/plugn.tgz \ 13 | && chmod +x /bin/docker* /bin/plugn \ 14 | && chown root:root /bin/docker* /bin/plugn 15 | 16 | ADD ./plugins /plugins 17 | ENV PLUGIN_PATH /plugins 18 | 19 | ADD ./start /start 20 | CMD ["/start"] 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2014 Jeff Lindsay 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | build: 3 | docker build -t plugins . -------------------------------------------------------------------------------- /PLUGINS.md: -------------------------------------------------------------------------------- 1 | # Available plugins 2 | 3 | The following are available third-party plugins for this repository: 4 | 5 | - Hipchat: https://github.com/lalyos/docker-plugin-hipchat 6 | - Set Consul Keys: https://github.com/bryanlarsen/docker-consulkv-plugin 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-plugins 2 | 3 | A Docker container for running [plugn](https://github.com/progrium/plugn) plugins that respond to Docker events, and a builtin collection of generally useful Docker plugins. 4 | 5 | ## Using docker-plugins 6 | 7 | $ docker pull progrium/plugins 8 | 9 | Once you have it, before using it, you can see plugins by running the `plugn list` command on it: 10 | 11 | $ docker run --rm progrium/plugins plugn list 12 | 13 | The builtin plugins are all disabled by default. You can enable plugins by setting environmant variable `ENABLE` with a space delimited list of plugin names to enable. 14 | 15 | To actually run docker-plugins, you mount your Docker socket and use the default command. Here we'll enable several plugins. You typically run docker-plugins detached, but for now, we'll run it with `-it` to see output and easily close it. 16 | 17 | $ docker run --rm -it \ 18 | -v /var/run/docker.sock:/var/run/docker.sock \ 19 | -e "ENABLE=autoremove timeout" \ 20 | progrium/plugins 21 | 22 | Before starting, it will always show you the current state of plugins inside the container. 23 | 24 | Most plugins are configured via environment variables. For example, here we run docker-plugins with the webhooks plugin enabled and giving it a RequestBin URL to use for all events. 25 | 26 | $ docker run --rm -it \ 27 | -v /var/run/docker.sock:/var/run/docker.sock \ 28 | -e "ENABLE=webhooks" \ 29 | -e "WEBHOOKS_URL=http://requestb.in/ysr016ys" \ 30 | progrium/plugins 31 | 32 | ## Installing plugins 33 | 34 | Plugins can be installed from any Git repository. The `plugn install` command is invoked automatically at boot when setting the `INSTALL` environment variable with a space delimited list of Git repository URLs. These plugins must also be enabled to activate them. 35 | 36 | $ docker run --rm -it \ 37 | -v /var/run/docker.sock:/var/run/docker.sock \ 38 | -e "INSTALL=https://github.com/progrium/docker-plugin-demo.git" 39 | -e "ENABLE=docker-plugin-demo" \ 40 | progrium/plugins 41 | 42 | ## Writing plugins 43 | 44 | Plugins are simply directories of executable hook scripts for available hooks, similar to Dokku plugins, and a plugin.toml file. The `plugn` tool helps manage these plugins. It is still a work in progress, but will eventually also help manage compatibility and configuration. 45 | 46 | Plugins can also implement a `dependencies` hook. The first argument is the plugin name, and this can be used to optionally trigger installing dependencies in use by your plugin. 47 | 48 | ### Hook scripts 49 | 50 | Hook scripts are called by `plugn`, but ultimately triggered by [dockerhook](https://github.com/progrium/dockerhook). For every event from the Docker stream, dockerhook triggers our plugn hooks passing it the container ID as the first argument, and inspected JSON of the container if available via STDIN. It would be *similar* to a command like this: 51 | 52 | $ docker inspect $id | your-hook $id 53 | 54 | However, the JSON passed in is a single object, not a list of objects like the output of `docker inspect`. 55 | 56 | ### Builtin tools for hooks 57 | 58 | The container environment is based on `ubuntu:14.04`. The `docker` binary is installed so you can interact with Docker. The following are some other packages made available to you: 59 | 60 | - `curl` for http access. 61 | - `git` for use with installing plugins. 62 | - `jq` is installed for handling JSON data. 63 | 64 | ### Available hooks 65 | 66 | To implement a hook, just create an executable shell script named after any supported hook. 67 | 68 | * exists - custom hook for containers found at boot before listening for events 69 | * create 70 | * destroy 71 | * die 72 | * export 73 | * kill 74 | * pause 75 | * restart 76 | * start 77 | * stop 78 | * unpause 79 | * untag - supported but not used by builtin plugins 80 | * delete - supported but not used by builtin plugins 81 | 82 | ## License 83 | 84 | BSD 85 | -------------------------------------------------------------------------------- /plugins/available/autoremove/die: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | docker rm $1 -------------------------------------------------------------------------------- /plugins/available/autoremove/plugin.toml: -------------------------------------------------------------------------------- 1 | [plugin] 2 | name = "autoremove" 3 | description = "Removes any container that dies, including stops and kills" 4 | version = "1.0" 5 | maintainer_name = "Jeff Lindsay" 6 | maintainer_email = "progrium@gmail.com" 7 | website_url = "http://github.com/progrium/docker-plugins" 8 | 9 | [plugin.config] 10 | 11 | [plugin.compatibility] 12 | -------------------------------------------------------------------------------- /plugins/available/envhooks/create: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | eval "$ENVHOOKS_CREATE" -------------------------------------------------------------------------------- /plugins/available/envhooks/destroy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | eval "$ENVHOOKS_DESTROY" -------------------------------------------------------------------------------- /plugins/available/envhooks/die: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | eval "$ENVHOOKS_DIE" -------------------------------------------------------------------------------- /plugins/available/envhooks/exists: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | eval "$ENVHOOKS_EXISTS" -------------------------------------------------------------------------------- /plugins/available/envhooks/export: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | eval "$ENVHOOKS_EXPORT" -------------------------------------------------------------------------------- /plugins/available/envhooks/kill: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | eval "$ENVHOOKS_KILL" -------------------------------------------------------------------------------- /plugins/available/envhooks/pause: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | eval "$ENVHOOKS_PAUSE" -------------------------------------------------------------------------------- /plugins/available/envhooks/plugin.toml: -------------------------------------------------------------------------------- 1 | [plugin] 2 | name = "envhooks" 3 | description = "Evaluates hook code from environ variables ENVHOOKS_" 4 | version = "1.0" 5 | maintainer_name = "Jeff Lindsay" 6 | maintainer_email = "progrium@gmail.com" 7 | website_url = "http://github.com/progrium/docker-plugins" 8 | 9 | [plugin.config] 10 | 11 | [plugin.compatibility] 12 | -------------------------------------------------------------------------------- /plugins/available/envhooks/restart: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | eval "$ENVHOOKS_RESTART" -------------------------------------------------------------------------------- /plugins/available/envhooks/start: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | eval "$ENVHOOKS_START" -------------------------------------------------------------------------------- /plugins/available/envhooks/stop: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | eval "$ENVHOOKS_STOP" -------------------------------------------------------------------------------- /plugins/available/envhooks/unpause: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | eval "$ENVHOOKS_UNPAUSE" -------------------------------------------------------------------------------- /plugins/available/timeout/plugin.toml: -------------------------------------------------------------------------------- 1 | [plugin] 2 | name = "timeout" 3 | description = "Kills containers with TIMEOUT set after TIMEOUT seconds" 4 | version = "1.0" 5 | maintainer_name = "Jeff Lindsay" 6 | maintainer_email = "progrium@gmail.com" 7 | website_url = "http://github.com/progrium/docker-plugins" 8 | 9 | [plugin.config] 10 | 11 | [plugin.compatibility] 12 | -------------------------------------------------------------------------------- /plugins/available/timeout/start: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | extract-timeout() { 4 | jq -r ".Config.Env[]" | awk '/TIMEOUT=/{split($0,kv,"="); print kv[2]}' 5 | } 6 | 7 | main() { 8 | declare id="$1" 9 | local timeout="$(cat | extract-timeout)" 10 | if [[ "$timeout" ]]; then 11 | sleep "$timeout" 12 | docker kill "$id" 13 | fi 14 | } 15 | 16 | main "$@" -------------------------------------------------------------------------------- /plugins/available/webhooks/_post: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | main() { 4 | declare event="$1" url="$2" 5 | if [[ "$url" ]]; then 6 | cat | curl -s -X POST -d @- -H "Content-Type: application/json" "$url?event=$event" > /dev/null 7 | fi 8 | } 9 | 10 | main "$@" -------------------------------------------------------------------------------- /plugins/available/webhooks/create: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat | $(dirname $BASH_SOURCE)/_post create "${WEBHOOKS_CREATE_URL:-$WEBHOOKS_URL}" -------------------------------------------------------------------------------- /plugins/available/webhooks/destroy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat | $(dirname $BASH_SOURCE)/_post destroy "${WEBHOOKS_DESTROY_URL:-$WEBHOOKS_URL}" -------------------------------------------------------------------------------- /plugins/available/webhooks/die: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat | $(dirname $BASH_SOURCE)/_post die "${WEBHOOKS_DIE_URL:-$WEBHOOKS_URL}" -------------------------------------------------------------------------------- /plugins/available/webhooks/exists: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat | $(dirname $BASH_SOURCE)/_post exists "${WEBHOOKS_EXISTS_URL:-$WEBHOOKS_URL}" -------------------------------------------------------------------------------- /plugins/available/webhooks/export: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat | $(dirname $BASH_SOURCE)/_post export "${WEBHOOKS_EXPORT_URL:-$WEBHOOKS_URL}" -------------------------------------------------------------------------------- /plugins/available/webhooks/kill: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat | $(dirname $BASH_SOURCE)/_post kill "${WEBHOOKS_KILL_URL:-$WEBHOOKS_URL}" -------------------------------------------------------------------------------- /plugins/available/webhooks/pause: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat | $(dirname $BASH_SOURCE)/_post pause "${WEBHOOKS_PAUSE_URL:-$WEBHOOKS_URL}" -------------------------------------------------------------------------------- /plugins/available/webhooks/plugin.toml: -------------------------------------------------------------------------------- 1 | [plugin] 2 | name = "webhooks" 3 | description = "Hits WEBHOOKS_URL or WEBHOOKS__URL with a POST for each event" 4 | version = "1.0" 5 | maintainer_name = "Jeff Lindsay" 6 | maintainer_email = "progrium@gmail.com" 7 | website_url = "http://github.com/progrium/docker-plugins" 8 | 9 | [plugin.config] 10 | 11 | [plugin.compatibility] 12 | -------------------------------------------------------------------------------- /plugins/available/webhooks/restart: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat | $(dirname $BASH_SOURCE)/_post restart "${WEBHOOKS_RESTART_URL:-$WEBHOOKS_URL}" -------------------------------------------------------------------------------- /plugins/available/webhooks/start: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat | $(dirname $BASH_SOURCE)/_post start "${WEBHOOKS_START_URL:-$WEBHOOKS_URL}" -------------------------------------------------------------------------------- /plugins/available/webhooks/stop: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat | $(dirname $BASH_SOURCE)/_post stop "${WEBHOOKS_STOP_URL:-$WEBHOOKS_URL}" -------------------------------------------------------------------------------- /plugins/available/webhooks/unpause: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat | $(dirname $BASH_SOURCE)/_post unpause "${WEBHOOKS_UNPAUSE_URL:-$WEBHOOKS_URL}" -------------------------------------------------------------------------------- /plugins/config.toml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/progrium/docker-plugins/58b2b32037de08a4f19f1501f53000c1537150ea/plugins/config.toml -------------------------------------------------------------------------------- /start: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | main() { 4 | mkdir -p "$PLUGIN_PATH/enabled" # until plugn ensures this for us 5 | if [[ "$INSTALL" ]]; then 6 | printf "%s\n" $INSTALL | xargs -L 1 plugn install 7 | printf "%s\n" $INSTALL | xargs -L 1 plugn trigger dependencies 8 | fi 9 | if [[ "$ENABLE" ]]; then 10 | printf "%s\n" $ENABLE | xargs -L 1 plugn enable 11 | fi 12 | echo "Starting docker-plugins with:" 13 | plugn list 14 | if [[ "$DEBUG" ]]; then 15 | dockerhook -d "/bin/plugn trigger" 16 | else 17 | dockerhook "/bin/plugn trigger" 18 | fi 19 | } 20 | 21 | main 22 | --------------------------------------------------------------------------------