github.com/rohankumardubey/nomad@v0.11.8/GNUmakefile (about)

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