-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from int128/golang
Move to Golang
- Loading branch information
Showing
20 changed files
with
547 additions
and
983 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ./... |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} |
Oops, something went wrong.