-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmakefile
102 lines (81 loc) · 2.63 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
APP_NAME = aerogear-app-metrics
PKG = github.com/aerogear/$(APP_NAME)
TOP_SRC_DIRS = pkg
PACKAGES ?= $(shell sh -c "find $(TOP_SRC_DIRS) -name \\*_test.go \
-exec dirname {} \\; | sort | uniq")
BIN_DIR := $(GOPATH)/bin
SHELL = /bin/bash
BINARY ?= aerogear-app-metrics
# This follows the output format for goreleaser
BINARY_LINUX_64 = ./dist/linux_amd64/aerogear-app-metrics
DOCKER_LATEST_TAG = aerogear/$(APP_NAME):latest
DOCKER_MASTER_TAG = aerogear/$(APP_NAME):master
RELEASE_TAG ?= $(CIRCLE_TAG)
DOCKER_RELEASE_TAG = aerogear/$(APP_NAME):$(RELEASE_TAG)
LDFLAGS=-ldflags "-w -s -X main.Version=${TAG}"
.PHONY: setup
setup:
dep ensure
.PHONY: build
build: setup
go build -o $(BINARY) ./cmd/metrics-api/metrics-api.go
.PHONY: build_linux
build_linux: setup
env GOOS=linux GOARCH=amd64 go build -o $(BINARY_LINUX_64) ./cmd/metrics-api/metrics-api.go
.PHONY: docker_build
docker_build: build_linux
docker build -t $(DOCKER_LATEST_TAG) --build-arg BINARY=$(BINARY_LINUX_64) .
.PHONY: docker_build_release
docker_build_release:
docker build -t $(DOCKER_LATEST_TAG) -t $(DOCKER_RELEASE_TAG) --build-arg BINARY=$(BINARY_LINUX_64) .
.PHONY: docker_build_master
docker_build_master:
docker build -t $(DOCKER_MASTER_TAG) --build-arg BINARY=$(BINARY_LINUX_64) .
.PHONY: test
test: test-unit
.PHONY: test-unit
test-unit:
@echo Running tests:
GOCACHE=off go test -cover \
$(addprefix $(PKG)/,$(PACKAGES))
.PHONY: test-integration
test-integration:
@echo Running tests:
GOCACHE=off go test -failfast -cover -tags=integration \
$(addprefix $(PKG)/,$(PACKAGES))
.PHONY: test-integration-cover
test-integration-cover:
echo "mode: count" > coverage-all.out
GOCACHE=off $(foreach pkg,$(PACKAGES),\
go test -failfast -tags=integration -coverprofile=coverage.out -covermode=count $(addprefix $(PKG)/,$(pkg)) || exit 1;\
tail -n +2 coverage.out >> coverage-all.out;)
.PHONY: errcheck
errcheck:
@echo errcheck
@errcheck -ignoretests $$(go list ./...)
.PHONY: vet
vet:
@echo go vet
@go vet $$(go list ./...)
.PHONY: fmt
fmt:
@echo go fmt
diff -u <(echo -n) <(gofmt -d `find . -type f -name '*.go' -not -path "./vendor/*"`)
.PHONY: clean
clean:
-rm -f ${BINARY}
.PHONY: release
release: setup
goreleaser --rm-dist
.PHONY: docker_push_release
docker_push_release:
@docker login --username $(DOCKERHUB_USERNAME) --password $(DOCKERHUB_PASSWORD)
docker push $(DOCKER_LATEST_TAG)
docker push $(DOCKER_RELEASE_TAG)
.PHONY: docker_push_master
docker_push_master:
@docker login -u $(DOCKERHUB_USERNAME) -p $(DOCKERHUB_PASSWORD)
docker push $(DOCKER_MASTER_TAG)
.PHONY: generate
generate:
go generate ./cmd/metrics-api/metrics-api.go