github.com/bigcommerce/nomad@v0.9.3-bc/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 = 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 ($(TRAVIS),true) 29 $(info Running in Travis, 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 pkg/darwin_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for darwin/amd64 55 @echo "==> Building $@ with tags $(GO_TAGS)..." 56 @CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 \ 57 go build \ 58 -ldflags $(GO_LDFLAGS) \ 59 -tags "$(GO_TAGS)" \ 60 -o "$@" 61 62 pkg/freebsd_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for freebsd/amd64 63 @echo "==> Building $@..." 64 @CGO_ENABLED=1 GOOS=freebsd GOARCH=amd64 \ 65 go build \ 66 -ldflags $(GO_LDFLAGS) \ 67 -tags "$(GO_TAGS)" \ 68 -o "$@" 69 70 pkg/linux_386/nomad: $(SOURCE_FILES) ## Build Nomad for linux/386 71 @echo "==> Building $@ with tags $(GO_TAGS)..." 72 @CGO_ENABLED=1 GOOS=linux GOARCH=386 \ 73 go build \ 74 -ldflags $(GO_LDFLAGS) \ 75 -tags "$(GO_TAGS)" \ 76 -o "$@" 77 78 pkg/linux_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for linux/amd64 79 @echo "==> Building $@ with tags $(GO_TAGS)..." 80 @CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \ 81 go build \ 82 -ldflags $(GO_LDFLAGS) \ 83 -tags "$(GO_TAGS)" \ 84 -o "$@" 85 86 pkg/linux_arm/nomad: $(SOURCE_FILES) ## Build Nomad for linux/arm 87 @echo "==> Building $@ with tags $(GO_TAGS)..." 88 @CGO_ENABLED=1 GOOS=linux GOARCH=arm CC=arm-linux-gnueabihf-gcc-5 \ 89 go build \ 90 -ldflags $(GO_LDFLAGS) \ 91 -tags "$(GO_TAGS)" \ 92 -o "$@" 93 94 pkg/linux_arm64/nomad: $(SOURCE_FILES) ## Build Nomad for linux/arm64 95 @echo "==> Building $@ with tags $(GO_TAGS)..." 96 @CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc-5 \ 97 go build \ 98 -ldflags $(GO_LDFLAGS) \ 99 -tags "$(GO_TAGS)" \ 100 -o "$@" 101 102 # If CGO support for Windows is ever required, set the following variables 103 # in the environment for `go build` for both the windows/amd64 and the 104 # windows/386 targets: 105 # CC=i686-w64-mingw32-gcc 106 # CXX=i686-w64-mingw32-g++ 107 pkg/windows_386/nomad: $(SOURCE_FILES) ## Build Nomad for windows/386 108 @echo "==> Building $@ with tags $(GO_TAGS)..." 109 @CGO_ENABLED=1 GOOS=windows GOARCH=386 \ 110 go build \ 111 -ldflags $(GO_LDFLAGS) \ 112 -tags "$(GO_TAGS)" \ 113 -o "$@.exe" 114 115 pkg/windows_amd64/nomad: $(SOURCE_FILES) ## Build Nomad for windows/amd64 116 @echo "==> Building $@ with tags $(GO_TAGS)..." 117 @CGO_ENABLED=1 GOOS=windows GOARCH=amd64 \ 118 go build \ 119 -ldflags $(GO_LDFLAGS) \ 120 -tags "$(GO_TAGS)" \ 121 -o "$@.exe" 122 123 # Define package targets for each of the build targets we actually have on this system 124 define makePackageTarget 125 126 pkg/$(1).zip: pkg/$(1)/nomad 127 @echo "==> Packaging for $(1)..." 128 @zip -j pkg/$(1).zip pkg/$(1)/* 129 130 endef 131 132 # Reify the package targets 133 $(foreach t,$(ALL_TARGETS),$(eval $(call makePackageTarget,$(t)))) 134 135 .PHONY: bootstrap 136 bootstrap: deps lint-deps git-hooks # Install all dependencies 137 138 .PHONY: deps 139 deps: ## Install build and development dependencies 140 @echo "==> Updating build dependencies..." 141 go get -u github.com/kardianos/govendor 142 go get -u github.com/hashicorp/go-bindata/go-bindata 143 go get -u github.com/elazarl/go-bindata-assetfs/go-bindata-assetfs 144 go get -u github.com/a8m/tree/cmd/tree 145 go get -u github.com/magiconair/vendorfmt/cmd/vendorfmt 146 go get -u gotest.tools/gotestsum 147 @bash -C "$(PROJECT_ROOT)/scripts/install-codecgen.sh" 148 @bash -C "$(PROJECT_ROOT)/scripts/install-protoc-gen-go.sh" 149 150 .PHONY: lint-deps 151 lint-deps: ## Install linter dependencies 152 @echo "==> Updating linter dependencies..." 153 go get -u github.com/alecthomas/gometalinter 154 gometalinter --install 155 156 .PHONY: git-hooks 157 git-dir = $(shell git rev-parse --git-dir) 158 git-hooks: $(git-dir)/hooks/pre-push 159 $(git-dir)/hooks/%: dev/hooks/% 160 cp $^ $@ 161 chmod 755 $@ 162 163 .PHONY: check 164 check: ## Lint the source code 165 @echo "==> Linting source code..." 166 @gometalinter \ 167 --deadline 10m \ 168 --vendor \ 169 --exclude='.*\.generated\.go' \ 170 --exclude='.*bindata_assetfs\.go' \ 171 --skip="ui/" \ 172 --sort="path" \ 173 --aggregate \ 174 --enable-gc \ 175 --disable-all \ 176 --enable goimports \ 177 --enable misspell \ 178 --enable vet \ 179 --enable deadcode \ 180 --enable varcheck \ 181 --enable ineffassign \ 182 --enable structcheck \ 183 --enable unconvert \ 184 --enable gofmt \ 185 ./... 186 @echo "==> Spell checking website..." 187 @misspell -error -source=text website/source/ 188 189 @echo "==> Check proto files are in-sync..." 190 @$(MAKE) proto 191 @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 192 193 @echo "==> Check API package is isolated from rest" 194 @! go list -f '{{ join .Deps "\n" }}' ./api | grep github.com/hashicorp/nomad/ | grep -v -e /vendor/ -e /nomad/api/ 195 196 .PHONY: checkscripts 197 checkscripts: ## Lint shell scripts 198 @echo "==> Linting scripts..." 199 @find scripts -type f -name '*.sh' | xargs shellcheck 200 201 .PHONY: generate-all 202 generate-all: generate-structs proto 203 204 .PHONY: generate-structs 205 generate-structs: LOCAL_PACKAGES = $(shell go list ./... | grep -v '/vendor/') 206 generate-structs: ## Update generated code 207 @echo "--> Running go generate..." 208 @go generate $(LOCAL_PACKAGES) 209 210 .PHONY: proto 211 proto: 212 @echo "--> Generating proto bindings..." 213 @for file in $$(git ls-files "*.proto" | grep -v "vendor\/.*.proto"); do \ 214 protoc -I . -I ../../.. --go_out=plugins=grpc:. $$file; \ 215 done 216 217 218 vendorfmt: 219 @echo "--> Formatting vendor/vendor.json" 220 test -x $(GOPATH)/bin/vendorfmt || go get -u github.com/magiconair/vendorfmt/cmd/vendorfmt 221 vendorfmt 222 changelogfmt: 223 @echo "--> Making [GH-xxxx] references clickable..." 224 @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 225 226 227 .PHONY: dev 228 dev: GOOS=$(shell go env GOOS) 229 dev: GOARCH=$(shell go env GOARCH) 230 dev: GOPATH=$(shell go env GOPATH) 231 dev: DEV_TARGET=pkg/$(GOOS)_$(GOARCH)/nomad 232 dev: vendorfmt changelogfmt ## Build for the current development platform 233 @echo "==> Removing old development build..." 234 @rm -f $(PROJECT_ROOT)/$(DEV_TARGET) 235 @rm -f $(PROJECT_ROOT)/bin/nomad 236 @rm -f $(GOPATH)/bin/nomad 237 @$(MAKE) --no-print-directory \ 238 $(DEV_TARGET) \ 239 GO_TAGS="$(NOMAD_UI_TAG)" 240 @mkdir -p $(PROJECT_ROOT)/bin 241 @mkdir -p $(GOPATH)/bin 242 @cp $(PROJECT_ROOT)/$(DEV_TARGET) $(PROJECT_ROOT)/bin/ 243 @cp $(PROJECT_ROOT)/$(DEV_TARGET) $(GOPATH)/bin 244 245 .PHONY: prerelease 246 prerelease: GO_TAGS=ui release 247 prerelease: generate-all ember-dist static-assets ## Generate all the static assets for a Nomad release 248 249 .PHONY: release 250 release: GO_TAGS=ui release 251 release: clean $(foreach t,$(ALL_TARGETS),pkg/$(t).zip) ## Build all release packages which can be built on this platform. 252 @echo "==> Results:" 253 @tree --dirsfirst $(PROJECT_ROOT)/pkg 254 255 .PHONY: test 256 test: ## Run the Nomad test suite and/or the Nomad UI test suite 257 @if [ ! $(SKIP_NOMAD_TESTS) ]; then \ 258 make test-nomad; \ 259 fi 260 @if [ $(RUN_WEBSITE_TESTS) ]; then \ 261 make test-website; \ 262 fi 263 @if [ $(RUN_UI_TESTS) ]; then \ 264 make test-ui; \ 265 fi 266 @if [ $(RUN_E2E_TESTS) ]; then \ 267 make e2e-test; \ 268 fi 269 270 .PHONY: test-nomad 271 test-nomad: dev ## Run Nomad test suites 272 @echo "==> Running Nomad test suites:" 273 $(if $(ENABLE_RACE),GORACE="strip_path_prefix=$(GOPATH)/src") $(GO_TEST_CMD) \ 274 $(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \ 275 -cover \ 276 -timeout=15m \ 277 $(GOTEST_PKGS) $(if $(VERBOSE), >test.log ; echo $$? > exit-code) 278 @if [ $(VERBOSE) ] ; then \ 279 bash -C "$(PROJECT_ROOT)/scripts/test_check.sh" ; \ 280 fi 281 282 .PHONY: e2e-test 283 e2e-test: dev ## Run the Nomad e2e test suite 284 @echo "==> Running Nomad E2E test suites:" 285 go test \ 286 $(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \ 287 -cover \ 288 -timeout=900s \ 289 github.com/hashicorp/nomad/e2e/vault/ \ 290 -integration 291 292 .PHONY: clean 293 clean: GOPATH=$(shell go env GOPATH) 294 clean: ## Remove build artifacts 295 @echo "==> Cleaning build artifacts..." 296 @rm -rf "$(PROJECT_ROOT)/bin/" 297 @rm -rf "$(PROJECT_ROOT)/pkg/" 298 @rm -f "$(GOPATH)/bin/nomad" 299 300 .PHONY: travis 301 travis: ## Run Nomad test suites with output to prevent timeouts under Travis CI 302 @if [ ! $(SKIP_NOMAD_TESTS) ]; then \ 303 make generate-structs; \ 304 fi 305 @"$(PROJECT_ROOT)/scripts/travis.sh" 306 307 .PHONY: testcluster 308 testcluster: ## Bring up a Linux test cluster using Vagrant. Set PROVIDER if necessary. 309 vagrant up nomad-server01 \ 310 nomad-server02 \ 311 nomad-server03 \ 312 nomad-client01 \ 313 nomad-client02 \ 314 nomad-client03 \ 315 $(if $(PROVIDER),--provider $(PROVIDER)) 316 317 .PHONY: static-assets 318 static-assets: ## Compile the static routes to serve alongside the API 319 @echo "--> Generating static assets" 320 @go-bindata-assetfs -pkg agent -prefix ui -modtime 1480000000 -tags ui -o bindata_assetfs.go ./ui/dist/... 321 @mv bindata_assetfs.go command/agent 322 323 .PHONY: test-website 324 test-website: ## Run Website Link Checks 325 @cd website && make test 326 327 .PHONY: test-ui 328 test-ui: ## Run Nomad UI test suite 329 @echo "--> Installing JavaScript assets" 330 @cd ui && npm rebuild node-sass 331 @cd ui && yarn install 332 @echo "--> Running ember tests" 333 @cd ui && npm test 334 335 .PHONY: ember-dist 336 ember-dist: ## Build the static UI assets from source 337 @echo "--> Installing JavaScript assets" 338 @cd ui && yarn install --silent 339 @cd ui && npm rebuild node-sass 340 @echo "--> Building Ember application" 341 @cd ui && npm run build 342 343 .PHONY: dev-ui 344 dev-ui: ember-dist static-assets 345 @$(MAKE) NOMAD_UI_TAG="ui" dev ## Build a dev binary with the UI baked in 346 347 HELP_FORMAT=" \033[36m%-25s\033[0m %s\n" 348 .PHONY: help 349 help: ## Display this usage information 350 @echo "Valid targets:" 351 @grep -E '^[^ ]+:.*?## .*$$' $(MAKEFILE_LIST) | \ 352 sort | \ 353 awk 'BEGIN {FS = ":.*?## "}; \ 354 {printf $(HELP_FORMAT), $$1, $$2}' 355 @echo "" 356 @echo "This host will build the following targets if 'make release' is invoked:" 357 @echo $(ALL_TARGETS) | sed 's/^/ /'