This repository has been archived by the owner on Oct 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
84 lines (69 loc) · 2.25 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
pkgs := $(shell go list ./... | grep -v /types)
prod_pkgs := $(shell go list ./... | grep -v /types | grep -v /e2e)
files := $(shell find . -path ./vendor -prune -path ./types/types.pb.go -prune -o -name '*.go' -print)
git_rev := $(shell git rev-parse --short HEAD)
git_tag := $(shell git tag --points-at=$(git_rev))
image := skycirrus/merlin
build_time := $(shell date -u)
ldflags := -X main.Version=$(if $(git_tag),$(git_tag),dev-$(git_rev)) -X "main.BuildTime=$(build_time)"
.PHONY: all clean format test build-release vet lint checkformat check docker release-docker proto setup
all : install check
check : checkformat vet lint test
travis : check build-release docker
setup :
@echo "== setup"
go get -u golang.org/x/lint/golint
go get -u golang.org/x/tools/cmd/goimports
go get -u github.com/golang/dep/cmd/dep
go get -u github.com/golang/protobuf/protoc-gen-go
dep ensure
format :
@echo "== format"
@goimports -w $(files)
@sync
clean :
@echo "== clean"
rm -rf build
build-release :
@echo "== build-release"
CGO_ENABLED=0 GOOS=linux go build -ldflags '-s $(ldflags)' -a -installsuffix static github.com/sky-uk/merlin/cmd/merlin
CGO_ENABLED=0 GOOS=linux go build -ldflags '-s $(ldflags)' -a -installsuffix static github.com/sky-uk/merlin/cmd/meradm
install :
@echo "== install"
@go install -race -v -ldflags '$(ldflags)' ./cmd/merlin
@go install -v -ldflags '$(ldflags)' ./cmd/meradm
unformatted = $(shell goimports -l $(files))
checkformat :
@echo "== check formatting"
ifneq "$(unformatted)" ""
@echo "needs formatting: $(unformatted)"
@echo "run make format"
@exit 1
endif
vet :
@echo "== vet"
@go vet $(prod_pkgs)
lint :
@echo "== lint"
@for pkg in $(prod_pkgs); do \
golint -set_exit_status $$pkg || exit 1; \
done;
test : install
@echo "== run tests"
@go test -race $(pkgs)
proto :
@echo "== compiling proto files"
protoc --go_out=plugins=grpc:. types/types.proto
docker : build-release
@echo "== build"
docker build -t $(image):latest .
release-docker : docker
@echo "== release"
ifeq ($(strip $(git_tag)),)
@echo "no tag on $(git_rev), skipping release"
else
@echo "releasing $(image):$(git_tag)"
@docker login -u $(DOCKER_USERNAME) -p $(DOCKER_PASSWORD)
docker tag $(image):latest $(image):$(git_tag)
docker push $(image):$(git_tag)
endif