From 348ed0a1a8c066762df74bd284299f7caf03c053 Mon Sep 17 00:00:00 2001 From: Euan Harris Date: Wed, 4 Jul 2018 13:42:25 +0100 Subject: [PATCH 1/4] circleci: Rename 'lint' to 'check' to match build target Signed-off-by: Euan Harris --- libnetwork/.circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnetwork/.circleci/config.yml b/libnetwork/.circleci/config.yml index 545fcde303..441592505c 100644 --- a/libnetwork/.circleci/config.yml +++ b/libnetwork/.circleci/config.yml @@ -30,7 +30,7 @@ jobs: exclusive: false - run: make build - lint: + check: <<: *defaults steps: - checkout @@ -68,7 +68,7 @@ workflows: - build: requires: - builder - - lint: + - check: requires: - builder - cross: From 3bebfbc34e6fef8d2ea1945da5b67c2a074a6114 Mon Sep 17 00:00:00 2001 From: Euan Harris Date: Tue, 3 Jul 2018 15:51:42 +0100 Subject: [PATCH 2/4] Makefile: Document and organize into sections Add documentation and move protobuf target into Build section Signed-off-by: Euan Harris --- libnetwork/Makefile | 55 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/libnetwork/Makefile b/libnetwork/Makefile index 7aa5dfe44a..694bc45ed5 100644 --- a/libnetwork/Makefile +++ b/libnetwork/Makefile @@ -1,18 +1,39 @@ -.PHONY: all all-local build build-local clean cross cross-local gosimple vet lint misspell check check-local check-code check-format unit-tests +.PHONY: all all-local build build-local clean cross cross-local gosimple vet lint misspell check check-local check-code check-format unit-tests 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/) + export PATH := $(CURDIR)/bin:$(PATH) + +# Several targets in this Makefile expect to run within the +# libnetworkbuild container. In general, a target named '-local' +# relies on utilities inside the build container. Usually there is also +# a wrapper called '' which starts a container and runs +# 'make -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 build -t ${build_image} ${dockerbuildargs} @@ -63,6 +84,22 @@ cross-local: go build -o "bin/dnet-$$GOOS-$$GOARCH" ./cmd/dnet 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) + +%.pb.go: %.proto + ${docker} protoc -I=. -I=/go/src -I=/go/src/github.com/gogo/protobuf -I=/go/src/github.com/gogo/protobuf/protobuf --gogo_out=./ $< + +.PHONY: $(PROTO_FILES) +protobuf: builder $(PB_FILES) + + +########################################################################### +# Test targets +########################################################################### + check: builder @${docker} make check-local @@ -121,16 +158,10 @@ gosimple: ## run gosimple @echo "🐳 $@" @test -z "$$(gosimple . | grep -v vendor/ | grep -v ".pb.go:" | grep -v ".mock.go" | tee /dev/stderr)" + +########################################################################### +# Utility targets +########################################################################### + shell: builder @${docker} ${SHELL} - -# Rebuild protocol buffers. -# These may need to be rebuilt after vendoring updates, so .pb.go 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) - -%.pb.go: %.proto - ${docker} protoc -I=. -I=/go/src -I=/go/src/github.com/gogo/protobuf -I=/go/src/github.com/gogo/protobuf/protobuf --gogo_out=./ $< - -.PHONY: protobuf $(PROTO_FILES) -protobuf: builder $(PB_FILES) From 2b602bf3d02c46930223d53d421c441111073907 Mon Sep 17 00:00:00 2001 From: Euan Harris Date: Tue, 3 Jul 2018 10:37:56 +0100 Subject: [PATCH 3/4] Makefile: Add protobuf-local target, runnable within build container Outside the build container, run: make protobuf Inside the build container, run: make protobuf-local Signed-off-by: Euan Harris --- libnetwork/Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libnetwork/Makefile b/libnetwork/Makefile index 694bc45ed5..db1a9c2d03 100644 --- a/libnetwork/Makefile +++ b/libnetwork/Makefile @@ -1,4 +1,4 @@ -.PHONY: all all-local build build-local clean cross cross-local gosimple vet lint misspell check check-local check-code check-format unit-tests protobuf +.PHONY: all all-local build build-local clean cross cross-local gosimple vet lint misspell check check-local check-code check-format unit-tests protobuf protobuf-local SHELL=/bin/bash dockerbuildargs ?= --target dev - < Dockerfile @@ -9,6 +9,7 @@ docker = docker run --rm -it --init ${dockerargs} $$EXTRA_ARGS ${container_env} 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) @@ -90,10 +91,12 @@ PROTO_FILES=$(shell find . -path ./vendor -prune -o -name \*.proto -print) PB_FILES=$(PROTO_FILES:.proto=.pb.go) %.pb.go: %.proto - ${docker} protoc -I=. -I=/go/src -I=/go/src/github.com/gogo/protobuf -I=/go/src/github.com/gogo/protobuf/protobuf --gogo_out=./ $< + protoc ${PROTOC_FLAGS} --gogo_out=./ $< .PHONY: $(PROTO_FILES) -protobuf: builder $(PB_FILES) +protobuf: builder + @${docker} make protobuf-local +protobuf-local: $(PB_FILES) ########################################################################### From 56c4a6dd3f8f7fc141c4ea72e0c99a8e4a3c6361 Mon Sep 17 00:00:00 2001 From: Euan Harris Date: Tue, 3 Jul 2018 15:59:12 +0100 Subject: [PATCH 4/4] Makefile: Add check for out of date protocol buffer code 'make check' will now fail if the files produced by re-running protoc differ from those which are checked into the repository. Signed-off-by: Euan Harris --- libnetwork/Makefile | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libnetwork/Makefile b/libnetwork/Makefile index db1a9c2d03..65ca478516 100644 --- a/libnetwork/Makefile +++ b/libnetwork/Makefile @@ -1,4 +1,4 @@ -.PHONY: all all-local build build-local clean cross cross-local gosimple vet lint misspell check check-local check-code check-format unit-tests protobuf protobuf-local +.PHONY: all all-local build build-local clean cross cross-local gosimple vet lint misspell check check-local check-code check-format unit-tests protobuf protobuf-local check-protobuf SHELL=/bin/bash dockerbuildargs ?= --target dev - < Dockerfile @@ -90,8 +90,15 @@ cross-local: 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 - protoc ${PROTOC_FLAGS} --gogo_out=./ $< + 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 @@ -108,7 +115,7 @@ check: builder check-local: check-code check-format -check-code: lint gosimple vet ineffassign +check-code: check-protobuf lint gosimple vet ineffassign check-format: fmt misspell @@ -161,6 +168,11 @@ gosimple: ## run gosimple @echo "🐳 $@" @test -z "$$(gosimple . | 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