2019-05-31 16:52:43 -04:00
.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
2015-04-16 15:00:36 -04:00
SHELL = /bin/bash
2018-07-03 10:51:42 -04:00
2018-06-19 20:19:16 -04:00
dockerbuildargs ?= --target dev - < Dockerfile
2018-05-29 16:53:19 -04:00
dockerargs ?= --privileged -v $( shell pwd ) :/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork
2015-10-16 14:33:08 -04:00
build_image = libnetworkbuild
2015-05-12 19:39:30 -04:00
container_env = -e "INSIDECONTAINER=-incontainer=true"
2018-07-10 05:20:44 -04:00
docker = docker run --rm -it --init ${ dockerargs } $$ EXTRA_ARGS ${ container_env } ${ build_image }
2018-07-03 10:51:42 -04:00
2016-04-21 14:20:01 -04:00
CROSS_PLATFORMS = linux/amd64 linux/386 linux/arm windows/amd64
2017-05-24 01:31:58 -04:00
PACKAGES = $( shell go list ./... | grep -v /vendor/)
2018-07-03 05:37:56 -04:00
PROTOC_FLAGS = -I= . -I= /go/src -I= /go/src/github.com/gogo/protobuf -I= /go/src/github.com/gogo/protobuf/protobuf
2018-07-03 10:51:42 -04:00
2016-06-09 07:31:24 -04:00
export PATH := $( CURDIR) /bin:$( PATH)
2015-03-24 14:52:38 -04:00
2018-07-03 10:51:42 -04:00
# 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
###########################################################################
2018-06-16 13:50:38 -04:00
all : build check clean
2015-05-20 15:28:58 -04:00
2018-05-29 16:53:19 -04:00
all-local : build -local check -local clean
2015-05-20 15:28:58 -04:00
2018-07-03 10:51:42 -04:00
###########################################################################
# Build targets
###########################################################################
# builder builds the libnetworkbuild container. All wrapper targets
# must depend on this to ensure that the container exists.
2018-05-29 16:53:19 -04:00
builder :
2019-07-18 05:01:07 -04:00
docker build -t ${ build_image } --build-arg= GO_VERSION ${ dockerbuildargs }
2016-01-05 18:55:27 -05:00
2018-05-29 16:53:19 -04:00
build : builder
2017-05-24 01:31:58 -04:00
@echo " 🐳 $@ "
2018-05-29 16:53:19 -04:00
@${ docker } make build-local
2015-03-24 14:52:38 -04:00
build-local :
2017-05-24 01:31:58 -04:00
@echo " 🐳 $@ "
2015-05-20 15:28:58 -04:00
@mkdir -p "bin"
2017-01-11 03:21:56 -05:00
go build -tags experimental -o "bin/dnet" ./cmd/dnet
go build -o "bin/docker-proxy" ./cmd/proxy
2018-05-24 18:22:58 -04:00
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 build -f cmd/diagnostic/Dockerfile.client -t dockereng/network-diagnostic:onlyclient bin/
docker build -f cmd/diagnostic/Dockerfile.dind -t dockereng/network-diagnostic:17.12-dind bin/
2018-07-06 13:15:00 -04:00
docker build -f cmd/networkdb-test/Dockerfile -t dockereng/e2e-networkdb:master bin/
2018-06-20 15:57:08 -04:00
docker build -t dockereng/network-diagnostic:support.sh support/
2018-05-24 18:22:58 -04:00
push-images : build -images
@echo " 🐳 $@ "
docker push dockereng/network-diagnostic:onlyclient
docker push dockereng/network-diagnostic:17.12-dind
2018-07-06 13:15:00 -04:00
docker push dockereng/e2e-networkdb:master
2018-06-20 15:57:08 -04:00
docker push dockereng/network-diagnostic:support.sh
2015-05-20 15:28:58 -04:00
clean :
2017-05-24 01:31:58 -04:00
@echo " 🐳 $@ "
2015-05-20 15:28:58 -04:00
@if [ -d bin ] ; then \
2018-06-16 13:50:38 -04:00
echo "Removing binaries" ; \
2015-05-20 15:28:58 -04:00
rm -rf bin; \
fi
2018-05-29 16:53:19 -04:00
cross : builder
2015-05-20 15:28:58 -04:00
@mkdir -p "bin"
@for platform in ${ CROSS_PLATFORMS } ; do \
2016-01-05 18:55:27 -05:00
EXTRA_ARGS = " -e GOOS= $$ {platform%/*} -e GOARCH= $$ {platform##*/} " ; \
2015-05-20 15:28:58 -04:00
echo " $$ {platform}... " ; \
2016-01-05 18:55:27 -05:00
${ docker } make cross-local ; \
2015-05-20 15:28:58 -04:00
done
cross-local :
2017-05-24 01:31:58 -04:00
@echo " 🐳 $@ "
2017-01-11 03:21:56 -05:00
go build -o " bin/dnet- $$ GOOS- $$ GOARCH " ./cmd/dnet
go build -o " bin/docker-proxy- $$ GOOS- $$ GOARCH " ./cmd/proxy
2015-03-24 14:52:38 -04:00
2018-07-03 10:51:42 -04:00
# 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)
2018-07-03 10:59:12 -04:00
# 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
2018-07-03 10:51:42 -04:00
%.pb.go : %.proto
2018-07-11 19:44:40 -04:00
@if [ ${ PROTOC_CHECK } ] ; then \
2018-07-03 10:59:12 -04:00
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
2018-07-03 10:51:42 -04:00
.PHONY : $( PROTO_FILES )
2018-07-03 05:37:56 -04:00
protobuf : builder
@${ docker } make protobuf-local
protobuf-local : $( PB_FILES )
2018-07-03 10:51:42 -04:00
###########################################################################
# Test targets
###########################################################################
2018-05-29 16:53:19 -04:00
check : builder
@${ docker } make check-local
2018-06-16 13:50:38 -04:00
check-local : check -code check -format
2015-03-24 14:52:38 -04:00
2019-05-31 16:52:43 -04:00
check-code : check -protobuf lint vet ineffassign
2015-03-24 14:52:38 -04:00
2017-05-24 01:31:58 -04:00
check-format : fmt misspell
2015-03-24 14:52:38 -04:00
2018-05-29 16:53:19 -04:00
unit-tests : builder
${ docker } make unit-tests-local
unit-tests-local :
2017-05-24 01:31:58 -04:00
@echo "🐳 Running tests... "
2015-04-16 15:00:36 -04:00
@echo "mode: count" > coverage.coverprofile
2018-05-29 16:53:19 -04:00
@go build -o "bin/docker-proxy" ./cmd/proxy
2017-10-25 09:33:06 -04:00
@for dir in $$ ( find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -not -path './vendor/*' -type d) ; do \
if ls $$ dir/*.go & > /dev/null; then \
2015-05-12 19:39:30 -04:00
pushd . & > /dev/null ; \
cd $$ dir ; \
2018-06-16 13:50:38 -04:00
go test ${ INSIDECONTAINER } -test.parallel 5 -test.v -covermode= count -coverprofile= ./profile.tmp ; \
2015-05-19 13:19:50 -04:00
ret = $$ ? ; \
if [ $$ ret -ne 0 ] ; then exit $$ ret; fi ; \
2015-05-12 19:39:30 -04:00
popd & > /dev/null; \
2015-09-02 00:48:09 -04:00
if [ -f $$ dir/profile.tmp ] ; then \
2017-10-25 09:33:06 -04:00
cat $$ dir/profile.tmp | tail -n +2 >> coverage.coverprofile ; \
2015-04-14 08:13:34 -04:00
rm $$ dir/profile.tmp ; \
2015-09-02 00:48:09 -04:00
fi ; \
fi ; \
2015-04-14 08:13:34 -04:00
done
2015-04-16 15:00:36 -04:00
@echo "Done running tests"
2015-03-24 14:52:38 -04:00
2017-05-24 01:31:58 -04:00
# 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 " 🐳 $@ "
2018-06-16 13:50:38 -04:00
@test -z " $$ (find . -type f | grep -v vendor/ | grep " \. go\| \. md" | xargs misspell -error | tee /dev/stderr)"
2017-05-24 01:31:58 -04:00
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)"
2018-07-03 10:59:12 -04:00
# check-protobuf rebuilds .pb.go files and fails if they have changed
check-protobuf : PROTOC_CHECK =1
check-protobuf : $( PB_FILES )
@echo " 🐳 $@ "
2018-06-20 12:20:49 -04:00
2018-07-03 10:51:42 -04:00
###########################################################################
# Utility targets
###########################################################################
2018-06-20 12:20:49 -04:00
2018-07-03 10:51:42 -04:00
shell : builder
@${ docker } ${ SHELL }