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