forked from docker-archive/deploykit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
130 lines (104 loc) · 3.86 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Set an output prefix, which is the local directory if not specified
PREFIX?=$(shell pwd -L)
# Used to populate version variable in main package.
VERSION?=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
REVISION?=$(shell git rev-list -1 HEAD)
# Allow turning off function inlining and variable registerization
ifeq (${DISABLE_OPTIMIZATION},true)
GO_GCFLAGS=-gcflags "-N -l"
VERSION:="$(VERSION)-noopt"
endif
.PHONY: clean all fmt vet lint build test vendor-update containers check-docs tutorial-test get-tools
.DEFAULT: all
all: clean fmt vet lint build test binaries
ci: fmt vet lint check-docs coverage tutorial-test
AUTHORS: .mailmap .git/HEAD
git log --format='%aN <%aE>' | sort -fu > $@
# Package list
PKGS_AND_MOCKS := $(shell go list ./... | grep -v /vendor)
PKGS := $(shell echo $(PKGS_AND_MOCKS) | tr ' ' '\n' | grep -v /mock$)
# Current working environment. Set these explicitly if you want to cross-compile
# in the build container (see the build-in-container target):
GOOS?=$(shell go env GOOS)
GOARCH?=$(shell go env GOARCH)
build-in-container: clean
@echo "+ $@"
@docker build -t infrakit-build -f ${CURDIR}/dockerfiles/Dockerfile.build .
@docker run --rm \
-e GOOS=${GOOS} -e GOARCCH=${GOARCH} \
-v ${CURDIR}/build:/go/src/github.com/docker/infrakit/build \
infrakit-build
get-tools:
@echo "+ $@"
@go get -u \
github.com/golang/lint/golint \
github.com/wfarner/blockcheck
vet:
@echo "+ $@"
@go vet $(PKGS)
fmt:
@echo "+ $@"
@test -z "$$(gofmt -s -l . 2>&1 | grep -v ^vendor/ | tee /dev/stderr)" || \
(echo >&2 "+ please format Go code with 'gofmt -s', or use 'make fmt-save'" && false)
fmt-save:
@echo "+ $@"
@gofmt -s -l . 2>&1 | grep -v ^vendor/ | xargs gofmt -s -l -w
lint:
@echo "+ $@"
$(if $(shell which golint || echo ''), , \
$(error Please install golint: `make get-tools`))
@test -z "$$(golint ./... 2>&1 | grep -v ^vendor/ | grep -v mock/ | tee /dev/stderr)"
check-docs:
@echo "+ $@"
find . -name '*.md' | grep -v vendor/ | blockcheck
./scripts/doc-source-check
build:
@echo "+ $@"
@go build ${GO_LDFLAGS} $(PKGS)
clean:
@echo "+ $@"
rm -rf build
mkdir -p build
define build_binary
go build -o build/$(1) \
-ldflags "-X github.com/docker/infrakit/cli.Version=$(VERSION) -X github.com/docker/infrakit/cli.Revision=$(REVISION)" $(2)
endef
binaries: clean build-binaries
build-binaries:
@echo "+ $@"
ifneq (,$(findstring .m,$(VERSION)))
@echo "\nWARNING - repository contains uncommitted changes, tagging binaries as dirty\n"
endif
$(call build_binary,infrakit,github.com/docker/infrakit/cmd/cli)
$(call build_binary,infrakit-manager,github.com/docker/infrakit/cmd/manager)
$(call build_binary,infrakit-group-default,github.com/docker/infrakit/cmd/group)
$(call build_binary,infrakit-flavor-combo,github.com/docker/infrakit/pkg/example/flavor/combo)
$(call build_binary,infrakit-flavor-swarm,github.com/docker/infrakit/pkg/example/flavor/swarm)
$(call build_binary,infrakit-flavor-vanilla,github.com/docker/infrakit/pkg/example/flavor/vanilla)
$(call build_binary,infrakit-flavor-zookeeper,github.com/docker/infrakit/pkg/example/flavor/zookeeper)
$(call build_binary,infrakit-instance-file,github.com/docker/infrakit/pkg/example/instance/file)
$(call build_binary,infrakit-instance-terraform,github.com/docker/infrakit/pkg/example/instance/terraform)
$(call build_binary,infrakit-instance-vagrant,github.com/docker/infrakit/pkg/example/instance/vagrant)
install:
@echo "+ $@"
@go install ${GO_LDFLAGS} $(PKGS)
generate:
@echo "+ $@"
@go generate -x $(PKGS_AND_MOCKS)
test:
@echo "+ $@"
@go test -test.short -timeout 30s -race -v $(PKGS)
coverage:
@echo "+ $@"
@for pkg in $(PKGS); do \
go test -test.short -race -coverprofile="../../../$$pkg/coverage.txt" $${pkg} || exit 1; \
done
tutorial-test:
@echo "+ $@"
./scripts/tutorial-test
test-full:
@echo "+ $@"
@go test -race $(PKGS)
vendor-update:
@echo "+ $@"
@trash -u