github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/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 -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 test -x $(GOPATH)/bin/vendorfmt || go get -u github.com/magiconair/vendorfmt/cmd/vendorfmt 246 vendorfmt 247 248 .PHONY: changelogfmt 249 changelogfmt: 250 @echo "--> Making [GH-xxxx] references clickable..." 251 @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 252 253 ## We skip the terraform directory as there are templated hcl configurations 254 ## that do not successfully compile without rendering 255 .PHONY: hclfmt 256 hclfmt: 257 @echo "--> Formatting HCL" 258 @find . -path ./terraform -prune -o -name 'upstart.nomad' -prune -o \( -name '*.nomad' -o -name '*.hcl' \) -exec \ 259 sh -c 'hclfmt -w {} || echo in path {}' ';' 260 261 .PHONY: dev 262 dev: GOOS=$(shell go env GOOS) 263 dev: GOARCH=$(shell go env GOARCH) 264 dev: GOPATH=$(shell go env GOPATH) 265 dev: DEV_TARGET=pkg/$(GOOS)_$(GOARCH)/nomad 266 dev: vendorfmt changelogfmt hclfmt ## Build for the current development platform 267 @echo "==> Removing old development build..." 268 @rm -f $(PROJECT_ROOT)/$(DEV_TARGET) 269 @rm -f $(PROJECT_ROOT)/bin/nomad 270 @rm -f $(GOPATH)/bin/nomad 271 @$(MAKE) --no-print-directory \ 272 $(DEV_TARGET) \ 273 GO_TAGS="$(GO_TAGS) $(NOMAD_UI_TAG)" 274 @mkdir -p $(PROJECT_ROOT)/bin 275 @mkdir -p $(GOPATH)/bin 276 @cp $(PROJECT_ROOT)/$(DEV_TARGET) $(PROJECT_ROOT)/bin/ 277 @cp $(PROJECT_ROOT)/$(DEV_TARGET) $(GOPATH)/bin 278 279 .PHONY: prerelease 280 prerelease: GO_TAGS=ui codegen_generated release 281 prerelease: generate-all ember-dist static-assets ## Generate all the static assets for a Nomad release 282 283 .PHONY: release 284 release: GO_TAGS=ui codegen_generated release 285 release: clean $(foreach t,$(ALL_TARGETS),pkg/$(t).zip) ## Build all release packages which can be built on this platform. 286 @echo "==> Results:" 287 @tree --dirsfirst $(PROJECT_ROOT)/pkg 288 289 .PHONY: test 290 test: ## Run the Nomad test suite and/or the Nomad UI test suite 291 @if [ ! $(SKIP_NOMAD_TESTS) ]; then \ 292 make test-nomad; \ 293 fi 294 @if [ $(RUN_WEBSITE_TESTS) ]; then \ 295 make test-website; \ 296 fi 297 @if [ $(RUN_UI_TESTS) ]; then \ 298 make test-ui; \ 299 fi 300 @if [ $(RUN_E2E_TESTS) ]; then \ 301 make e2e-test; \ 302 fi 303 304 .PHONY: test-nomad 305 test-nomad: dev ## Run Nomad test suites 306 @echo "==> Running Nomad test suites:" 307 $(if $(ENABLE_RACE),GORACE="strip_path_prefix=$(GOPATH)/src") $(GO_TEST_CMD) \ 308 $(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \ 309 -cover \ 310 -timeout=15m \ 311 -tags "$(GO_TAGS)" \ 312 $(GOTEST_PKGS) $(if $(VERBOSE), >test.log ; echo $$? > exit-code) 313 @if [ $(VERBOSE) ] ; then \ 314 bash -C "$(PROJECT_ROOT)/scripts/test_check.sh" ; \ 315 fi 316 317 .PHONY: e2e-test 318 e2e-test: dev ## Run the Nomad e2e test suite 319 @echo "==> Running Nomad E2E test suites:" 320 go test \ 321 $(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \ 322 -cover \ 323 -timeout=900s \ 324 -tags "$(GO_TAGS)" \ 325 github.com/hashicorp/nomad/e2e/vault/ \ 326 -integration 327 328 .PHONY: clean 329 clean: GOPATH=$(shell go env GOPATH) 330 clean: ## Remove build artifacts 331 @echo "==> Cleaning build artifacts..." 332 @rm -rf "$(PROJECT_ROOT)/bin/" 333 @rm -rf "$(PROJECT_ROOT)/pkg/" 334 @rm -f "$(GOPATH)/bin/nomad" 335 336 .PHONY: testcluster 337 testcluster: ## Bring up a Linux test cluster using Vagrant. Set PROVIDER if necessary. 338 vagrant up nomad-server01 \ 339 nomad-server02 \ 340 nomad-server03 \ 341 nomad-client01 \ 342 nomad-client02 \ 343 nomad-client03 \ 344 $(if $(PROVIDER),--provider $(PROVIDER)) 345 346 .PHONY: static-assets 347 static-assets: ## Compile the static routes to serve alongside the API 348 @echo "--> Generating static assets" 349 @go-bindata-assetfs -pkg agent -prefix ui -modtime 1480000000 -tags ui -o bindata_assetfs.go ./ui/dist/... 350 @mv bindata_assetfs.go command/agent 351 352 .PHONY: test-ui 353 test-ui: ## Run Nomad UI test suite 354 @echo "--> Installing JavaScript assets" 355 @cd ui && npm rebuild node-sass 356 @cd ui && yarn install 357 @echo "--> Running ember tests" 358 @cd ui && npm test 359 360 .PHONY: ember-dist 361 ember-dist: ## Build the static UI assets from source 362 @echo "--> Installing JavaScript assets" 363 @cd ui && yarn install --silent 364 @cd ui && npm rebuild node-sass 365 @echo "--> Building Ember application" 366 @cd ui && npm run build 367 368 .PHONY: dev-ui 369 dev-ui: ember-dist static-assets 370 @$(MAKE) NOMAD_UI_TAG="ui" dev ## Build a dev binary with the UI baked in 371 372 HELP_FORMAT=" \033[36m%-25s\033[0m %s\n" 373 .PHONY: help 374 help: ## Display this usage information 375 @echo "Valid targets:" 376 @grep -E '^[^ ]+:.*?## .*$$' $(MAKEFILE_LIST) | \ 377 sort | \ 378 awk 'BEGIN {FS = ":.*?## "}; \ 379 {printf $(HELP_FORMAT), $$1, $$2}' 380 @echo "" 381 @echo "This host will build the following targets if 'make release' is invoked:" 382 @echo $(ALL_TARGETS) | sed 's/^/ /' 383 384 .PHONY: ui-screenshots 385 ui-screenshots: 386 @echo "==> Collecting UI screenshots..." 387 # Build the screenshots image if it doesn't exist yet 388 @if [[ "$$(docker images -q nomad-ui-screenshots 2> /dev/null)" == "" ]]; then \ 389 docker build --tag="nomad-ui-screenshots" ./scripts/screenshots; \ 390 fi 391 @docker run \ 392 --rm \ 393 --volume "$(shell pwd)/scripts/screenshots/screenshots:/screenshots" \ 394 nomad-ui-screenshots 395 396 .PHONY: ui-screenshots-local 397 ui-screenshots-local: 398 @echo "==> Collecting UI screenshots (local)..." 399 @cd scripts/screenshots/src && SCREENSHOTS_DIR="../screenshots" node index.js