forked from atlassian/gostatsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (65 loc) · 2.78 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
VERSION_VAR := main.Version
GIT_VAR := main.GitCommit
BUILD_DATE_VAR := main.BuildDate
REPO_VERSION := $(shell git describe --abbrev=0 --tags)
BUILD_DATE := $(shell date +%Y-%m-%d-%H:%M)
GIT_HASH := $(shell git rev-parse --short HEAD)
GOBUILD_VERSION_ARGS := -ldflags "-s -X $(VERSION_VAR)=$(REPO_VERSION) -X $(GIT_VAR)=$(GIT_HASH) -X $(BUILD_DATE_VAR)=$(BUILD_DATE)"
BINARY_NAME := gostatsd
IMAGE_NAME := jtblin/$(BINARY_NAME)
ARCH ?= darwin
setup:
go get -v -u github.com/githubnemo/CompileDaemon
go get -v -u github.com/alecthomas/gometalinter
gometalinter --install --update
GO15VENDOREXPERIMENT=1 glide install
build: *.go fmt
go build -o build/bin/$(ARCH)/$(BINARY_NAME) $(GOBUILD_VERSION_ARGS) github.com/jtblin/$(BINARY_NAME)
fmt:
gofmt -w=true -s $(shell find . -type f -name '*.go' -not -path "./vendor/*")
goimports -w=true -d $(shell find . -type f -name '*.go' -not -path "./vendor/*")
test:
GO15VENDOREXPERIMENT=1 go test $(shell GO15VENDOREXPERIMENT=1 go list ./... | grep -v /vendor/)
race:
GO15VENDOREXPERIMENT=1 go build -race $(shell GO15VENDOREXPERIMENT=1 go list ./... | grep -v /vendor/)
bench:
GO15VENDOREXPERIMENT=1 go test -bench=. $(shell GO15VENDOREXPERIMENT=1 go list ./... | grep -v /vendor/)
cover:
./cover.sh
junit-test: build
go get github.com/jstemmer/go-junit-report
go test -v $(shell GO15VENDOREXPERIMENT=1 go list ./... | grep -v /vendor/) | go-junit-report > test-report.xml
check:
gometalinter --deadline=60s ./... --vendor --linter="errcheck::-ignore=net:Close" --cyclo-over=20 --linter="vet::--composites=false"
profile:
./build/bin/$(ARCH)/$(BINARY_NAME) --backends=stdout --cpu-profile=./profile.out --flush-interval=1s
go tool pprof build/bin/$(ARCH)/$(BINARY_NAME) profile.out
watch:
CompileDaemon -color=true -build "make test check"
commit-hook:
cp dev/commit-hook.sh .git/hooks/pre-commit
cross:
CGO_ENABLED=0 GOOS=linux go build -o build/bin/linux/$(BINARY_NAME) $(GOBUILD_VERSION_ARGS) -a -installsuffix cgo github.com/jtblin/$(BINARY_NAME)
docker: cross
cd build && docker build -t $(IMAGE_NAME):$(GIT_HASH) .
release: test docker
docker push $(IMAGE_NAME):$(GIT_HASH)
docker tag -f $(IMAGE_NAME):$(GIT_HASH) $(IMAGE_NAME):latest
docker push $(IMAGE_NAME):latest
docker tag -f $(IMAGE_NAME):$(GIT_HASH) $(IMAGE_NAME):$(REPO_VERSION)
docker push $(IMAGE_NAME):$(REPO_VERSION)
run: build
./build/bin/$(ARCH)/$(BINARY_NAME) --backends=stdout --verbose --flush-interval=1s
run-docker: cross
cd build/ && docker-compose rm -f gostatsd
docker-compose -f build/docker-compose.yml build
docker-compose -f build/docker-compose.yml up -d
stop-docker:
cd build/ && docker-compose stop
version:
@echo $(REPO_VERSION)
clean:
rm -f build/bin/*
-docker rm $(docker ps -a -f 'status=exited' -q)
-docker rmi $(docker images -f 'dangling=true' -q)
.PHONY: build