github.com/manicqin/nomad@v0.9.5/GNUmakefile (about)

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