github.com/criteo-forks/consul@v1.4.5-criteonogrpc/GNUmakefile (about) 1 SHELL = bash 2 GOTOOLS = \ 3 github.com/elazarl/go-bindata-assetfs/... \ 4 github.com/hashicorp/go-bindata/... \ 5 github.com/magiconair/vendorfmt/cmd/vendorfmt \ 6 github.com/mitchellh/gox \ 7 golang.org/x/tools/cmd/cover \ 8 golang.org/x/tools/cmd/stringer \ 9 github.com/axw/gocov/gocov \ 10 gopkg.in/matm/v1/gocov-html \ 11 github.com/gogo/protobuf/protoc-gen-gofast \ 12 github.com/vektra/mockery/cmd/mockery 13 14 GOTAGS ?= 15 GOFILES ?= $(shell go list ./... | grep -v /vendor/) 16 ifeq ($(origin GOTEST_PKGS_EXCLUDE), undefined) 17 GOTEST_PKGS ?= "./..." 18 else 19 GOTEST_PKGS=$(shell go list ./... | sed 's/github.com\/hashicorp\/consul/./' | egrep -v "^($(GOTEST_PKGS_EXCLUDE))$$") 20 endif 21 GOOS?=$(shell go env GOOS) 22 GOARCH?=$(shell go env GOARCH) 23 GOPATH=$(shell go env GOPATH) 24 25 ASSETFS_PATH?=agent/bindata_assetfs.go 26 # Get the git commit 27 GIT_COMMIT?=$(shell git rev-parse --short HEAD) 28 GIT_DIRTY?=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true) 29 GIT_DESCRIBE?=$(shell git describe --tags --always) 30 GIT_IMPORT=github.com/hashicorp/consul/version 31 GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) -X $(GIT_IMPORT).GitDescribe=$(GIT_DESCRIBE) 32 33 ifeq ($(FORCE_REBUILD),1) 34 NOCACHE=--no-cache 35 else 36 NOCACHE= 37 endif 38 39 DOCKER_BUILD_QUIET?=1 40 ifeq (${DOCKER_BUILD_QUIET},1) 41 QUIET=-q 42 else 43 QUIET= 44 endif 45 46 CONSUL_DEV_IMAGE?=consul-dev 47 GO_BUILD_TAG?=consul-build-go 48 UI_BUILD_TAG?=consul-build-ui 49 UI_LEGACY_BUILD_TAG?=consul-build-ui-legacy 50 BUILD_CONTAINER_NAME?=consul-builder 51 52 DIST_TAG?=1 53 DIST_BUILD?=1 54 DIST_SIGN?=1 55 56 ifdef DIST_VERSION 57 DIST_VERSION_ARG=-v "$(DIST_VERSION)" 58 else 59 DIST_VERSION_ARG= 60 endif 61 62 ifdef DIST_RELEASE_DATE 63 DIST_DATE_ARG=-d "$(DIST_RELEASE_DATE)" 64 else 65 DIST_DATE_ARG= 66 endif 67 68 ifdef DIST_PRERELEASE 69 DIST_REL_ARG=-r "$(DIST_PRERELEASE)" 70 else 71 DIST_REL_ARG= 72 endif 73 74 PUB_GIT?=1 75 PUB_WEBSITE?=1 76 77 ifeq ($(PUB_GIT),1) 78 PUB_GIT_ARG=-g 79 else 80 PUB_GIT_ARG= 81 endif 82 83 ifeq ($(PUB_WEBSITE),1) 84 PUB_WEBSITE_ARG=-w 85 else 86 PUB_WEBSITE_ARG= 87 endif 88 89 NOGOX?=1 90 91 export NOGOX 92 export GO_BUILD_TAG 93 export UI_BUILD_TAG 94 export UI_LEGACY_BUILD_TAG 95 export BUILD_CONTAINER_NAME 96 export GIT_COMMIT 97 export GIT_DIRTY 98 export GIT_DESCRIBE 99 export GOTAGS 100 export GOLDFLAGS 101 102 103 DEV_PUSH?=0 104 ifeq ($(DEV_PUSH),1) 105 DEV_PUSH_ARG= 106 else 107 DEV_PUSH_ARG=--no-push 108 endif 109 110 # all builds binaries for all targets 111 all: bin 112 113 bin: tools 114 @$(SHELL) $(CURDIR)/build-support/scripts/build-local.sh 115 116 # dev creates binaries for testing locally - these are put into ./bin and $GOPATH 117 dev: changelogfmt vendorfmt dev-build 118 119 dev-build: 120 @$(SHELL) $(CURDIR)/build-support/scripts/build-local.sh -o $(GOOS) -a $(GOARCH) 121 122 dev-docker: go-build-image 123 @docker build -t '$(CONSUL_DEV_IMAGE)' --build-arg 'GIT_COMMIT=$(GIT_COMMIT)' --build-arg 'GIT_DIRTY=$(GIT_DIRTY)' --build-arg 'GIT_DESCRIBE=$(GIT_DESCRIBE)' --build-arg 'CONSUL_BUILD_IMAGE=$(GO_BUILD_TAG)' -f $(CURDIR)/build-support/docker/Consul-Dev.dockerfile '$(CURDIR)' 124 125 vendorfmt: 126 @echo "--> Formatting vendor/vendor.json" 127 test -x $(GOPATH)/bin/vendorfmt || go get -u github.com/magiconair/vendorfmt/cmd/vendorfmt 128 vendorfmt 129 130 changelogfmt: 131 @echo "--> Making [GH-xxxx] references clickable..." 132 @sed -E 's|([^\[])\[GH-([0-9]+)\]|\1[[GH-\2](https://github.com/hashicorp/consul/issues/\2)]|g' CHANGELOG.md > changelog.tmp && mv changelog.tmp CHANGELOG.md 133 134 # linux builds a linux package independent of the source platform 135 linux: 136 @$(SHELL) $(CURDIR)/build-support/scripts/build-local.sh -o linux -a amd64 137 138 pkg/bin/windows_amd64/consul.exe: 139 mkdir -p pkg/bin/windows_amd64 140 GOOS=windows GOARCH=amd64 go build -o pkg/bin/windows_amd64/consul.exe 141 142 pkg/bin/linux_amd64/consul: 143 mkdir -p pkg/bin/linux_amd64 144 GOOS=linux GOARCH=amd64 go build -o pkg/bin/linux_amd64/consul 145 146 pkg/bin/darwin_amd64/consul: 147 mkdir -p pkg/bin/darwin_amd64 148 GOOS=darwin GOARCH=amd64 go build -o pkg/bin/darwin_amd64/consul 149 150 multiarch: pkg/bin/windows_amd64/consul.exe pkg/bin/linux_amd64/consul pkg/bin/darwin_amd64/consul 151 152 # dist builds binaries for all platforms and packages them for distribution 153 dist: 154 @$(SHELL) $(CURDIR)/build-support/scripts/release.sh -t '$(DIST_TAG)' -b '$(DIST_BUILD)' -S '$(DIST_SIGN)' $(DIST_VERSION_ARG) $(DIST_DATE_ARG) $(DIST_REL_ARG) 155 156 verify: 157 @$(SHELL) $(CURDIR)/build-support/scripts/verify.sh 158 159 publish: 160 @$(SHELL) $(CURDIR)/build-support/scripts/publish.sh $(PUB_GIT_ARG) $(PUB_WEBSITE_ARG) 161 162 dev-tree: 163 @$(SHELL) $(CURDIR)/build-support/scripts/dev.sh $(DEV_PUSH_ARG) 164 165 cov: 166 gocov test $(GOFILES) | gocov-html > /tmp/coverage.html 167 open /tmp/coverage.html 168 169 test: other-consul dev-build vet test-install-deps test-internal 170 171 test-install-deps: 172 go test -tags '$(GOTAGS)' -i $(GOTEST_PKGS) 173 174 test-internal: 175 @echo "--> Running go test" 176 @rm -f test.log exit-code 177 @# Dump verbose output to test.log so we can surface test names on failure but 178 @# hide it from travis as it exceeds their log limits and causes job to be 179 @# terminated (over 4MB and over 10k lines in the UI). We need to output 180 @# _something_ to stop them terminating us due to inactivity... 181 { go test -v $(GOTEST_FLAGS) -tags '$(GOTAGS)' $(GOTEST_PKGS) 2>&1 ; echo $$? > exit-code ; } | tee test.log | egrep '^(ok|FAIL|panic:|--- FAIL|--- PASS)' 182 @echo "Exit code: $$(cat exit-code)" 183 @# This prints all the race report between ====== lines 184 @awk '/^WARNING: DATA RACE/ {do_print=1; print "=================="} do_print==1 {print} /^={10,}/ {do_print=0}' test.log || true 185 @grep -A10 'panic: ' test.log || true 186 @# Prints all the failure output until the next non-indented line - testify 187 @# helpers often output multiple lines for readability but useless if we can't 188 @# see them. Un-intuitive order of matches is necessary. No || true because 189 @# awk always returns true even if there is no match and it breaks non-bash 190 @# shells locally. 191 @awk '/^[^[:space:]]/ {do_print=0} /--- SKIP/ {do_print=1} do_print==1 {print}' test.log 192 @awk '/^[^[:space:]]/ {do_print=0} /--- FAIL/ {do_print=1} do_print==1 {print}' test.log 193 @grep '^FAIL' test.log || true 194 @if [ "$$(cat exit-code)" == "0" ] ; then echo "PASS" ; exit 0 ; else exit 1 ; fi 195 196 test-race: 197 $(MAKE) GOTEST_FLAGS=-race 198 199 # Run tests with config for CI so `make test` can still be local-dev friendly. 200 test-ci: other-consul dev-build vet test-install-deps 201 @ if ! GOTEST_FLAGS="-short -timeout 8m -p 3 -parallel 4" make test-internal; then \ 202 echo " ============"; \ 203 echo " Retrying 1/2"; \ 204 echo " ============"; \ 205 if ! GOTEST_FLAGS="-timeout 9m -p 1 -parallel 1" make test-internal; then \ 206 echo " ============"; \ 207 echo " Retrying 2/2"; \ 208 echo " ============"; \ 209 GOTEST_FLAGS="-timeout 9m -p 1 -parallel 1" make test-internal; \ 210 fi \ 211 fi 212 213 test-flake: other-consul vet test-install-deps 214 @$(SHELL) $(CURDIR)/build-support/scripts/test-flake.sh --pkg "$(FLAKE_PKG)" --test "$(FLAKE_TEST)" --cpus "$(FLAKE_CPUS)" --n "$(FLAKE_N)" 215 216 other-consul: 217 @echo "--> Checking for other consul instances" 218 @if ps -ef | grep 'consul agent' | grep -v grep ; then \ 219 echo "Found other running consul agents. This may affect your tests." ; \ 220 exit 1 ; \ 221 fi 222 223 cover: 224 go test $(GOFILES) --cover 225 226 format: 227 @echo "--> Running go fmt" 228 @go fmt $(GOFILES) 229 230 vet: 231 @echo "--> Running go vet" 232 @go vet -tags '$(GOTAGS)' $(GOFILES); if [ $$? -eq 1 ]; then \ 233 echo ""; \ 234 echo "Vet found suspicious constructs. Please check the reported constructs"; \ 235 echo "and fix them if necessary before submitting the code for review."; \ 236 exit 1; \ 237 fi 238 239 # If you've run "make ui" manually then this will get called for you. This is 240 # also run as part of the release build script when it verifies that there are no 241 # changes to the UI assets that aren't checked in. 242 static-assets: 243 @go-bindata-assetfs -pkg agent -prefix pkg -o $(ASSETFS_PATH) ./pkg/web_ui/... 244 $(MAKE) format 245 246 247 # Build the static web ui and build static assets inside a Docker container 248 ui: ui-legacy-docker ui-docker static-assets-docker 249 250 tools: 251 go get -u -v $(GOTOOLS) 252 253 version: 254 @echo -n "Version: " 255 @$(SHELL) $(CURDIR)/build-support/scripts/version.sh 256 @echo -n "Version + release: " 257 @$(SHELL) $(CURDIR)/build-support/scripts/version.sh -r 258 @echo -n "Version + git: " 259 @$(SHELL) $(CURDIR)/build-support/scripts/version.sh -g 260 @echo -n "Version + release + git: " 261 @$(SHELL) $(CURDIR)/build-support/scripts/version.sh -r -g 262 263 264 docker-images: go-build-image ui-build-image ui-legacy-build-image 265 266 go-build-image: 267 @echo "Building Golang build container" 268 @docker build $(NOCACHE) $(QUIET) --build-arg 'GOTOOLS=$(GOTOOLS)' -t $(GO_BUILD_TAG) - < build-support/docker/Build-Go.dockerfile 269 270 ui-build-image: 271 @echo "Building UI build container" 272 @docker build $(NOCACHE) $(QUIET) -t $(UI_BUILD_TAG) - < build-support/docker/Build-UI.dockerfile 273 274 ui-legacy-build-image: 275 @echo "Building Legacy UI build container" 276 @docker build $(NOCACHE) $(QUIET) -t $(UI_LEGACY_BUILD_TAG) - < build-support/docker/Build-UI-Legacy.dockerfile 277 278 static-assets-docker: go-build-image 279 @$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh static-assets 280 281 consul-docker: go-build-image 282 @$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh consul 283 284 ui-docker: ui-build-image 285 @$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh ui 286 287 ui-legacy-docker: ui-legacy-build-image 288 @$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh ui-legacy 289 290 proto: 291 protoc agent/connect/ca/plugin/*.proto --gofast_out=plugins=grpc:../../.. 292 293 .PHONY: all ci bin dev dist cov test test-ci test-internal test-install-deps cover format vet ui static-assets tools vendorfmt 294 .PHONY: docker-images go-build-image ui-build-image ui-legacy-build-image static-assets-docker consul-docker ui-docker ui-legacy-docker version proto