github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/libnetwork/Makefile (about) 1 .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 2 SHELL=/bin/bash 3 4 dockerbuildargs ?= --target dev - < Dockerfile 5 dockerargs ?= --privileged -v $(shell pwd):/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork 6 build_image=libnetworkbuild 7 container_env = -e "INSIDECONTAINER=-incontainer=true" 8 docker = docker run --rm -it --init ${dockerargs} $$EXTRA_ARGS ${container_env} ${build_image} 9 10 CROSS_PLATFORMS = linux/amd64 linux/386 linux/arm windows/amd64 11 PACKAGES=$(shell go list ./... | grep -v /vendor/) 12 PROTOC_FLAGS=-I=. -I=/go/src -I=/go/src/github.com/gogo/protobuf -I=/go/src/github.com/gogo/protobuf/protobuf 13 14 export PATH := $(CURDIR)/bin:$(PATH) 15 16 17 # Several targets in this Makefile expect to run within the 18 # libnetworkbuild container. In general, a target named '<target>-local' 19 # relies on utilities inside the build container. Usually there is also 20 # a wrapper called '<target>' which starts a container and runs 21 # 'make <target>-local' inside it. 22 23 ########################################################################### 24 # Top level targets 25 ########################################################################### 26 27 all: build check clean 28 29 all-local: build-local check-local clean 30 31 32 ########################################################################### 33 # Build targets 34 ########################################################################### 35 36 # builder builds the libnetworkbuild container. All wrapper targets 37 # must depend on this to ensure that the container exists. 38 builder: 39 DOCKER_BUILDKIT=1 docker build --progress=plain -t ${build_image} --build-arg=GO_VERSION ${dockerbuildargs} 40 41 build: builder 42 @echo "🐳 $@" 43 @${docker} make build-local 44 45 build-local: 46 @echo "🐳 $@" 47 @mkdir -p "bin" 48 GO111MODULE=off go build -tags experimental -o "bin/dnet" ./cmd/dnet 49 GO111MODULE=off go build -o "bin/docker-proxy" ./cmd/proxy 50 CGO_ENABLED=0 go build -o "bin/diagnosticClient" ./cmd/diagnostic 51 CGO_ENABLED=0 go build -o "bin/testMain" ./cmd/networkdb-test/testMain.go 52 53 build-images: 54 @echo "🐳 $@" 55 cp cmd/diagnostic/daemon.json ./bin 56 DOCKER_BUILDKIT=1 docker build --progress=plain -f cmd/diagnostic/Dockerfile.client -t dockereng/network-diagnostic:onlyclient bin/ 57 DOCKER_BUILDKIT=1 docker build --progress=plain -f cmd/diagnostic/Dockerfile.dind -t dockereng/network-diagnostic:17.12-dind bin/ 58 DOCKER_BUILDKIT=1 docker build --progress=plain -f cmd/networkdb-test/Dockerfile -t dockereng/e2e-networkdb:master bin/ 59 DOCKER_BUILDKIT=1 docker build --progress=plain -t dockereng/network-diagnostic:support.sh support/ 60 61 push-images: build-images 62 @echo "🐳 $@" 63 docker push dockereng/network-diagnostic:onlyclient 64 docker push dockereng/network-diagnostic:17.12-dind 65 docker push dockereng/e2e-networkdb:master 66 docker push dockereng/network-diagnostic:support.sh 67 68 clean: 69 @echo "🐳 $@" 70 @if [ -d bin ]; then \ 71 echo "Removing binaries"; \ 72 rm -rf bin; \ 73 fi 74 75 cross: builder 76 @mkdir -p "bin" 77 @for platform in ${CROSS_PLATFORMS}; do \ 78 EXTRA_ARGS="-e GOOS=$${platform%/*} -e GOARCH=$${platform##*/}" ; \ 79 echo "$${platform}..." ; \ 80 ${docker} make cross-local ; \ 81 done 82 83 cross-local: 84 @echo "🐳 $@" 85 GO111MODULE=off go build -o "bin/dnet-$$GOOS-$$GOARCH" ./cmd/dnet 86 GO111MODULE=off go build -o "bin/docker-proxy-$$GOOS-$$GOARCH" ./cmd/proxy 87 88 # Rebuild protocol buffers. 89 # These may need to be rebuilt after vendoring updates, so .proto files are declared .PHONY so they are always rebuilt. 90 PROTO_FILES=$(shell find . -path ./vendor -prune -o -name \*.proto -print) 91 PB_FILES=$(PROTO_FILES:.proto=.pb.go) 92 93 # Pattern rule for protoc. If PROTOC_CHECK is defined, it checks 94 # whether the generated files are up to date and fails if they are not 95 %.pb.go: %.proto 96 @if [ ${PROTOC_CHECK} ]; then \ 97 protoc ${PROTOC_FLAGS} --gogo_out=/tmp $< ; \ 98 diff -q $@ /tmp/$@ >/dev/null || (echo "👹 $@ is out of date; please run 'make protobuf' and check in updates" && exit 1) ; \ 99 else \ 100 protoc ${PROTOC_FLAGS} --gogo_out=./ $< ; \ 101 fi 102 103 .PHONY: $(PROTO_FILES) 104 protobuf: builder 105 @${docker} make protobuf-local 106 protobuf-local: $(PB_FILES) 107 108 109 ########################################################################### 110 # Test targets 111 ########################################################################### 112 113 check: builder 114 @${docker} make check-local 115 116 check-local: check-code check-format 117 118 check-code: check-protobuf lint vet ineffassign 119 120 check-format: fmt misspell 121 122 unit-tests: builder 123 ${docker} make unit-tests-local 124 125 unit-tests-local: 126 @echo "🐳 Running tests... " 127 @echo "mode: count" > coverage.coverprofile 128 @GO111MODULE=off go build -o "bin/docker-proxy" ./cmd/proxy 129 @for dir in $$( find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -not -path './vendor/*' -type d); do \ 130 if ls $$dir/*.go &> /dev/null; then \ 131 pushd . &> /dev/null ; \ 132 cd $$dir ; \ 133 go test ${INSIDECONTAINER} -test.parallel 5 -test.v -covermode=count -coverprofile=./profile.tmp ; \ 134 ret=$$? ;\ 135 if [ $$ret -ne 0 ]; then exit $$ret; fi ;\ 136 popd &> /dev/null; \ 137 if [ -f $$dir/profile.tmp ]; then \ 138 cat $$dir/profile.tmp | tail -n +2 >> coverage.coverprofile ; \ 139 rm $$dir/profile.tmp ; \ 140 fi ; \ 141 fi ; \ 142 done 143 @echo "Done running tests" 144 145 # Depends on binaries because vet will silently fail if it can not load compiled imports 146 vet: ## run go vet 147 @echo "🐳 $@" 148 @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)" 149 150 misspell: 151 @echo "🐳 $@" 152 @test -z "$$(find . -type f | grep -v vendor/ | grep "\.go\|\.md" | xargs misspell -error | tee /dev/stderr)" 153 154 fmt: ## run go fmt 155 @echo "🐳 $@" 156 @test -z "$$(gofmt -s -l . | grep -v vendor/ | grep -v ".pb.go$$" | tee /dev/stderr)" || \ 157 (echo "👹 please format Go code with 'gofmt -s -w'" && false) 158 159 lint: ## run go lint 160 @echo "🐳 $@" 161 @test -z "$$(golint ./... | grep -v vendor/ | grep -v ".pb.go:" | grep -v ".mock.go" | tee /dev/stderr)" 162 163 ineffassign: ## run ineffassign 164 @echo "🐳 $@" 165 @test -z "$$(ineffassign . | grep -v vendor/ | grep -v ".pb.go:" | grep -v ".mock.go" | tee /dev/stderr)" 166 167 # check-protobuf rebuilds .pb.go files and fails if they have changed 168 check-protobuf: PROTOC_CHECK=1 169 check-protobuf: $(PB_FILES) 170 @echo "🐳 $@" 171 172 173 ########################################################################### 174 # Utility targets 175 ########################################################################### 176 177 shell: builder 178 @${docker} ${SHELL}