github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/GNUmakefile (about)

     1  SHELL = bash
     2  PROJECT_ROOT := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
     3  THIS_OS := $(shell uname | cut -d- -f1)
     4  THIS_ARCH := $(shell uname -m)
     5  
     6  GIT_COMMIT := $(shell git rev-parse HEAD)
     7  GIT_DIRTY := $(if $(shell git status --porcelain),+CHANGES)
     8  
     9  GO_LDFLAGS := "-X github.com/hashicorp/nomad/version.GitCommit=$(GIT_COMMIT)$(GIT_DIRTY)"
    10  GO_TAGS ?= codegen_generated
    11  
    12  GO_TEST_CMD = $(if $(shell command -v gotestsum 2>/dev/null),gotestsum --,go test)
    13  
    14  ifeq ($(origin GOTEST_PKGS_EXCLUDE), undefined)
    15  GOTEST_PKGS ?= "./..."
    16  else
    17  GOTEST_PKGS=$(shell go list ./... | sed 's/github.com\/hashicorp\/nomad/./' | egrep -v "^($(GOTEST_PKGS_EXCLUDE))(/.*)?$$")
    18  endif
    19  
    20  # tag corresponding to latest release we maintain backward compatibility with
    21  PROTO_COMPARE_TAG ?= v1.0.3$(if $(findstring ent,$(GO_TAGS)),+ent,)
    22  
    23  default: help
    24  
    25  ifeq ($(CI),true)
    26  	$(info Running in a CI environment, verbose mode is disabled)
    27  else
    28  	VERBOSE="true"
    29  endif
    30  
    31  ifeq (Linux,$(THIS_OS))
    32  ALL_TARGETS = linux_386 \
    33  	linux_amd64 \
    34  	linux_arm \
    35  	linux_arm64 \
    36  	windows_386 \
    37  	windows_amd64
    38  endif
    39  
    40  ifeq (s390x,$(THIS_ARCH))
    41  ALL_TARGETS = linux_s390x
    42  endif
    43  
    44  ifeq (Darwin,$(THIS_OS))
    45  ALL_TARGETS = darwin_amd64
    46  endif
    47  
    48  ifeq (FreeBSD,$(THIS_OS))
    49  ALL_TARGETS = freebsd_amd64
    50  endif
    51  
    52  SUPPORTED_OSES = Darwin Linux FreeBSD Windows MSYS_NT
    53  
    54  # include per-user customization after all variables are defined
    55  -include GNUMakefile.local
    56  
    57  pkg/%/nomad: GO_OUT ?= $@
    58  pkg/%/nomad: CC ?= $(shell go env CC)
    59  pkg/%/nomad: ## Build Nomad for GOOS_GOARCH, e.g. pkg/linux_amd64/nomad
    60  ifeq (,$(findstring $(THIS_OS),$(SUPPORTED_OSES)))
    61  	$(warning WARNING: Building Nomad is only supported on $(SUPPORTED_OSES); not $(THIS_OS))
    62  endif
    63  	@echo "==> Building $@ with tags $(GO_TAGS)..."
    64  	@CGO_ENABLED=1 \
    65  		GOOS=$(firstword $(subst _, ,$*)) \
    66  		GOARCH=$(lastword $(subst _, ,$*)) \
    67  		CC=$(CC) \
    68  		go build -trimpath -ldflags $(GO_LDFLAGS) -tags "$(GO_TAGS)" -o $(GO_OUT)
    69  
    70  pkg/linux_arm/nomad: CC = arm-linux-gnueabihf-gcc-5
    71  pkg/linux_arm64/nomad: CC = aarch64-linux-gnu-gcc-5
    72  pkg/windows_%/nomad: GO_OUT = $@.exe
    73  
    74  # Define package targets for each of the build targets we actually have on this system
    75  define makePackageTarget
    76  
    77  pkg/$(1).zip: pkg/$(1)/nomad
    78  	@echo "==> Packaging for $(1)..."
    79  	@zip -j pkg/$(1).zip pkg/$(1)/*
    80  
    81  endef
    82  
    83  # Reify the package targets
    84  $(foreach t,$(ALL_TARGETS),$(eval $(call makePackageTarget,$(t))))
    85  
    86  .PHONY: bootstrap
    87  bootstrap: deps lint-deps git-hooks # Install all dependencies
    88  
    89  .PHONY: deps
    90  deps:  ## Install build and development dependencies
    91  ## Keep versions in sync with tools/go.mod for now (see https://github.com/golang/go/issues/30515)
    92  	@echo "==> Updating build dependencies..."
    93  	GO111MODULE=on cd tools && go get github.com/hashicorp/go-bindata/go-bindata@bf7910af899725e4938903fb32048c7c0b15f12e
    94  	GO111MODULE=on cd tools && go get github.com/elazarl/go-bindata-assetfs/go-bindata-assetfs@234c15e7648ff35458026de92b34c637bae5e6f7
    95  	GO111MODULE=on cd tools && go get github.com/a8m/tree/cmd/tree@fce18e2a750ea4e7f53ee706b1c3d9cbb22de79c
    96  	GO111MODULE=on cd tools && go get gotest.tools/gotestsum@v0.4.2
    97  	GO111MODULE=on cd tools && go get github.com/hashicorp/hcl/v2/cmd/hclfmt@v2.5.1
    98  	GO111MODULE=on cd tools && go get github.com/golang/protobuf/protoc-gen-go@v1.3.4
    99  	GO111MODULE=on cd tools && go get github.com/hashicorp/go-msgpack/codec/codecgen@v1.1.5
   100  
   101  .PHONY: lint-deps
   102  lint-deps: ## Install linter dependencies
   103  ## Keep versions in sync with tools/go.mod (see https://github.com/golang/go/issues/30515)
   104  	@echo "==> Updating linter dependencies..."
   105  	GO111MODULE=on cd tools && go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.24.0
   106  	GO111MODULE=on cd tools && go get github.com/client9/misspell/cmd/misspell@v0.3.4
   107  	GO111MODULE=on cd tools && go get github.com/hashicorp/go-hclog/hclogvet@v0.1.3
   108  
   109  .PHONY: git-hooks
   110  git-dir = $(shell git rev-parse --git-dir)
   111  git-hooks: $(git-dir)/hooks/pre-push
   112  $(git-dir)/hooks/%: dev/hooks/%
   113  	cp $^ $@
   114  	chmod 755 $@
   115  
   116  .PHONY: check
   117  check: ## Lint the source code
   118  	@echo "==> Linting source code..."
   119  	@golangci-lint run -j 1
   120  
   121  	@echo "==> Linting hclog statements..."
   122  	@hclogvet .
   123  
   124  	@echo "==> Spell checking website..."
   125  	@misspell -error -source=text website/pages/
   126  
   127  	@echo "==> Checking for breaking changes in protos..."
   128  	@buf breaking --config tools/buf/buf.yaml --against-config tools/buf/buf.yaml --against .git#tag=$(PROTO_COMPARE_TAG)
   129  
   130  	@echo "==> Check proto files are in-sync..."
   131  	@$(MAKE) proto
   132  	@if (git status -s | grep -q .pb.go); then echo the following proto files are out of sync; git status -s | grep .pb.go; exit 1; fi
   133  
   134  	@echo "==> Check format of jobspecs and HCL files..."
   135  	@$(MAKE) hclfmt
   136  	@if (git status -s | grep -q -e '\.hcl$$' -e '\.nomad$$'); then echo the following HCL files are out of sync; git status -s | grep -e '\.hcl$$' -e '\.nomad$$'; exit 1; fi
   137  
   138  	@echo "==> Check API package is isolated from rest"
   139  	@cd ./api && if go list --test -f '{{ join .Deps "\n" }}' . | grep github.com/hashicorp/nomad/ | grep -v -e /vendor/ -e /nomad/api/ -e nomad/api.test; then echo "  /api package depends the ^^ above internal nomad packages.  Remove such dependency"; exit 1; fi
   140  
   141  	@echo "==> Checking Go mod.."
   142  	@GO111MODULE=on $(MAKE) sync
   143  	@if (git status --porcelain | grep -Eq "go\.(mod|sum)"); then \
   144  		echo go.mod or go.sum needs updating; \
   145  		git --no-pager diff go.mod; \
   146  		git --no-pager diff go.sum; \
   147  		exit 1; fi
   148  	@if (git status --porcelain | grep -Eq "vendor/github.com/hashicorp/nomad/.*\.go"); then \
   149  		echo "nomad go submodules are out of sync, try 'make sync':"; \
   150  		git status -s | grep -E "vendor/github.com/hashicorp/nomad/.*\.go"; \
   151  		exit 1; fi
   152  
   153  	@echo "==> Check raft util msg type mapping are in-sync..."
   154  	@go generate ./helper/raftutil/
   155  	@if (git status -s ./helper/raftutil| grep -q .go); then echo "raftutil helper message type mapping is out of sync. Run go generate ./... and push."; exit 1; fi
   156  
   157  .PHONY: checkscripts
   158  checkscripts: ## Lint shell scripts
   159  	@echo "==> Linting scripts..."
   160  	@find scripts -type f -name '*.sh' | xargs shellcheck
   161  
   162  .PHONY: checkproto
   163  checkproto: ## Lint protobuf files
   164  	@echo "==> Lint proto files..."
   165  	@buf check lint --config tools/buf/buf.yaml
   166  
   167  	@echo "==> Checking for breaking changes in protos..."
   168  	@buf check breaking --config tools/buf/buf.yaml --against-config tools/buf/buf.yaml --against .git#tag=$(PROTO_COMPARE_TAG)
   169  
   170  .PHONY: generate-all
   171  generate-all: generate-structs proto generate-examples
   172  
   173  .PHONY: generate-structs
   174  generate-structs: LOCAL_PACKAGES = $(shell go list ./... | grep -v '/vendor/')
   175  generate-structs: ## Update generated code
   176  	@echo "--> Running go generate..."
   177  	@go generate $(LOCAL_PACKAGES)
   178  
   179  .PHONY: proto
   180  proto:
   181  	@echo "--> Generating proto bindings..."
   182  	@buf --config tools/buf/buf.yaml --template tools/buf/buf.gen.yaml generate
   183  
   184  .PHONY: generate-examples
   185  generate-examples: command/job_init.bindata_assetfs.go
   186  
   187  command/job_init.bindata_assetfs.go: command/assets/*
   188  	go-bindata-assetfs -pkg command -o command/job_init.bindata_assetfs.go ./command/assets/...
   189  
   190  .PHONY: changelogfmt
   191  changelogfmt:
   192  	@echo "--> Making [GH-xxxx] references clickable..."
   193  	@sed -E 's|([^\[])\[GH-([0-9]+)\]|\1[[GH-\2](https://github.com/hashicorp/nomad/issues/\2)]|g' CHANGELOG.md > changelog.tmp && mv changelog.tmp CHANGELOG.md
   194  
   195  ## We skip the terraform directory as there are templated hcl configurations
   196  ## that do not successfully compile without rendering
   197  .PHONY: hclfmt
   198  hclfmt:
   199  	@echo "--> Formatting HCL"
   200  	@find . -path ./terraform -prune -o -name 'upstart.nomad' -prune -o \( -name '*.nomad' -o -name '*.hcl' \) -exec \
   201  sh -c 'hclfmt -w {} || echo in path {}' ';'
   202  
   203  .PHONY: tidy
   204  tidy:
   205  	@echo "--> Tidy up submodules"
   206  	@cd tools && go mod tidy
   207  	@cd api && go mod tidy
   208  	@echo "--> Tidy nomad module"
   209  	@go mod tidy
   210  
   211  .PHONY: sync
   212  sync: tidy
   213  	@echo "--> Sync vendor directory"
   214  	@go mod vendor
   215  
   216  .PHONY: dev
   217  dev: GOOS=$(shell go env GOOS)
   218  dev: GOARCH=$(shell go env GOARCH)
   219  dev: GOPATH=$(shell go env GOPATH)
   220  dev: DEV_TARGET=pkg/$(GOOS)_$(GOARCH)/nomad
   221  dev: changelogfmt hclfmt ## Build for the current development platform
   222  	@echo "==> Removing old development build..."
   223  	@rm -f $(PROJECT_ROOT)/$(DEV_TARGET)
   224  	@rm -f $(PROJECT_ROOT)/bin/nomad
   225  	@rm -f $(GOPATH)/bin/nomad
   226  	@$(MAKE) --no-print-directory \
   227  		$(DEV_TARGET) \
   228  		GO_TAGS="$(GO_TAGS) $(NOMAD_UI_TAG)"
   229  	@mkdir -p $(PROJECT_ROOT)/bin
   230  	@mkdir -p $(GOPATH)/bin
   231  	@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(PROJECT_ROOT)/bin/
   232  	@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(GOPATH)/bin
   233  
   234  .PHONY: prerelease
   235  prerelease: GO_TAGS=ui codegen_generated release
   236  prerelease: generate-all ember-dist static-assets ## Generate all the static assets for a Nomad release
   237  
   238  .PHONY: release
   239  release: GO_TAGS=ui codegen_generated release
   240  release: clean $(foreach t,$(ALL_TARGETS),pkg/$(t).zip) ## Build all release packages which can be built on this platform.
   241  	@echo "==> Results:"
   242  	@tree --dirsfirst $(PROJECT_ROOT)/pkg
   243  
   244  .PHONY: test
   245  test: ## Run the Nomad test suite and/or the Nomad UI test suite
   246  	@if [ ! $(SKIP_NOMAD_TESTS) ]; then \
   247  		make test-nomad; \
   248  		fi
   249  	@if [ $(RUN_WEBSITE_TESTS) ]; then \
   250  		make test-website; \
   251  		fi
   252  	@if [ $(RUN_UI_TESTS) ]; then \
   253  		make test-ui; \
   254  		fi
   255  	@if [ $(RUN_E2E_TESTS) ]; then \
   256  		make e2e-test; \
   257  		fi
   258  
   259  .PHONY: test-nomad
   260  test-nomad: dev ## Run Nomad test suites
   261  	@echo "==> Running Nomad test suites:"
   262  	$(if $(ENABLE_RACE),GORACE="strip_path_prefix=$(GOPATH)/src") $(GO_TEST_CMD) \
   263  		$(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \
   264  		-cover \
   265  		-timeout=15m \
   266  		-tags "$(GO_TAGS)" \
   267  		$(GOTEST_PKGS) $(if $(VERBOSE), >test.log ; echo $$? > exit-code)
   268  	@if [ $(VERBOSE) ] ; then \
   269  		bash -C "$(PROJECT_ROOT)/scripts/test_check.sh" ; \
   270  	fi
   271  
   272  .PHONY: test-nomad-module
   273  test-nomad-module: dev ## Run Nomad test suites on a sub-module
   274  	@echo "==> Running Nomad test suites on sub-module:"
   275  	@cd $(GOTEST_MOD) && $(if $(ENABLE_RACE),GORACE="strip_path_prefix=$(GOPATH)/src") $(GO_TEST_CMD) \
   276  		$(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \
   277  		-cover \
   278  		-timeout=15m \
   279  		-tags "$(GO_TAGS)" \
   280  		./... $(if $(VERBOSE), >test.log ; echo $$? > exit-code)
   281  	@if [ $(VERBOSE) ] ; then \
   282  		bash -C "$(PROJECT_ROOT)/scripts/test_check.sh" ; \
   283  	fi
   284  
   285  .PHONY: e2e-test
   286  e2e-test: dev ## Run the Nomad e2e test suite
   287  	@echo "==> Running Nomad E2E test suites:"
   288  	go test \
   289  		$(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \
   290  		-timeout=900s \
   291  		-tags "$(GO_TAGS)" \
   292  		github.com/hashicorp/nomad/e2e
   293  
   294  .PHONY: integration-test
   295  integration-test: dev ## Run Nomad integration tests
   296  	@echo "==> Running Nomad integration test suites:"
   297  	go test \
   298  		$(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \
   299  		-cover \
   300  		-timeout=900s \
   301  		-tags "$(GO_TAGS)" \
   302  		github.com/hashicorp/nomad/e2e/vaultcompat/ \
   303  		-integration
   304  
   305  .PHONY: clean
   306  clean: GOPATH=$(shell go env GOPATH)
   307  clean: ## Remove build artifacts
   308  	@echo "==> Cleaning build artifacts..."
   309  	@rm -rf "$(PROJECT_ROOT)/bin/"
   310  	@rm -rf "$(PROJECT_ROOT)/pkg/"
   311  	@rm -f "$(GOPATH)/bin/nomad"
   312  
   313  .PHONY: testcluster
   314  testcluster: ## Bring up a Linux test cluster using Vagrant. Set PROVIDER if necessary.
   315  	vagrant up nomad-server01 \
   316  		nomad-server02 \
   317  		nomad-server03 \
   318  		nomad-client01 \
   319  		nomad-client02 \
   320  		nomad-client03 \
   321  		$(if $(PROVIDER),--provider $(PROVIDER))
   322  
   323  .PHONY: static-assets
   324  static-assets: ## Compile the static routes to serve alongside the API
   325  	@echo "--> Generating static assets"
   326  	@go-bindata-assetfs -pkg agent -prefix ui -modtime 1480000000 -tags ui -o bindata_assetfs.go ./ui/dist/...
   327  	@mv bindata_assetfs.go command/agent
   328  
   329  .PHONY: test-ui
   330  test-ui: ## Run Nomad UI test suite
   331  	@echo "--> Installing JavaScript assets"
   332  	@cd ui && npm rebuild node-sass
   333  	@cd ui && yarn install
   334  	@echo "--> Running ember tests"
   335  	@cd ui && npm test
   336  
   337  .PHONY: ember-dist
   338  ember-dist: ## Build the static UI assets from source
   339  	@echo "--> Installing JavaScript assets"
   340  	@cd ui && yarn install --silent
   341  	@cd ui && npm rebuild node-sass
   342  	@echo "--> Building Ember application"
   343  	@cd ui && npm run build
   344  
   345  .PHONY: dev-ui
   346  dev-ui: ember-dist static-assets
   347  	@$(MAKE) NOMAD_UI_TAG="ui" dev ## Build a dev binary with the UI baked in
   348  
   349  HELP_FORMAT="    \033[36m%-25s\033[0m %s\n"
   350  .PHONY: help
   351  help: ## Display this usage information
   352  	@echo "Valid targets:"
   353  	@grep -E '^[^ ]+:.*?## .*$$' $(MAKEFILE_LIST) | \
   354  		sort | \
   355  		awk 'BEGIN {FS = ":.*?## "}; \
   356  			{printf $(HELP_FORMAT), $$1, $$2}'
   357  	@echo ""
   358  	@echo "This host will build the following targets if 'make release' is invoked:"
   359  	@echo $(ALL_TARGETS) | sed 's/^/    /'
   360  
   361  .PHONY: ui-screenshots
   362  ui-screenshots:
   363  	@echo "==> Collecting UI screenshots..."
   364          # Build the screenshots image if it doesn't exist yet
   365  	@if [[ "$$(docker images -q nomad-ui-screenshots 2> /dev/null)" == "" ]]; then \
   366  		docker build --tag="nomad-ui-screenshots" ./scripts/screenshots; \
   367  	fi
   368  	@docker run \
   369  		--rm \
   370  		--volume "$(shell pwd)/scripts/screenshots/screenshots:/screenshots" \
   371  		nomad-ui-screenshots
   372  
   373  .PHONY: ui-screenshots-local
   374  ui-screenshots-local:
   375  	@echo "==> Collecting UI screenshots (local)..."
   376  	@cd scripts/screenshots/src && SCREENSHOTS_DIR="../screenshots" node index.js