github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/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  	go get -u github.com/golang/protobuf/protoc-gen-go
   156  
   157  .PHONY: lint-deps
   158  lint-deps: ## Install linter dependencies
   159  	@echo "==> Updating linter dependencies..."
   160  	go get -u github.com/alecthomas/gometalinter
   161  	gometalinter --install
   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  .PHONY: checkscripts
   190  checkscripts: ## Lint shell scripts
   191  	@echo "==> Linting scripts..."
   192  	@shellcheck ./scripts/*
   193  
   194  generate: LOCAL_PACKAGES = $(shell go list ./... | grep -v '/vendor/')
   195  generate: ## Update generated code
   196  	@go generate $(LOCAL_PACKAGES)
   197  
   198  vendorfmt:
   199  	@echo "--> Formatting vendor/vendor.json"
   200  	test -x $(GOPATH)/bin/vendorfmt || go get -u github.com/magiconair/vendorfmt/cmd/vendorfmt
   201  		vendorfmt
   202  changelogfmt:
   203  	@echo "--> Making [GH-xxxx] references clickable..."
   204  	@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
   205  
   206  
   207  .PHONY: dev
   208  dev: GOOS=$(shell go env GOOS)
   209  dev: GOARCH=$(shell go env GOARCH)
   210  dev: GOPATH=$(shell go env GOPATH)
   211  dev: DEV_TARGET=pkg/$(GOOS)_$(GOARCH)$(if $(HAS_LXC),-lxc)/nomad
   212  dev: vendorfmt changelogfmt ## Build for the current development platform
   213  	@echo "==> Removing old development build..."
   214  	@rm -f $(PROJECT_ROOT)/$(DEV_TARGET)
   215  	@rm -f $(PROJECT_ROOT)/bin/nomad
   216  	@rm -f $(GOPATH)/bin/nomad
   217  	@$(MAKE) --no-print-directory \
   218  		$(DEV_TARGET) \
   219  		GO_TAGS="$(NOMAD_UI_TAG)"
   220  	@mkdir -p $(PROJECT_ROOT)/bin
   221  	@mkdir -p $(GOPATH)/bin
   222  	@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(PROJECT_ROOT)/bin/
   223  	@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(GOPATH)/bin
   224  
   225  .PHONY: prerelease
   226  prerelease: GO_TAGS=ui release
   227  prerelease: check generate ember-dist static-assets ## Generate all the static assets for a Nomad release
   228  
   229  .PHONY: release
   230  release: GO_TAGS=ui release
   231  release: clean $(foreach t,$(ALL_TARGETS),pkg/$(t).zip) ## Build all release packages which can be built on this platform.
   232  	@echo "==> Results:"
   233  	@tree --dirsfirst $(PROJECT_ROOT)/pkg
   234  
   235  .PHONY: test
   236  test: ## Run the Nomad test suite and/or the Nomad UI test suite
   237  	@if [ ! $(SKIP_NOMAD_TESTS) ]; then \
   238  		make test-nomad; \
   239  		fi
   240  	@if [ $(RUN_UI_TESTS) ]; then \
   241  		make test-ui; \
   242  		fi
   243  
   244  .PHONY: test-nomad
   245  test-nomad: dev ## Run Nomad test suites
   246  	@echo "==> Running Nomad test suites:"
   247  	$(if $(ENABLE_RACE),GORACE="strip_path_prefix=$(GOPATH)/src") go test \
   248  		$(if $(ENABLE_RACE),-race) $(if $(VERBOSE),-v) \
   249  		-cover \
   250  		-timeout=900s \
   251  		-tags="$(if $(HAS_LXC),lxc)" ./... $(if $(VERBOSE), >test.log ; echo $$? > exit-code)
   252  	@if [ $(VERBOSE) ] ; then \
   253  		bash -C "$(PROJECT_ROOT)/scripts/test_check.sh" ; \
   254  	fi
   255  
   256  .PHONY: clean
   257  clean: GOPATH=$(shell go env GOPATH)
   258  clean: ## Remove build artifacts
   259  	@echo "==> Cleaning build artifacts..."
   260  	@rm -rf "$(PROJECT_ROOT)/bin/"
   261  	@rm -rf "$(PROJECT_ROOT)/pkg/"
   262  	@rm -f "$(GOPATH)/bin/nomad"
   263  
   264  .PHONY: travis
   265  travis: ## Run Nomad test suites with output to prevent timeouts under Travis CI
   266  	@if [ ! $(SKIP_NOMAD_TESTS) ]; then \
   267  		make generate; \
   268  	fi
   269  	@sh -C "$(PROJECT_ROOT)/scripts/travis.sh"
   270  
   271  .PHONY: testcluster
   272  testcluster: ## Bring up a Linux test cluster using Vagrant. Set PROVIDER if necessary.
   273  	vagrant up nomad-server01 \
   274  		nomad-server02 \
   275  		nomad-server03 \
   276  		nomad-client01 \
   277  		nomad-client02 \
   278  		nomad-client03 \
   279  		$(if $(PROVIDER),--provider $(PROVIDER))
   280  
   281  .PHONY: static-assets
   282  static-assets: ## Compile the static routes to serve alongside the API
   283  	@echo "--> Generating static assets"
   284  	@go-bindata-assetfs -pkg agent -prefix ui -modtime 1480000000 -tags ui -o bindata_assetfs.go ./ui/dist/...
   285  	@mv bindata_assetfs.go command/agent
   286  
   287  .PHONY: test-ui
   288  test-ui: ## Run Nomad UI test suite
   289  	@echo "--> Installing JavaScript assets"
   290  	@cd ui && npm rebuild node-sass
   291  	@cd ui && yarn install
   292  	@echo "--> Running ember tests"
   293  	@cd ui && npm test
   294  
   295  .PHONY: ember-dist
   296  ember-dist: ## Build the static UI assets from source
   297  	@echo "--> Installing JavaScript assets"
   298  	@cd ui && yarn install --silent
   299  	@cd ui && npm rebuild node-sass
   300  	@echo "--> Building Ember application"
   301  	@cd ui && npm run build
   302  
   303  .PHONY: dev-ui
   304  dev-ui: ember-dist static-assets
   305  	@$(MAKE) NOMAD_UI_TAG="ui" dev ## Build a dev binary with the UI baked in
   306  
   307  HELP_FORMAT="    \033[36m%-25s\033[0m %s\n"
   308  .PHONY: help
   309  help: ## Display this usage information
   310  	@echo "Valid targets:"
   311  	@grep -E '^[^ ]+:.*?## .*$$' $(MAKEFILE_LIST) | \
   312  		sort | \
   313  		awk 'BEGIN {FS = ":.*?## "}; \
   314  			{printf $(HELP_FORMAT), $$1, $$2}'
   315  	@echo ""
   316  	@echo "This host will build the following targets if 'make release' is invoked:"
   317  	@echo $(ALL_TARGETS) | sed 's/^/    /'