Skip to content

Commit

Permalink
Merge pull request #9 from int128/golang
Browse files Browse the repository at this point in the history
Move to Golang
  • Loading branch information
int128 authored Oct 24, 2018
2 parents 4652448 + d8e1832 commit 4fb591c
Show file tree
Hide file tree
Showing 20 changed files with 547 additions and 983 deletions.
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.11.1
environment:
GO111MODULE: "on"
working_directory: /go/src/github.com/int128/slack-docker
steps:
- checkout
- run: go get -u golang.org/x/lint/golint
- run: golint
- run: go build -v
- run: go test -v ./...
1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
from node:onbuild
FROM golang:1.11.1-alpine AS builder
WORKDIR /go/src/github.com/int128/slack-docker
RUN apk update && apk add --no-cache git gcc musl-dev
ENV GO111MODULE on
COPY . .
RUN go install -v

FROM alpine
RUN apk update && apk add --no-cache ca-certificates
EXPOSE 3000
USER daemon
COPY --from=builder /go/bin/slack-docker /
CMD ["/slack-docker"]
46 changes: 21 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,51 @@
# slack-docker
# slack-docker [![CircleCI](https://circleci.com/gh/int128/slack-docker.svg?style=shield)](https://circleci.com/gh/int128/slack-docker)

A Slack integration to notify Docker events.
A Slack integration to notify [Docker events](https://docs.docker.com/engine/reference/commandline/events/) written in Go.

<img width="623" alt="slack-docker-screenshot" src="https://user-images.githubusercontent.com/321266/32720381-bc847924-c8a6-11e7-8348-fa7e03e82939.png">

## How to Run

Set up [an incoming WebHook integration](https://my.slack.com/services/new/incoming-webhook) and get the Webhook URL.
## Getting Started

Run a container as follows:
Setup [an Incoming WebHook](https://my.slack.com/services/new/incoming-webhook) on your Slack workspace and get the WebHook URL.

Run slack-docker as follows:

```sh
# Standalone
./slack-docker --webhook=https://hooks.slack.com/services/...

# Docker
docker run -d -e webhook=URL -v /var/run/docker.sock:/var/run/docker.sock int128/slack-docker
docker run -d -e webhook=https://hooks.slack.com/services/... -v /var/run/docker.sock:/var/run/docker.sock int128/slack-docker

# Docker Compose
curl -O https://raw.githubusercontent.com/int128/slack-docker/master/docker-compose.yml
docker-compose up -d
```

### Include docker hostname in the messages

If you run standalone docker hosts you'll probably find usefull include the `HOSTNAME` in the
messages posted to slack. Run the container as follows:
## Configuration

```sh
# Docker
docker run --net=host --env include_hostname=1 -d -e webhook=URL -v /var/run/docker.sock:/var/run/docker.sock int128/slack-docker
```
It supports the following options and environment variables:

or set the variable explicitly
```
Application Options:
--webhook= Slack Incoming WebHook URL [$webhook]
--image-regexp= Filter events by image name (default to all) [$image_regexp]
```sh
# Docker
docker run --env HOSTNAME=${HOSTNAME} --env include_hostname=1 -d -e webhook=URL -v /var/run/docker.sock:/var/run/docker.sock int128/slack-docker
Help Options:
-h, --help Show this help message
```


### 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
# show events only from node
-e image_regexp='^node:'

# show events but exclude from node
-e image_regexp='^(?!node:)'
webhook=https://hooks.slack.com/services/... image_regexp='^alpine$' ./slack-docker
```


## Contribution

Please let me know an issue or pull request.
This is an open source software licensed under Apache-2.0.
Feel free to open issues or pull requests.
59 changes: 0 additions & 59 deletions app.js

This file was deleted.

1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ daemon:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- webhook=https://hooks.slack.com/services/...
#- include_hostname=1
15 changes: 15 additions & 0 deletions formatter/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package formatter

import (
"fmt"
"github.com/int128/slack-docker/slack"
)

// Error returns a message for the error.
func Error(err error) *slack.Message {
return &slack.Message{
Username: "docker",
IconEmoji: ":whale:",
Text: fmt.Sprintf("Error while receiving events from Docker server: %s", err),
}
}
Loading

0 comments on commit 4fb591c

Please sign in to comment.