From 4398de084a44bc3508bab9c07d9587ff85bd38d5 Mon Sep 17 00:00:00 2001 From: int128 Date: Tue, 15 Dec 2015 01:13:08 +0900 Subject: [PATCH] Feature #2: filter events by image name --- README.md | 8 ++++++++ app.coffee | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e37cdd4..f25ed15 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,14 @@ curl -O https://raw.githubusercontent.com/int128/slack-docker/master/docker-comp docker-compose up -d ``` +### Filter events by image name + +By default all events are sent to Slack, but events can be filtered by the environment variable `image_regexp` as follows: + +```sh +docker run -d -e image_regexp='node:.*' -e webhook=URL -v /var/run/docker.sock:/var/run/docker.sock int128/slack-docker +``` + ## Contribution diff --git a/app.coffee b/app.coffee index 53a04d3..36f7976 100644 --- a/app.coffee +++ b/app.coffee @@ -26,6 +26,11 @@ Slack = fields: fields .fail (e) -> console.error e +EventFilter = + _imageRegExp: new RegExp(process.env.image_regexp) + satisfy: (event) -> + @_imageRegExp.test event.from + EventProcessor = _containers: {} _start: (event) -> @@ -55,8 +60,8 @@ Docker.getVersion().then (version) -> console.info version Docker.events().then (stream) -> stream.pipe EventStream.map (event) -> - console.info "#{event.time}: #{event.status}: #{event.id} from #{event.from}" - EventProcessor.handle event + if EventFilter.satisfy event + EventProcessor.handle event .fail (e) -> console.error e