github.com/quite/nomad@v0.8.6/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 default: help 12 13 ifeq (,$(findstring $(THIS_OS),Darwin Linux FreeBSD)) 14 $(error Building Nomad is currently only supported on Darwin and Linux.) 15 endif 16 17 # On Linux we build for Linux, Windows, and potentially Linux+LXC 18 ifeq (Linux,$(THIS_OS)) 19 20 # Detect if we have LXC on the path 21 ifeq (0,$(shell pkg-config --exists lxc; echo $$?)) 22 HAS_LXC="true" 23 endif 24 25 ifeq ($(TRAVIS),true) 26 $(info Running in Travis, verbose mode is disabled) 27 else 28 VERBOSE="true" 29 endif 30 31 32 ALL_TARGETS += linux_386 \ 33 linux_amd64 \ 34 linux_arm \ 35 linux_arm64 \ 36 windows_386 \ 37 windows_amd64 38 39 ifeq ("true",$(HAS_LXC)) 40 ALL_TARGETS += linux_amd64-lxc 41 endif 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 pkg/linux_amd64-lxc/nomad: $(SOURCE_FILES) ## Build Nomad+LXC for linux/amd64 124 @echo "==> Building $@ with tags $(GO_TAGS)..." 125 @CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \ 126 go build \ 127 -ldflags $(GO_LDFLAGS) \ 128 -tags "$(GO_TAGS) lxc" \ 129 -o "$@" 130 131 # Define package targets for each of the build targets we actually have on this system 132 define makePackageTarget 133 134 pkg/$(1).zip: pkg/$(1)/nomad 135 @echo "==> Packaging for $(1)..." 136 @zip -j pkg/$(1).zip pkg/$(1)/* 137 138 endef 139 140 # Reify the package targets 141 $(foreach t,$(ALL_TARGETS),$(eval $(call makePackageTarget,$(t)))) 142 143 .PHONY: bootstrap 144 bootstrap: deps lint-deps # Install all dependencies 145 146 .PHONY: deps 147 deps: ## Install build and development dependencies 148 @echo "==> Updating build dependencies..." 149 go get -u github.com/kardianos/govendor 150 go get -u github.com/ugorji/go/codec/codecgen 151 go get -u github.com/hashicorp/go-bindata/... 152 go get -u github.com/elazarl/go-bindata-assetfs/... 153 go get -u github.com/a8m/tree/cmd/tree 154 go get -u github.com/magiconair/vendorfmt/cmd/vendorfmt 155 156 .PHONY: lint-deps 157 lint-deps: ## Install linter dependencies 158 @echo "==> Updating linter dependencies..." 159 go get -u github.com/alecthomas/gometalinter 160 gometalinter --install 161 162 .PHONY: check 163 check: ## Lint the source code 164 @echo "==> Linting source code..." 165 @gometalinter \ 166 --deadline 10m \ 167 --vendor \ 168 --exclude='.*\.generated\.go' \ 169 --exclude='.*bindata_assetfs\.go' \ 170 --skip="ui/" \ 171 --sort="path" \ 172 --aggregate \ 173 --enable-gc \ 174 --disable-all \ 175 --enable goimports \ 176 --enable misspell \ 177 --enable vet \ 178 --enable deadcode \ 179 --enable varcheck \ 180 --enable ineffassign \ 181 --enable structcheck \ 182 --enable unconvert \ 183 --enable gofmt \ 184 ./... 185 @echo "==> Spell checking website..." 186 @misspell -error -source=text website/source/ 187 188 .PHONY: checkscripts 189 checkscripts: ## Lint shell scripts 190 @echo "==> Linting scripts..." 191 @shellcheck ./scripts/* 192 193 generate: LOCAL_PACKAGES = $(shell go list ./... | grep -v '/vendor/') 194 generate: ## Update generated code 195 @go generate $(LOCAL_PACKAGES) 196 197 vendorfmt: 198 @echo "--> Formatting vendor/vendor.json" 199 test -x $(GOPATH)/bin/vendorfmt || go get -u github.com/magiconair/vendorfmt/cmd/vendorfmt 200 vendorfmt 201 changelogfmt: 202 @echo "--> Making [GH-xxxx] references clickable..." 203 @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 204 205 206 .PHONY: dev 207 dev: GOOS=$(shell go env GOOS) 208 dev: GOARCH=$(shell go env GOARCH) 209 dev: GOPATH=$(shell go env GOPATH) 210 dev: DEV_TARGET=pkg/$(GOOS)_$(GOARCH)$(if $(HAS_LXC),-lxc)/nomad 211 dev: vendorfmt changelogfmt ## Build for the current development platform 212 @echo "==> Removing old development build..." 213 @rm -f $(PROJECT_ROOT)/$(DEV_TARGET) 214 @rm -f $(PROJECT_ROOT)/bin/nomad 215 @rm -f $(GOPATH)/bin/nomad 216 @$(MAKE) --no-print-directory \ 217 $(DEV_TARGET) \ 218 GO_TAGS="$(NOMAD_UI_TAG)" 219 @mkdir -p $(PROJECT_ROOT)/bin 220 @mkdir -p $(GOPATH)/bin 221 @cp $(PROJECT_ROOT)/$(DEV_TARGET) $(PROJECT_ROOT)/bin/ 222 @cp $(PROJECT_ROOT)/$(DEV_TARGET) $(GOPATH)/bin 223 224 .PHONY: prerelease 225 prerelease: GO_TAGS=ui release 226 prerelease: check generate ember-dist static-assets ## Generate all the static assets for a Nomad release 227 228 .PHONY: release 229 release: GO_TAGS=ui release 230 release: clean $(foreach t,$(ALL_TARGETS),pkg/$(t).zip) ## Build all release packages which can be built on this platform. 231 @echo "==> Results:" 232 @tree --dirsfirst $(PROJECT_ROOT)/pkg 233 234 .PHONY: test 235 test: ## Run the Nomad test suite and/or the Nomad UI test suite 236 @if [ ! $(SKIP_NOMAD_TESTS) ]; then \ 237 make test-nomad; \ 238 fi 239 @if [ $(RUN_UI_TESTS) ]; then \ 240 make test-ui; \ 241 fi 242 @if [ $(RUN_E2E_TESTS) ]; then \ 243 make e2e-test; \ 244 fi 245 246 .PHONY: test-nomad 247 test-nomad: dev ## Run Nomad test suites 248 @echo "==> Running Nomad test suites:" 249 @go test $(if $(VERBOSE),-v) \ 250 -cover \ 251 -timeout=900s \ 252 -tags="$(if $(HAS_LXC),lxc)" ./... $(if $(VERBOSE), >test.log ; echo $$? > exit-code) 253 @if [ $(VERBOSE) ] ; then \ 254 bash -C "$(PROJECT_ROOT)/scripts/test_check.sh" ; \ 255 fi 256 257 .PHONY: e2e-test 258 e2e-test: dev ## Run the Nomad e2e test suite 259 @echo "==> Running Nomad E2E test suites:" 260 go test \ 261 $(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \ 262 -cover \ 263 -timeout=900s \ 264 github.com/hashicorp/nomad/e2e/vault/ 265 266 .PHONY: clean 267 clean: GOPATH=$(shell go env GOPATH) 268 clean: ## Remove build artifacts 269 @echo "==> Cleaning build artifacts..." 270 @rm -rf "$(PROJECT_ROOT)/bin/" 271 @rm -rf "$(PROJECT_ROOT)/pkg/" 272 @rm -f "$(GOPATH)/bin/nomad" 273 274 .PHONY: travis 275 travis: ## Run Nomad test suites with output to prevent timeouts under Travis CI 276 @if [ ! $(SKIP_NOMAD_TESTS) ]; then \ 277 make generate; \ 278 fi 279 @sh -C "$(PROJECT_ROOT)/scripts/travis.sh" 280 281 .PHONY: testcluster 282 testcluster: ## Bring up a Linux test cluster using Vagrant. Set PROVIDER if necessary. 283 vagrant up nomad-server01 \ 284 nomad-server02 \ 285 nomad-server03 \ 286 nomad-client01 \ 287 nomad-client02 \ 288 nomad-client03 \ 289 $(if $(PROVIDER),--provider $(PROVIDER)) 290 291 .PHONY: static-assets 292 static-assets: ## Compile the static routes to serve alongside the API 293 @echo "--> Generating static assets" 294 @go-bindata-assetfs -pkg agent -prefix ui -modtime 1480000000 -tags ui -o bindata_assetfs.go ./ui/dist/... 295 @mv bindata_assetfs.go command/agent 296 297 .PHONY: test-ui 298 test-ui: ## Run Nomad UI test suite 299 @echo "--> Installing JavaScript assets" 300 @cd ui && npm rebuild node-sass 301 @cd ui && yarn install 302 @echo "--> Running ember tests" 303 @cd ui && phantomjs --version 304 @cd ui && npm test 305 306 .PHONY: ember-dist 307 ember-dist: ## Build the static UI assets from source 308 @echo "--> Installing JavaScript assets" 309 @cd ui && yarn install --silent 310 @cd ui && npm rebuild node-sass 311 @echo "--> Building Ember application" 312 @cd ui && npm run build 313 314 .PHONY: dev-ui 315 dev-ui: ember-dist static-assets 316 @$(MAKE) NOMAD_UI_TAG="ui" dev ## Build a dev binary with the UI baked in 317 318 HELP_FORMAT=" \033[36m%-25s\033[0m %s\n" 319 .PHONY: help 320 help: ## Display this usage information 321 @echo "Valid targets:" 322 @grep -E '^[^ ]+:.*?## .*$$' $(MAKEFILE_LIST) | \ 323 sort | \ 324 awk 'BEGIN {FS = ":.*?## "}; \ 325 {printf $(HELP_FORMAT), $$1, $$2}' 326 @echo "" 327 @echo "This host will build the following targets if 'make release' is invoked:" 328 @echo $(ALL_TARGETS) | sed 's/^/ /'