-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
107 lines (87 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
files := $(shell find . -path ./vendor -prune -path ./pb -prune -o -name '*.go' -print)
pkgs := $(shell go list ./... | grep -v /vendor/ )
git_rev := $(shell git rev-parse --short HEAD)
git_tag := $(shell git tag --points-at=$(git_rev))
release_date := $(shell date +%d-%m-%y)
latest_git_tag := $(shell git for-each-ref --format="%(tag)" --sort=-taggerdate refs/tags | head -1)
latest_git_rev := $(shell git rev-list --abbrev-commit -n 1 $(latest_git_tag))
version := $(if $(git_tag),$(git_tag),dev-$(git_rev))
build_time := $(shell date -u)
ldflags := -X "github.com/sky-uk/osprey/v2/cmd.version=$(version)" -X "github.com/sky-uk/osprey/v2/cmd.buildTime=$(build_time)"
cwd= $(shell pwd)
build_dir := $(cwd)/build/bin
dist_dir := $(cwd)/dist
# Define cross compiling targets
os := $(shell uname)
ifeq ("$(os)", "Linux")
target_os = linux
else ifeq ("$(os)", "Darwin")
target_os = darwin
endif
.PHONY: all build check check-format check-os clean docker format install lint proto release-docker setup test vet
all : check install test
check : check-os check-format vet lint test
travis : clean setup check build test docker
check-os:
ifndef target_os
$(error Unsupported platform: ${os})
endif
setup:
@echo "== setup"
go install golang.org/x/lint/golint@latest
go install golang.org/x/tools/cmd/goimports@latest
go mod download
format :
@echo "== format"
@goimports -w $(files)
@sync
clean :
@echo "== clean"
rm -rf build
rm -rf dist
build :
@echo "== build"
GOOS=${target_os} GOARCH=amd64 go build -ldflags '-s $(ldflags)' -o ${build_dir}/${target_os}_amd64/osprey -v
install :
@echo "== install"
@echo "Installing binary for ${target_os}"
GOOS=${target_os} GOARCH=amd64 go install -ldflags '$(ldflags)' -v
unformatted = $(shell goimports -l $(files))
check-format :
@echo "== check formatting"
@if [ "`goimports -l $(files)`" != "" ]; then \
echo "code needs formatting. Run make format"; \
exit 1; \
fi;
vet :
@echo "== vet"
@go vet $(pkgs)
lint :
@echo "== lint"
@for pkg in $(pkgs); do \
golint -set_exit_status $$pkg || exit 1 ; \
done;
test :
@echo "== run tests"
go test -v -race $(pkgs)
proto :
@echo "== compiling proto files"
@docker run -v `pwd`/common/pb:/pb -w / grpc/go:1.0 protoc -I /pb /pb/osprey.proto --go_out=plugins=grpc:pb
image := skycirrus/osprey
docker : build
@echo "== docker"
docker build -t $(image):latest .
release-docker : docker
ifeq ($(strip $(git_tag)),)
@echo "no tag on $(git_rev), skipping docker release"
else
@echo "== release docker"
@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)
@if [ "$(git_rev)" = "$(latest_git_rev)" ]; then \
echo "updating latest image"; \
echo docker push $(image):latest ; \
fi;
endif