github.imxd.top/hashicorp/consul@v1.4.5/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  # dist builds binaries for all platforms and packages them for distribution
   139  dist:
   140  	@$(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)
   141  
   142  verify:
   143  	@$(SHELL) $(CURDIR)/build-support/scripts/verify.sh
   144  
   145  publish:
   146  	@$(SHELL) $(CURDIR)/build-support/scripts/publish.sh $(PUB_GIT_ARG) $(PUB_WEBSITE_ARG)
   147  
   148  dev-tree:
   149  	@$(SHELL) $(CURDIR)/build-support/scripts/dev.sh $(DEV_PUSH_ARG)
   150  
   151  cov:
   152  	gocov test $(GOFILES) | gocov-html > /tmp/coverage.html
   153  	open /tmp/coverage.html
   154  
   155  test: other-consul dev-build vet test-install-deps test-internal
   156  
   157  test-install-deps:
   158  	go test -tags '$(GOTAGS)' -i $(GOTEST_PKGS)
   159  
   160  test-internal:
   161  	@echo "--> Running go test"
   162  	@rm -f test.log exit-code
   163  	@# Dump verbose output to test.log so we can surface test names on failure but
   164  	@# hide it from travis as it exceeds their log limits and causes job to be
   165  	@# terminated (over 4MB and over 10k lines in the UI). We need to output
   166  	@# _something_ to stop them terminating us due to inactivity...
   167  	{ go test -v $(GOTEST_FLAGS) -tags '$(GOTAGS)' $(GOTEST_PKGS) 2>&1 ; echo $$? > exit-code ; } | tee test.log | egrep '^(ok|FAIL|panic:|--- FAIL|--- PASS)'
   168  	@echo "Exit code: $$(cat exit-code)"
   169  	@# This prints all the race report between ====== lines
   170  	@awk '/^WARNING: DATA RACE/ {do_print=1; print "=================="} do_print==1 {print} /^={10,}/ {do_print=0}' test.log || true
   171  	@grep -A10 'panic: ' test.log || true
   172  	@# Prints all the failure output until the next non-indented line - testify
   173  	@# helpers often output multiple lines for readability but useless if we can't
   174  	@# see them. Un-intuitive order of matches is necessary. No || true because
   175  	@# awk always returns true even if there is no match and it breaks non-bash
   176  	@# shells locally.
   177  	@awk '/^[^[:space:]]/ {do_print=0} /--- SKIP/ {do_print=1} do_print==1 {print}' test.log
   178  	@awk '/^[^[:space:]]/ {do_print=0} /--- FAIL/ {do_print=1} do_print==1 {print}' test.log
   179  	@grep '^FAIL' test.log || true
   180  	@if [ "$$(cat exit-code)" == "0" ] ; then echo "PASS" ; exit 0 ; else exit 1 ; fi
   181  
   182  test-race:
   183  	$(MAKE) GOTEST_FLAGS=-race
   184  
   185  # Run tests with config for CI so `make test` can still be local-dev friendly.
   186  test-ci: other-consul dev-build vet test-install-deps
   187  	@ if ! GOTEST_FLAGS="-short -timeout 8m -p 3 -parallel 4" make test-internal; then \
   188  	    echo "    ============"; \
   189  	    echo "      Retrying 1/2"; \
   190  	    echo "    ============"; \
   191  	    if ! GOTEST_FLAGS="-timeout 9m -p 1 -parallel 1" make test-internal; then \
   192  	       echo "    ============"; \
   193  	       echo "      Retrying 2/2"; \
   194  	       echo "    ============"; \
   195  	       GOTEST_FLAGS="-timeout 9m -p 1 -parallel 1" make test-internal; \
   196  	    fi \
   197  	fi
   198  
   199  test-flake: other-consul vet test-install-deps
   200  	@$(SHELL) $(CURDIR)/build-support/scripts/test-flake.sh --pkg "$(FLAKE_PKG)" --test "$(FLAKE_TEST)" --cpus "$(FLAKE_CPUS)" --n "$(FLAKE_N)"
   201  
   202  other-consul:
   203  	@echo "--> Checking for other consul instances"
   204  	@if ps -ef | grep 'consul agent' | grep -v grep ; then \
   205  		echo "Found other running consul agents. This may affect your tests." ; \
   206  		exit 1 ; \
   207  	fi
   208  
   209  cover:
   210  	go test $(GOFILES) --cover
   211  
   212  format:
   213  	@echo "--> Running go fmt"
   214  	@go fmt $(GOFILES)
   215  
   216  vet:
   217  	@echo "--> Running go vet"
   218  	@go vet -tags '$(GOTAGS)' $(GOFILES); if [ $$? -eq 1 ]; then \
   219  		echo ""; \
   220  		echo "Vet found suspicious constructs. Please check the reported constructs"; \
   221  		echo "and fix them if necessary before submitting the code for review."; \
   222  		exit 1; \
   223  	fi
   224  
   225  # If you've run "make ui" manually then this will get called for you. This is
   226  # also run as part of the release build script when it verifies that there are no
   227  # changes to the UI assets that aren't checked in.
   228  static-assets:
   229  	@go-bindata-assetfs -pkg agent -prefix pkg -o $(ASSETFS_PATH) ./pkg/web_ui/...
   230  	$(MAKE) format
   231  
   232  
   233  # Build the static web ui and build static assets inside a Docker container
   234  ui: ui-legacy-docker ui-docker static-assets-docker
   235  
   236  tools:
   237  	go get -u -v $(GOTOOLS)
   238  
   239  version:
   240  	@echo -n "Version:                    "
   241  	@$(SHELL) $(CURDIR)/build-support/scripts/version.sh
   242  	@echo -n "Version + release:          "
   243  	@$(SHELL) $(CURDIR)/build-support/scripts/version.sh -r
   244  	@echo -n "Version + git:              "
   245  	@$(SHELL) $(CURDIR)/build-support/scripts/version.sh  -g
   246  	@echo -n "Version + release + git:    "
   247  	@$(SHELL) $(CURDIR)/build-support/scripts/version.sh -r -g
   248  
   249  
   250  docker-images: go-build-image ui-build-image ui-legacy-build-image
   251  
   252  go-build-image:
   253  	@echo "Building Golang build container"
   254  	@docker build $(NOCACHE) $(QUIET) --build-arg 'GOTOOLS=$(GOTOOLS)' -t $(GO_BUILD_TAG) - < build-support/docker/Build-Go.dockerfile
   255  
   256  ui-build-image:
   257  	@echo "Building UI build container"
   258  	@docker build $(NOCACHE) $(QUIET) -t $(UI_BUILD_TAG) - < build-support/docker/Build-UI.dockerfile
   259  
   260  ui-legacy-build-image:
   261  	@echo "Building Legacy UI build container"
   262  	@docker build $(NOCACHE) $(QUIET) -t $(UI_LEGACY_BUILD_TAG) - < build-support/docker/Build-UI-Legacy.dockerfile
   263  
   264  static-assets-docker: go-build-image
   265  	@$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh static-assets
   266  
   267  consul-docker: go-build-image
   268  	@$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh consul
   269  
   270  ui-docker: ui-build-image
   271  	@$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh ui
   272  
   273  ui-legacy-docker: ui-legacy-build-image
   274  	@$(SHELL) $(CURDIR)/build-support/scripts/build-docker.sh ui-legacy
   275  
   276  proto:
   277  	protoc agent/connect/ca/plugin/*.proto --gofast_out=plugins=grpc:../../..
   278  
   279  .PHONY: all ci bin dev dist cov test test-ci test-internal test-install-deps cover format vet ui static-assets tools vendorfmt
   280  .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