-
Notifications
You must be signed in to change notification settings - Fork 881
/
Makefile
178 lines (140 loc) Β· 6.48 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
.PHONY: all all-local build build-local clean cross cross-local vet lint misspell check check-local check-code check-format unit-tests protobuf protobuf-local check-protobuf
SHELL=/bin/bash
dockerbuildargs ?= --target dev - < Dockerfile
dockerargs ?= --privileged -v $(shell pwd):/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork
build_image=libnetworkbuild
container_env = -e "INSIDECONTAINER=-incontainer=true"
docker = docker run --rm -it --init ${dockerargs} $$EXTRA_ARGS ${container_env} ${build_image}
CROSS_PLATFORMS = linux/amd64 linux/386 linux/arm windows/amd64
PACKAGES=$(shell go list ./... | grep -v /vendor/)
PROTOC_FLAGS=-I=. -I=/go/src -I=/go/src/github.com/gogo/protobuf -I=/go/src/github.com/gogo/protobuf/protobuf
export PATH := $(CURDIR)/bin:$(PATH)
# Several targets in this Makefile expect to run within the
# libnetworkbuild container. In general, a target named '<target>-local'
# relies on utilities inside the build container. Usually there is also
# a wrapper called '<target>' which starts a container and runs
# 'make <target>-local' inside it.
###########################################################################
# Top level targets
###########################################################################
all: build check clean
all-local: build-local check-local clean
###########################################################################
# Build targets
###########################################################################
# builder builds the libnetworkbuild container. All wrapper targets
# must depend on this to ensure that the container exists.
builder:
DOCKER_BUILDKIT=1 docker build --progress=plain -t ${build_image} --build-arg=GO_VERSION ${dockerbuildargs}
build: builder
@echo "π³ $@"
@${docker} make build-local
build-local:
@echo "π³ $@"
@mkdir -p "bin"
GO111MODULE=off go build -tags experimental -o "bin/dnet" ./cmd/dnet
GO111MODULE=off go build -o "bin/docker-proxy" ./cmd/proxy
CGO_ENABLED=0 go build -o "bin/diagnosticClient" ./cmd/diagnostic
CGO_ENABLED=0 go build -o "bin/testMain" ./cmd/networkdb-test/testMain.go
build-images:
@echo "π³ $@"
cp cmd/diagnostic/daemon.json ./bin
DOCKER_BUILDKIT=1 docker build --progress=plain -f cmd/diagnostic/Dockerfile.client -t dockereng/network-diagnostic:onlyclient bin/
DOCKER_BUILDKIT=1 docker build --progress=plain -f cmd/diagnostic/Dockerfile.dind -t dockereng/network-diagnostic:17.12-dind bin/
DOCKER_BUILDKIT=1 docker build --progress=plain -f cmd/networkdb-test/Dockerfile -t dockereng/e2e-networkdb:master bin/
DOCKER_BUILDKIT=1 docker build --progress=plain -t dockereng/network-diagnostic:support.sh support/
push-images: build-images
@echo "π³ $@"
docker push dockereng/network-diagnostic:onlyclient
docker push dockereng/network-diagnostic:17.12-dind
docker push dockereng/e2e-networkdb:master
docker push dockereng/network-diagnostic:support.sh
clean:
@echo "π³ $@"
@if [ -d bin ]; then \
echo "Removing binaries"; \
rm -rf bin; \
fi
cross: builder
@mkdir -p "bin"
@for platform in ${CROSS_PLATFORMS}; do \
EXTRA_ARGS="-e GOOS=$${platform%/*} -e GOARCH=$${platform##*/}" ; \
echo "$${platform}..." ; \
${docker} make cross-local ; \
done
cross-local:
@echo "π³ $@"
GO111MODULE=off go build -o "bin/dnet-$$GOOS-$$GOARCH" ./cmd/dnet
GO111MODULE=off go build -o "bin/docker-proxy-$$GOOS-$$GOARCH" ./cmd/proxy
# Rebuild protocol buffers.
# These may need to be rebuilt after vendoring updates, so .proto files are declared .PHONY so they are always rebuilt.
PROTO_FILES=$(shell find . -path ./vendor -prune -o -name \*.proto -print)
PB_FILES=$(PROTO_FILES:.proto=.pb.go)
# Pattern rule for protoc. If PROTOC_CHECK is defined, it checks
# whether the generated files are up to date and fails if they are not
%.pb.go: %.proto
@if [ ${PROTOC_CHECK} ]; then \
protoc ${PROTOC_FLAGS} --gogo_out=/tmp $< ; \
diff -q $@ /tmp/$@ >/dev/null || (echo "πΉ $@ is out of date; please run 'make protobuf' and check in updates" && exit 1) ; \
else \
protoc ${PROTOC_FLAGS} --gogo_out=./ $< ; \
fi
.PHONY: $(PROTO_FILES)
protobuf: builder
@${docker} make protobuf-local
protobuf-local: $(PB_FILES)
###########################################################################
# Test targets
###########################################################################
check: builder
@${docker} make check-local
check-local: check-code check-format
check-code: check-protobuf lint vet ineffassign
check-format: fmt misspell
unit-tests: builder
${docker} make unit-tests-local
unit-tests-local:
@echo "π³ Running tests... "
@echo "mode: count" > coverage.coverprofile
@GO111MODULE=off go build -o "bin/docker-proxy" ./cmd/proxy
@for dir in $$( find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -not -path './vendor/*' -type d); do \
if ls $$dir/*.go &> /dev/null; then \
pushd . &> /dev/null ; \
cd $$dir ; \
go test ${INSIDECONTAINER} -test.parallel 5 -test.v -covermode=count -coverprofile=./profile.tmp ; \
ret=$$? ;\
if [ $$ret -ne 0 ]; then exit $$ret; fi ;\
popd &> /dev/null; \
if [ -f $$dir/profile.tmp ]; then \
cat $$dir/profile.tmp | tail -n +2 >> coverage.coverprofile ; \
rm $$dir/profile.tmp ; \
fi ; \
fi ; \
done
@echo "Done running tests"
# Depends on binaries because vet will silently fail if it can not load compiled imports
vet: ## run go vet
@echo "π³ $@"
@test -z "$$(go vet ${PACKAGES} 2>&1 | grep -v 'constant [0-9]* not a string in call to Errorf' | egrep -v '(timestamp_test.go|duration_test.go|exit status 1)' | tee /dev/stderr)"
misspell:
@echo "π³ $@"
@test -z "$$(find . -type f | grep -v vendor/ | grep "\.go\|\.md" | xargs misspell -error | tee /dev/stderr)"
fmt: ## run go fmt
@echo "π³ $@"
@test -z "$$(gofmt -s -l . | grep -v vendor/ | grep -v ".pb.go$$" | tee /dev/stderr)" || \
(echo "πΉ please format Go code with 'gofmt -s -w'" && false)
lint: ## run go lint
@echo "π³ $@"
@test -z "$$(golint ./... | grep -v vendor/ | grep -v ".pb.go:" | grep -v ".mock.go" | tee /dev/stderr)"
ineffassign: ## run ineffassign
@echo "π³ $@"
@test -z "$$(ineffassign . | grep -v vendor/ | grep -v ".pb.go:" | grep -v ".mock.go" | tee /dev/stderr)"
# check-protobuf rebuilds .pb.go files and fails if they have changed
check-protobuf: PROTOC_CHECK=1
check-protobuf: $(PB_FILES)
@echo "π³ $@"
###########################################################################
# Utility targets
###########################################################################
shell: builder
@${docker} ${SHELL}