Skip to content

Commit

Permalink
Docker autobuild and fix codestyle (#1)
Browse files Browse the repository at this point in the history
* add autobuilding for a docker image

* fix codestyle

* update shields
  • Loading branch information
xjewer authored Sep 28, 2017
1 parent 3f89492 commit 399bddf
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: go

go:
- 1.9.x
- tip

script:
- go test -v -race ./...
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM alpine:3.6

MAINTAINER [email protected]
# builder layer
FROM golang:1.9-alpine as builder
COPY . /go/src/github.com/xjewer/snitch
RUN go build -o /snitch github.com/xjewer/snitch/cmd/snitch

# original image
FROM alpine:3.6
LABEL maintainer="[email protected]"
RUN apk --update add ca-certificates
COPY snitch /

COPY --from=builder /snitch .
ENTRYPOINT ["/snitch"]
CMD ["--help"]
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Snitch

[![Travis](https://img.shields.io/travis/xjewer/snitch.svg)](https://travis-ci.org/xjewer/snitch)
[![Go Report Card](https://goreportcard.com/badge/github.com/xjewer/snitch)](https://goreportcard.com/report/github.com/xjewer/snitch)
[![GitHub release](https://img.shields.io/github/release/xjewer/snitch.svg)](https://github.com/xjewer/snitch/releases)
[![Docker Automated build](https://img.shields.io/docker/automated/xjewer/snitch.svg)](https://hub.docker.com/r/xjewer/snitch/)
[![ImageLayers Layers](https://img.shields.io/imagelayers/layers/xjewer/snitch/latest.svg)](https://hub.docker.com/r/xjewer/snitch/)
[![ImageLayers Size](https://img.shields.io/imagelayers/image-size/xjewer/snitch/latest.svg)](https://hub.docker.com/r/xjewer/snitch/)

This tool allows to parse log files and send statistics to statsd endpoint

### Startup options
Expand Down Expand Up @@ -54,8 +61,10 @@ Snitch allows handle a few sources per instance

### Docker build

Docker build uses [multistage build](https://docs.docker.com/engine/userguide/eng-image/multistage-build/)

```
docker run --rm -v "$(pwd):/src" -v /var/run/docker.sock:/var/run/docker.sock -e MAIN_PATH=cmd/snitch xjewer/golang-builder:v1.9 xjewer/snitch:{tag}
docker build -t xjewer/snitch:{tag} .
```


Expand Down
File renamed without changes.
12 changes: 5 additions & 7 deletions cmd/test/test.go → cmd/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

const (
TestLineOk = "[%s] 200 192.168.1.1:80 200 0.036 https POST /test /test OK hostname"
TestLineError = "[%s] 200 192.168.1.1:80 : 127.0.0.1:8000 504 : 200 0.7 : 0.002 https POST /test /test Error hostname"
testLineOk = "[%s] 200 192.168.1.1:80 200 0.036 https POST /test /test OK hostname"
testLineError = "[%s] 200 192.168.1.1:80 : 127.0.0.1:8000 504 : 200 0.7 : 0.002 https POST /test /test Error hostname"
)

var (
Expand Down Expand Up @@ -56,17 +56,15 @@ func writeToFile() error {
f.Seek(0, 0)
case <-done:
ticker.Stop()
break
return nil
}
}

return nil
}

func getLogLine(f *os.File) {
if rand.Intn(2) == 0 {
fmt.Fprintf(f, TestLineOk+"\n", time.Now().Format("02/Jan/2006:15:04:05 -0700"))
fmt.Fprintf(f, testLineOk+"\n", time.Now().Format("02/Jan/2006:15:04:05 -0700"))
} else {
fmt.Fprintf(f, TestLineError+"\n", time.Now().Format("02/Jan/2006:15:04:05 -0700"))
fmt.Fprintf(f, testLineError+"\n", time.Now().Format("02/Jan/2006:15:04:05 -0700"))
}
}
5 changes: 5 additions & 0 deletions lib/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ const (
)

var (
// ErrConfigFileMissing is a missing config file error
ErrConfigFileMissing = errors.New("config file is missing")
)

// Data is a main config structure
type Data struct {
Sources []Source `yaml:"sources"`
}

// Source describes log parser
type Source struct {
Name string `yaml:"source"`
File string `yaml:"file"`
Expand All @@ -34,13 +37,15 @@ type Source struct {
OffsetFile string `yaml:"offsetFile"`
}

// Key describes statsd keys and their metrics
type Key struct {
Key string `yaml:"key"`
Count bool `yaml:"count"`
Timing string `yaml:"timing"`
Delimiter string `yaml:"delimiter"`
}

// Parse parses config file
func Parse(path string) (*Data, error) {
file, err := ioutil.ReadFile(path)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion lib/simplelog/simplelog.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package simplelog

// Logger interface, log.Logger satisfy this interface
type Logger interface {
Println(...interface{})
Print(...interface{})
Printf(string, ...interface{})
}

type NoopLogger struct {}
// NoopLogger is a no-op Logger implementation
type NoopLogger struct{}

// Println is a no-op Println implementation
func (n *NoopLogger) Println(...interface{}) {}

// Print is a no-op Print implementation
func (n *NoopLogger) Print(...interface{}) {}

// Printf is a no-op Printf implementation
func (n *NoopLogger) Printf(string, ...interface{}) {}

0 comments on commit 399bddf

Please sign in to comment.